Skip to content

Commit

Permalink
Don't mark unwound non-bad blocks as bad (#12980)
Browse files Browse the repository at this point in the history
An `UnwindReason` created w/o an error (by `ForkReset`) means that a
block has to be unwound, but it's not bad, so it shouldn't be inserted
into `BadHeaderNumber` by `TruncateCanonicalHash`. `ForkReset` is used
in Bor milestone rewind.
  • Loading branch information
yperbasis authored Dec 4, 2024
1 parent 2cb24b5 commit cd6312c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/integration/commands/stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion core/rawdb/rawdbreset/reset_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions eth/stagedsync/stage_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/stage_polygon_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit cd6312c

Please sign in to comment.