From c808f2b733f560fa821201e3de6235095662347b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CGheisMohammadi=E2=80=9D?= <36589218+GheisMohammadi@users.noreply.github.com> Date: Thu, 5 Oct 2023 15:08:10 +0800 Subject: [PATCH] fix pivot block issue for write on chain --- api/service/stagedstreamsync/stage_state.go | 2 +- api/service/stagedstreamsync/stage_statesync.go | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/api/service/stagedstreamsync/stage_state.go b/api/service/stagedstreamsync/stage_state.go index 6c82a69c1..80a3faa0e 100644 --- a/api/service/stagedstreamsync/stage_state.go +++ b/api/service/stagedstreamsync/stage_state.go @@ -55,7 +55,7 @@ func NewStageStatesCfg( func (stg *StageStates) Exec(ctx context.Context, firstCycle bool, invalidBlockRevert bool, s *StageState, reverter Reverter, tx kv.RwTx) (err error) { // only execute this stage in full sync mode if s.state.config.SyncMode != FullSync { - if s.state.status.pivotBlock != nil && s.state.bc.CurrentBlock().NumberU64() <= s.state.status.pivotBlock.NumberU64() { + if s.state.status.pivotBlock != nil && s.state.bc.CurrentBlock().NumberU64() < s.state.status.pivotBlock.NumberU64() { return nil } } diff --git a/api/service/stagedstreamsync/stage_statesync.go b/api/service/stagedstreamsync/stage_statesync.go index 654171df4..130f7f71f 100644 --- a/api/service/stagedstreamsync/stage_statesync.go +++ b/api/service/stagedstreamsync/stage_statesync.go @@ -113,6 +113,16 @@ func (sss *StageStateSync) Exec(ctx context.Context, bool, invalidBlockRevert bo } wg.Wait() + // insert block + if err := sss.configs.bc.WriteHeadBlock(s.state.status.pivotBlock); err != nil { + sss.configs.logger.Warn().Err(err). + Uint64("pivot block number", s.state.status.pivotBlock.NumberU64()). + Msg(WrapStagedSyncMsg("insert pivot block failed")) + s.state.Debug("StateSync/pivot/insert/error", err) + // TODO: panic("pivot block is failed to insert in chain.") + return err + } + /* gbm := s.state.gbm