diff --git a/eth/backend.go b/eth/backend.go index 59d80e82c3405b0b5f6db3fa433a1339f328ed5c..1f0102e5a1ff3381771013ce0b206ae6effe5c00 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -447,16 +447,22 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere if err != nil { return nil, err } - if config.BadBlock != 0 { - var badHash common.Hash + + emptyBadHash := config.BadBlockHash == common.Hash{} + if !emptyBadHash { + var badBlockHeader *types.Header if err = chainKv.View(context.Background(), func(tx kv.Tx) error { - var hErr error - badHash, hErr = rawdb.ReadCanonicalHash(tx, config.BadBlock) + header, hErr := rawdb.ReadHeaderByHash(tx, config.BadBlockHash) + badBlockHeader = header return hErr }); err != nil { return nil, err } - backend.stagedSync.UnwindTo(config.BadBlock-1, badHash) + + if badBlockHeader != nil { + unwindPoint := badBlockHeader.Number.Uint64() - 1 + backend.stagedSync.UnwindTo(unwindPoint, config.BadBlockHash) + } } go txpropagate.BroadcastPendingTxsToNetwork(backend.downloadCtx, backend.txPool, backend.txPoolP2PServer.RecentPeers, backend.downloadServer) diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 503fdb919532dcbbca01c5dd717c901e61147c79..a116e27d48dea398ab59f4c5d41e798fa1255547 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -137,9 +137,9 @@ type Config struct { P2PEnabled bool - Prune prune.Mode - BatchSize datasize.ByteSize // Batch size for execution stage - BadBlock uint64 // Block marked as bad (for forced reorg) + Prune prune.Mode + BatchSize datasize.ByteSize // Batch size for execution stage + BadBlockHash common.Hash // hash of the block marked as bad Snapshot Snapshot diff --git a/turbo/cli/flags.go b/turbo/cli/flags.go index b023b0610579b4c90ce541d89749c4b3b2875c2d..f1c86c56fc3b7026719a3b831194acc3a051779e 100644 --- a/turbo/cli/flags.go +++ b/turbo/cli/flags.go @@ -8,7 +8,9 @@ import ( "github.com/c2h5oh/datasize" "github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon/cmd/utils" + "github.com/ledgerwatch/erigon/common" "github.com/ledgerwatch/erigon/common/etl" + "github.com/ledgerwatch/erigon/common/hexutil" "github.com/ledgerwatch/erigon/eth/ethconfig" "github.com/ledgerwatch/erigon/ethdb/prune" "github.com/ledgerwatch/erigon/node" @@ -150,10 +152,10 @@ var ( Value: "", } - BadBlockFlag = cli.IntFlag{ + BadBlockFlag = cli.StringFlag{ Name: "bad.block", - Usage: "Marks block with given number bad and forces initial reorg before normal staged sync", - Value: 0, + Usage: "Marks block with given hex string as bad and forces initial reorg before normal staged sync", + Value: "", } ) @@ -207,7 +209,12 @@ func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) { } cfg.SyncLoopThrottle = syncLoopThrottle } - cfg.BadBlock = uint64(ctx.GlobalInt(BadBlockFlag.Name)) + + bytes, err := hexutil.Decode(BadBlockFlag.Value) + if err != nil { + log.Warn("Error decoding hash %v: %v", BadBlockFlag.Value, err) + } + cfg.BadBlockHash = common.BytesToHash(bytes) } func ApplyFlagsForEthConfigCobra(f *pflag.FlagSet, cfg *ethconfig.Config) {