From 5a70bf6b129b64fa73c8869a8ff506a7c4a05e50 Mon Sep 17 00:00:00 2001 From: yperbasis Date: Tue, 3 Dec 2024 17:14:02 +0100 Subject: [PATCH] Don't mark unwound non-bad blocks as bad --- cmd/integration/commands/stages.go | 2 +- core/rawdb/rawdbreset/reset_stages.go | 2 +- eth/stagedsync/stage_headers.go | 6 ++++-- eth/stagedsync/stage_polygon_sync.go | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/cmd/integration/commands/stages.go b/cmd/integration/commands/stages.go index a9326f52d25..9be3db08f65 100644 --- a/cmd/integration/commands/stages.go +++ b/cmd/integration/commands/stages.go @@ -758,7 +758,7 @@ func stageHeaders(db kv.RwDB, ctx context.Context, logger log.Logger) error { } } // remove all canonical markers from this point - if err = rawdb.TruncateCanonicalHash(tx, progress+1, false); err != nil { + if err = rawdb.TruncateCanonicalHash(tx, progress+1, false /* markChainAsBad */); err != nil { return err } if err = rawdb.TruncateTd(tx, progress+1); err != nil { diff --git a/core/rawdb/rawdbreset/reset_stages.go b/core/rawdb/rawdbreset/reset_stages.go index c7265c1a639..171d068d60a 100644 --- a/core/rawdb/rawdbreset/reset_stages.go +++ b/core/rawdb/rawdbreset/reset_stages.go @@ -67,7 +67,7 @@ func ResetBlocks(tx kv.RwTx, db kv.RoDB, agg *state.Aggregator, br services.Full } // remove all canonical markers from this point - if err := rawdb.TruncateCanonicalHash(tx, 1, false); err != nil { + if err := rawdb.TruncateCanonicalHash(tx, 1, false /* markChainAsBad */); err != nil { return err } if err := rawdb.TruncateTd(tx, 1); err != nil { diff --git a/eth/stagedsync/stage_headers.go b/eth/stagedsync/stage_headers.go index fe03640c415..24dcc9a71cf 100644 --- a/eth/stagedsync/stage_headers.go +++ b/eth/stagedsync/stage_headers.go @@ -421,8 +421,10 @@ func HeadersUnwind(ctx context.Context, u *UnwindState, s *StageState, tx kv.RwT } // Delete canonical hashes that are being unwound unwindBlock := (u.Reason.Block != nil) + badBlock := false if unwindBlock { - if u.Reason.IsBadBlock() { + badBlock = u.Reason.IsBadBlock() + if badBlock { cfg.hd.ReportBadHeader(*u.Reason.Block) } @@ -448,7 +450,7 @@ func HeadersUnwind(ctx context.Context, u *UnwindState, s *StageState, tx kv.RwT return fmt.Errorf("iterate over headers to mark bad headers: %w", err) } } - if err := rawdb.TruncateCanonicalHash(tx, u.UnwindPoint+1, unwindBlock); err != nil { + if err := rawdb.TruncateCanonicalHash(tx, u.UnwindPoint+1, badBlock); err != nil { return err } if unwindBlock { diff --git a/eth/stagedsync/stage_polygon_sync.go b/eth/stagedsync/stage_polygon_sync.go index ea5a0dd9d4e..9e9b9a0e6bb 100644 --- a/eth/stagedsync/stage_polygon_sync.go +++ b/eth/stagedsync/stage_polygon_sync.go @@ -240,8 +240,8 @@ func UnwindPolygonSyncStage(ctx context.Context, tx kv.RwTx, u *UnwindState, cfg } // headers - unwindBlock := u.Reason.Block != nil - if err := rawdb.TruncateCanonicalHash(tx, u.UnwindPoint+1, unwindBlock); err != nil { + badBlock := u.Reason.IsBadBlock() + if err := rawdb.TruncateCanonicalHash(tx, u.UnwindPoint+1, badBlock); err != nil { return err }