Skip to content

Commit

Permalink
Merge branch 'hotfix/v1.1.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamSLevy committed Feb 19, 2020
2 parents 2ef721f + 07b0572 commit 27650d1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
9 changes: 7 additions & 2 deletions internal/state/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ func (state *State) ApplyEBlock(ctx context.Context,
return fmt.Errorf("factom.EBlock.Get(): %w", err)
}

if chain == nil { // Chain is unknown
if !eb.IsFirst() {
if chain == nil { // if Chain is unknown...
if !eb.IsFirst() { // if Chain is not new...
state.ignore(eb.ChainID)
return nil
}
Expand Down Expand Up @@ -119,6 +119,11 @@ func (state *State) ApplyEBlock(ctx context.Context,
err = fmt.Errorf("factom.EBlock.GetEntries(): %w", err)
return
}
if err := chain.UpdateSidechainData(
state.ctx, state.c); err != nil {
return nil, fmt.Errorf(
"state.Chain.UpdateSidechainData(): %w", err)
}
if err = Apply(&fatChain, dbKeyMR, eb); err != nil {
err = fmt.Errorf("state.Apply(): %w", err)
return
Expand Down
17 changes: 12 additions & 5 deletions internal/state/fatchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,20 @@ func (chain *FATChain) ApplyEntry(e factom.Entry) (eID int64, err error) {
}

var txErr error
entryType := "Tx"
defer chain.save()(&txErr, &err)
if !chain.IsIssued() {
txErr, err = chain.ApplyIssuance(eID, e)
entryType = "Issuance"
} else {
_, txErr, err = chain.ApplyTx(eID, e)
}

//if txErr != nil {
// chain.Log.Debugf("Invalid Tx: %v %v", txErr, e.Hash)
//} else {
// chain.Log.Debugf("Valid Tx: %v", 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)
}

return
}
Expand Down Expand Up @@ -420,6 +422,11 @@ func NewFATChainByEBlock(ctx context.Context, c *factom.Client,
}
}()

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

chain.Log.Info("Syncing entries...")

if err = firstEB.GetEntries(ctx, c); err != nil {
Expand Down
9 changes: 5 additions & 4 deletions internal/state/parallelchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (state *State) NewParallelChain(ctx context.Context,
}

defer func() {
pChain.Lock()
pChain.Lock() // lock forever on exit.
if err := pChain.Chain.Close(); err != nil {
pChain.ToFactomChain().Log.Errorf(
"state.Chain.Close(): %v", err)
Expand Down Expand Up @@ -197,9 +197,10 @@ func (chain *ParallelChain) processEBlock(state *State, eb dbKeyMREBlock) error
"state.Chain.UpdateSidechainData(): %w", err)
}

if eb.EBlock.ChainID == nil {
if err := chain.Chain.SetSync(
eb.EBlock.Height, eb.dbKeyMR); err != nil {
if !eb.EBlock.IsPopulated() {
// An unpopulated EBlock is sent by ParallelChain.SetSync to
// indicate that we should simply advance the sync height.
if err := chain.Chain.SetSync(eb.EBlock.Height, eb.dbKeyMR); err != nil {
return fmt.Errorf("state.Chain.SetSync(): %w",
err)

Expand Down
5 changes: 5 additions & 0 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,11 @@ func (state *State) loadFATChains(dbPath string,
return nil, fmt.Errorf(
"state.NewFATChainByChainID(): %w", err)
}
if err := chain.UpdateSidechainData(
state.ctx, state.c); err != nil {
return nil, fmt.Errorf(
"state.Chain.UpdateSidechainData(): %w", err)
}
return &chain, nil
}

Expand Down

0 comments on commit 27650d1

Please sign in to comment.