From 354ba1a9475769aeae781b5e2ea4bb8b384b78f5 Mon Sep 17 00:00:00 2001 From: gladcow Date: Fri, 28 Jul 2023 04:28:47 +0300 Subject: [PATCH] Adds clear_bad_blocks command (#7934) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adds `clear_bad_blocks` command to integration tool. This command allows to re-process blocks that were erroneously marked as bad. Command just clears `BadHeaderNumber` table. It can be safer in some cases than ``` ./integration state_stages —unwind= ./integration stage_headers —unwind= ``` and can be used in the cases like this one https://github.com/ledgerwatch/erigon/issues/7892%20 Command syntax: ``` ./integration clear_bad_blocks --datadir= ``` --- cmd/integration/Readme.md | 6 ++++++ cmd/integration/commands/reset_state.go | 23 +++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/cmd/integration/Readme.md b/cmd/integration/Readme.md index 992868b867d..eceb59b710b 100644 --- a/cmd/integration/Readme.md +++ b/cmd/integration/Readme.md @@ -87,4 +87,10 @@ make all 3. Stop Erigon again after about 1 minute (Steps 2 and 3 create a new empty db in /path/to/copy-to/chaindata ) 4. Build integration: cd erigon; make integration 5. Run: ./build/bin/integration mdbx_to_mdbx --chaindata /existing/erigon/path/chaindata/ --chaindata.to /path/to/copy-to/chaindata/ +``` + +## Clear bad blocks table in the case some block was marked as invalid after some error +It allows to process this blocks again +``` +1. ./build/bin/integration clear_bad_blocks --datadir= ``` \ No newline at end of file diff --git a/cmd/integration/commands/reset_state.go b/cmd/integration/commands/reset_state.go index 28bc13b293f..0dd01f94a77 100644 --- a/cmd/integration/commands/reset_state.go +++ b/cmd/integration/commands/reset_state.go @@ -5,6 +5,7 @@ import ( "encoding/binary" "errors" "fmt" + "github.com/ledgerwatch/erigon/turbo/backup" "os" "text/tabwriter" @@ -64,12 +65,34 @@ var cmdResetState = &cobra.Command{ }, } +var cmdClearBadBlocks = &cobra.Command{ + Use: "clear_bad_blocks", + Short: "Clear table with bad block hashes to allow to process this blocks one more time", + RunE: func(cmd *cobra.Command, args []string) error { + logger := debug.SetupCobra(cmd, "integration") + ctx, _ := common.RootContext() + db, err := openDB(dbCfg(kv.ChainDB, chaindata), true, logger) + if err != nil { + logger.Error("Opening DB", "error", err) + return err + } + defer db.Close() + + return db.Update(ctx, func(tx kv.RwTx) error { + return backup.ClearTable(ctx, db, tx, "BadHeaderNumber") + }) + }, +} + func init() { withConfig(cmdResetState) withDataDir(cmdResetState) withChain(cmdResetState) rootCmd.AddCommand(cmdResetState) + + withDataDir(cmdClearBadBlocks) + rootCmd.AddCommand(cmdClearBadBlocks) } func printStages(tx kv.Tx, snapshots *freezeblocks.RoSnapshots, agg *state.AggregatorV3) error {