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
No related branches found
No related tags found
No related merge requests found
...@@ -447,16 +447,22 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere ...@@ -447,16 +447,22 @@ func New(stack *node.Node, config *ethconfig.Config, logger log.Logger) (*Ethere
if err != nil { if err != nil {
return nil, err 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 { if err = chainKv.View(context.Background(), func(tx kv.Tx) error {
var hErr error header, hErr := rawdb.ReadHeaderByHash(tx, config.BadBlockHash)
badHash, hErr = rawdb.ReadCanonicalHash(tx, config.BadBlock) badBlockHeader = header
return hErr return hErr
}); err != nil { }); err != nil {
return nil, err 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) go txpropagate.BroadcastPendingTxsToNetwork(backend.downloadCtx, backend.txPool, backend.txPoolP2PServer.RecentPeers, backend.downloadServer)
......
...@@ -139,7 +139,7 @@ type Config struct { ...@@ -139,7 +139,7 @@ type Config struct {
Prune prune.Mode Prune prune.Mode
BatchSize datasize.ByteSize // Batch size for execution stage 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 Snapshot Snapshot
......
...@@ -8,7 +8,9 @@ import ( ...@@ -8,7 +8,9 @@ import (
"github.com/c2h5oh/datasize" "github.com/c2h5oh/datasize"
"github.com/ledgerwatch/erigon-lib/kv" "github.com/ledgerwatch/erigon-lib/kv"
"github.com/ledgerwatch/erigon/cmd/utils" "github.com/ledgerwatch/erigon/cmd/utils"
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/common/etl" "github.com/ledgerwatch/erigon/common/etl"
"github.com/ledgerwatch/erigon/common/hexutil"
"github.com/ledgerwatch/erigon/eth/ethconfig" "github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/ethdb/prune" "github.com/ledgerwatch/erigon/ethdb/prune"
"github.com/ledgerwatch/erigon/node" "github.com/ledgerwatch/erigon/node"
...@@ -150,10 +152,10 @@ var ( ...@@ -150,10 +152,10 @@ var (
Value: "", Value: "",
} }
BadBlockFlag = cli.IntFlag{ BadBlockFlag = cli.StringFlag{
Name: "bad.block", Name: "bad.block",
Usage: "Marks block with given number bad and forces initial reorg before normal staged sync", Usage: "Marks block with given hex string as bad and forces initial reorg before normal staged sync",
Value: 0, Value: "",
} }
) )
...@@ -207,7 +209,12 @@ func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) { ...@@ -207,7 +209,12 @@ func ApplyFlagsForEthConfig(ctx *cli.Context, cfg *ethconfig.Config) {
} }
cfg.SyncLoopThrottle = syncLoopThrottle 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) { 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