Skip to content

Commit

Permalink
Merge branch 'hotfix/v1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSLevy committed Feb 20, 2020
2 parents 984c7c1 + 4943e86 commit 5512d7f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
3 changes: 1 addition & 2 deletions internal/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ func goN(ctx context.Context, n int,
}

func ApplyDBlock(ctx context.Context, c *factom.Client, h uint32, state State) error {
//log.Debugf("Syncing DBlock %v...", h)
// Load next DBlock.
dblock := factom.DBlock{Height: h}
if err := dblock.Get(ctx, c); err != nil {
Expand Down Expand Up @@ -299,7 +298,7 @@ func ApplyDBlock(ctx context.Context, c *factom.Client, h uint32, state State) e
}
close(eblocks)
if err := g.Wait(); err != nil {
return fmt.Errorf("errgroup.Wait(): %w", err)
return fmt.Errorf("ApplyDBlock: errgroup.Wait(): %w", err)
}

// DBlock completed so update the sync height for all
Expand Down
15 changes: 8 additions & 7 deletions internal/state/fatchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func ToFATChain(chain Chain) (fatChain *FATChain, ok bool) {
fatChain, ok = chain.(*FATChain)
return
}
func (chain *FATChain) ToFATChain() *db.FATChain {
func (chain *FATChain) ToDBFATChain() *db.FATChain {
return (*db.FATChain)(chain)
}
func (chain *FATChain) ToFactomChain() *db.FactomChain {
Expand All @@ -93,11 +93,12 @@ func (chain *FATChain) ApplyEntry(e factom.Entry) (eID int64, err error) {
_, txErr, err = chain.ApplyTx(eID, e)
}

if txErr != nil {
chain.Log.Debugf("Invalid %v: %v %v", entryType, txErr, e.Hash)
} else {
chain.Log.Debugf("Valid %v: %v", entryType, e.Hash)
}
//if txErr != nil {
// chain.Log.Debugf("Invalid %v: %v %v", entryType, txErr, e.Hash)
//} else {
// chain.Log.Debugf("Valid %v: %v", entryType, e.Hash)
//}
_ = entryType

return
}
Expand Down Expand Up @@ -190,7 +191,7 @@ func (chain *FATChain) applyFAT0Tx(eID int64, e factom.Entry) (tx fat0.Transacti
txErr = fmt.Errorf("coinbase exceeds max supply")
return
}
if err = chain.ToFATChain().AddNumIssued(addIssued); err != nil {
if err = chain.ToDBFATChain().AddNumIssued(addIssued); err != nil {
return
}
if _, err = address.InsertTxRelation(
Expand Down
32 changes: 22 additions & 10 deletions internal/state/parallelchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,24 @@ func (chain *ParallelChain) SetSync(height uint32, dbKeyMR *factom.Bytes32) erro
if height <= chain.syncHeight {
return nil
}

// SetSync is called inside of State.SetSync on all chains.
// State.SetSync acquires the State.Lock. In order to avoid deadlock,
// this function MUST return so that the State.Lock can be released.
chain.syncHeight = height
select {
case eb := <-chain.eblocks:
// If there is already an eblock in the channel, check to see
// if its populated.
if eb.EBlock.IsPopulated() {
// Just put it back.
chain.eblocks <- eb
return nil
}
// Otherwise it was simply a marker for the sync height, so we
// discard it and replace it with the new sync height.
default:
}

chain.eblocks <- dbKeyMREBlock{dbKeyMR, factom.EBlock{Height: height}}

return nil
Expand All @@ -81,8 +97,6 @@ func (chain *ParallelChain) ApplyEBlockCtx(ctx context.Context,
case <-ctx.Done():
return ctx.Err()
}

return nil
}

func (chain *ParallelChain) ApplyPendingEntries(
Expand All @@ -107,8 +121,8 @@ func (state *State) NewParallelChain(ctx context.Context,
}

pChain := ParallelChain{
eblocks: make(chan dbKeyMREBlock, 1),
pending: make(chan []factom.Entry, 1),
eblocks: make(chan dbKeyMREBlock, 1), // DO NOT INCREASE BUFFER SIZE
pending: make(chan []factom.Entry, 1), // DO NOT INCREASE BUFFER SIZE
syncHeight: head.Height,
TryLocker: trylock.New(),
}
Expand Down Expand Up @@ -192,11 +206,6 @@ func (chain *ParallelChain) processEBlock(state *State, eb dbKeyMREBlock) error
}
}

if err := chain.UpdateSidechainData(state.ctx, state.c); err != nil {
return fmt.Errorf(
"state.Chain.UpdateSidechainData(): %w", err)
}

if !eb.EBlock.IsPopulated() {
// An unpopulated EBlock is sent by ParallelChain.SetSync to
// indicate that we should simply advance the sync height.
Expand All @@ -212,6 +221,9 @@ func (chain *ParallelChain) processEBlock(state *State, eb dbKeyMREBlock) error
return fmt.Errorf("factom.EBlock.GetEntries(): %w", err)
}

if err := chain.UpdateSidechainData(state.ctx, state.c); err != nil {
return fmt.Errorf("state.Chain.UpdateSidechainData(): %w", err)
}
if err := Apply(chain.Chain, eb.dbKeyMR, eb.EBlock); err != nil {
return fmt.Errorf("state.Apply(): %w", err)
}
Expand Down

0 comments on commit 5512d7f

Please sign in to comment.