diff --git a/internal/state/apply.go b/internal/state/apply.go index f1714ad..6bb493c 100644 --- a/internal/state/apply.go +++ b/internal/state/apply.go @@ -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 } @@ -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 diff --git a/internal/state/fatchain.go b/internal/state/fatchain.go index 7b9a40b..5669a94 100644 --- a/internal/state/fatchain.go +++ b/internal/state/fatchain.go @@ -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 } @@ -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 { diff --git a/internal/state/parallelchain.go b/internal/state/parallelchain.go index b973e73..3f38e3e 100644 --- a/internal/state/parallelchain.go +++ b/internal/state/parallelchain.go @@ -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) @@ -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) diff --git a/internal/state/state.go b/internal/state/state.go index 05a5a74..8abd315 100644 --- a/internal/state/state.go +++ b/internal/state/state.go @@ -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 }