cmd, eth: implement flag delete-all-bad-blocks (#1770)

This commit is contained in:
Daniel Liu 2025-11-15 19:20:52 +08:00 committed by GitHub
parent c66f8f9fb2
commit de9ed732e2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 24 additions and 0 deletions

View file

@ -138,6 +138,7 @@ var (
utils.AnnounceTxsFlag,
utils.StoreRewardFlag,
utils.SetHeadFlag,
utils.DeleteAllBadBlocksFlag,
utils.XDCSlaveModeFlag,
}, utils.NetworkFlags, utils.DatabaseFlags)

View file

@ -806,6 +806,11 @@ var (
}
// MISC settings
DeleteAllBadBlocksFlag = &cli.BoolFlag{
Name: "delete-all-bad-blocks",
Usage: "Delete all bad blocks in the database",
Category: flags.MiscCategory,
}
SetHeadFlag = &cli.Uint64Flag{
Name: "set-head",
Usage: "Rollback chain to block number",
@ -1553,6 +1558,9 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) {
os.Mkdir(common.StoreRewardFolder, os.ModePerm)
}
}
if ctx.Bool(DeleteAllBadBlocksFlag.Name) {
cfg.DeleteAllBadBlocks = true
}
if ctx.IsSet(SetHeadFlag.Name) {
common.RollbackNumber = ctx.Uint64(SetHeadFlag.Name)
if common.RollbackNumber == 0 {

View file

@ -177,6 +177,20 @@ func New(stack *node.Node, config *ethconfig.Config, XDCXServ *XDCx.XDCX, lendin
}
}
badBlocks := rawdb.ReadAllBadBlocks(chainDb)
log.Info("Bad blocks in db", "count", len(badBlocks))
for i, block := range badBlocks {
log.Info("Bad block in db", "i", i, "number", block.Number(), "hash", block.Hash().Hex())
}
if config.DeleteAllBadBlocks {
if len(badBlocks) == 0 {
log.Warn("No bad blocks in db to delete")
} else {
rawdb.DeleteBadBlocks(chainDb)
log.Info(fmt.Sprintf("Deleted %d bad blocks in db", len(badBlocks)))
}
}
var (
vmConfig = vm.Config{EnablePreimageRecording: config.EnablePreimageRecording}
cacheConfig = &core.CacheConfig{

View file

@ -81,6 +81,7 @@ type Config struct {
// Database options
SkipBcVersionCheck bool `toml:"-"`
DeleteAllBadBlocks bool `toml:"-"`
DatabaseHandles int `toml:"-"`
DatabaseCache int
TrieCleanCache int