From 48b2b4cca1401195c0de369511b13deebd0578cf Mon Sep 17 00:00:00 2001 From: frozen <355847+Frozen@users.noreply.github.com> Date: Thu, 23 Nov 2023 15:36:00 -0400 Subject: [PATCH] Skip epochchain errors. --- api/service/legacysync/syncing.go | 6 +++++- api/service/stagedstreamsync/staged_stream_sync.go | 5 ++++- api/service/stagedsync/stagedsync.go | 6 +++++- consensus/downloader.go | 6 +++++- core/blockchain_impl.go | 5 +++-- core/epochchain.go | 2 +- 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/api/service/legacysync/syncing.go b/api/service/legacysync/syncing.go index bc5d9aed45..92c8a457f0 100644 --- a/api/service/legacysync/syncing.go +++ b/api/service/legacysync/syncing.go @@ -1158,7 +1158,11 @@ func (ss *StateSync) addConsensusLastMile(bc core.BlockChain, consensus *consens if block == nil { break } - if _, err := bc.InsertChain(types.Blocks{block}, true); err != nil { + _, err := bc.InsertChain(types.Blocks{block}, true) + switch { + case errors.Is(err, core.ErrKnownBlock): + case errors.Is(err, core.ErrNotLastBlockInEpoch): + case err != nil: return errors.Wrap(err, "failed to InsertChain") } } diff --git a/api/service/stagedstreamsync/staged_stream_sync.go b/api/service/stagedstreamsync/staged_stream_sync.go index fc59290474..98922af28d 100644 --- a/api/service/stagedstreamsync/staged_stream_sync.go +++ b/api/service/stagedstreamsync/staged_stream_sync.go @@ -637,7 +637,10 @@ func (ss *StagedStreamSync) addConsensusLastMile(bc core.BlockChain, cs *consens break } _, err := bc.InsertChain(types.Blocks{block}, true) - if err != nil && !errors.Is(err, core.ErrKnownBlock) { + switch { + case errors.Is(err, core.ErrKnownBlock): + case errors.Is(err, core.ErrNotLastBlockInEpoch): + case err != nil: return errors.Wrap(err, "failed to InsertChain") } hashes = append(hashes, block.Header().Hash()) diff --git a/api/service/stagedsync/stagedsync.go b/api/service/stagedsync/stagedsync.go index 4cc2a98ea7..83be4bae46 100644 --- a/api/service/stagedsync/stagedsync.go +++ b/api/service/stagedsync/stagedsync.go @@ -1221,7 +1221,11 @@ func (ss *StagedSync) addConsensusLastMile(bc core.BlockChain, cs *consensus.Con if block == nil { break } - if _, err := bc.InsertChain(types.Blocks{block}, true); err != nil && !errors.Is(err, core.ErrKnownBlock) { + _, err := bc.InsertChain(types.Blocks{block}, true) + switch { + case errors.Is(err, core.ErrKnownBlock): + case errors.Is(err, core.ErrNotLastBlockInEpoch): + case err != nil: return errors.Wrap(err, "failed to InsertChain") } } diff --git a/consensus/downloader.go b/consensus/downloader.go index f6e0e71003..804a25aabb 100644 --- a/consensus/downloader.go +++ b/consensus/downloader.go @@ -91,7 +91,11 @@ func (consensus *Consensus) AddConsensusLastMile() error { if block == nil { break } - if _, err := consensus.Blockchain().InsertChain(types.Blocks{block}, true); err != nil && !errors.Is(err, core.ErrKnownBlock) { + _, err := consensus.Blockchain().InsertChain(types.Blocks{block}, true) + switch { + case errors.Is(err, core.ErrKnownBlock): + case errors.Is(err, core.ErrNotLastBlockInEpoch): + case err != nil: return errors.Wrap(err, "failed to InsertChain") } } diff --git a/core/blockchain_impl.go b/core/blockchain_impl.go index 48e35325be..c9cb5a10e3 100644 --- a/core/blockchain_impl.go +++ b/core/blockchain_impl.go @@ -90,8 +90,9 @@ var ( blockWriteTimer = metrics.NewRegisteredTimer("chain/write", nil) // ErrNoGenesis is the error when there is no genesis. - ErrNoGenesis = errors.New("Genesis not found in chain") - ErrEmptyChain = errors.New("empty chain") + ErrNoGenesis = errors.New("Genesis not found in chain") + ErrEmptyChain = errors.New("empty chain") + ErrNotLastBlockInEpoch = errors.New("not last block in epoch") // errExceedMaxPendingSlashes .. errExceedMaxPendingSlashes = errors.New("exceeed max pending slashes") errNilEpoch = errors.New("nil epoch for voting power computation") diff --git a/core/epochchain.go b/core/epochchain.go index 7a3c40677b..7d9aeae1a8 100644 --- a/core/epochchain.go +++ b/core/epochchain.go @@ -124,7 +124,7 @@ func (bc *EpochChain) InsertChain(blocks types.Blocks, _ bool) (int, error) { }() for i, block := range blocks { if !block.IsLastBlockInEpoch() { - return i, errors.New("block is not last block in epoch") + return i, ErrNotLastBlockInEpoch } sig, bitmap, err := chain.ParseCommitSigAndBitmap(block.GetCurrentCommitSig()) if err != nil {