Skip to content

Commit

Permalink
Adds clear_bad_blocks command (#7934)
Browse files Browse the repository at this point in the history
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=<some_number>
./integration stage_headers —unwind=<some_number>
```
and can be used in the cases like this one
#7892

Command syntax:
```
./integration clear_bad_blocks --datadir=<datadir>
```
  • Loading branch information
gladcow committed Jul 28, 2023
1 parent a0865b4 commit 7e3c6ea
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cmd/integration/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<datadir>
```
23 changes: 23 additions & 0 deletions cmd/integration/commands/reset_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/binary"
"errors"
"fmt"
"github.com/ledgerwatch/erigon/turbo/backup"
"os"
"text/tabwriter"

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 7e3c6ea

Please sign in to comment.