From b1dc618b956ead927ae92d7eda8ebad96d646b3e Mon Sep 17 00:00:00 2001 From: Alex Sharov Date: Thu, 6 May 2021 14:18:43 +0700 Subject: [PATCH] update stage progress before commit - to keep db always consistent (#1888) --- eth/stagedsync/stage_bodies_new.go | 3 +++ eth/stagedsync/stage_execute.go | 6 +++--- eth/stagedsync/stage_headers_new.go | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/eth/stagedsync/stage_bodies_new.go b/eth/stagedsync/stage_bodies_new.go index bfda809fd..7a096f4d1 100644 --- a/eth/stagedsync/stage_bodies_new.go +++ b/eth/stagedsync/stage_bodies_new.go @@ -159,6 +159,9 @@ func BodiesForward( return err } if !useExternalTx { + if err := s.DoneAndUpdate(tx, bodyProgress); err != nil { + return err + } if err = tx.CommitAndBegin(context.Background()); err != nil { return err } diff --git a/eth/stagedsync/stage_execute.go b/eth/stagedsync/stage_execute.go index 7e9c8a7a5..a666111e0 100644 --- a/eth/stagedsync/stage_execute.go +++ b/eth/stagedsync/stage_execute.go @@ -212,15 +212,15 @@ func SpawnExecuteBlocksStage(s *StageState, stateDB ethdb.Database, toBlock uint updateProgress := !useBatch || batch.BatchSize() >= int(params.batchSize) if updateProgress { - if err = s.Update(tx, stageProgress); err != nil { - return err - } if useBatch { if err = batch.CommitAndBegin(context.Background()); err != nil { return err } } if !useExternalTx { + if err = s.Update(tx, stageProgress); err != nil { + return err + } if err = tx.CommitAndBegin(context.Background()); err != nil { return err } diff --git a/eth/stagedsync/stage_headers_new.go b/eth/stagedsync/stage_headers_new.go index 3c76aaa75..895600a66 100644 --- a/eth/stagedsync/stage_headers_new.go +++ b/eth/stagedsync/stage_headers_new.go @@ -152,6 +152,9 @@ func HeadersForward( return err } if !useExternalTx { + if err = s.Update(tx, headerInserter.GetHighest()); err != nil { + return err + } if err = tx.CommitAndBegin(context.Background()); err != nil { return err }