good morning!!!!

Skip to content
Snippets Groups Projects
Unverified Commit fd357f03 authored by racytech's avatar racytech Committed by GitHub
Browse files

`bad.hash` flag added to exclude block by hash and not by number (#2612)

* BadHashFlag added

* bad.hash to bad.block
parent 2c6d4ae4
Branches
Tags
No related merge requests found
......@@ -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)
......
......@@ -139,7 +139,7 @@ type Config struct {
Prune prune.Mode
BatchSize datasize.ByteSize // Batch size for execution stage
BadBlock uint64 // Block marked as bad (for forced reorg)
BadBlockHash common.Hash // hash of the block marked as bad
Snapshot Snapshot
......
......@@ -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) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment