Skip to content

Commit

Permalink
fix: block inspect
Browse files Browse the repository at this point in the history
  • Loading branch information
jingjunLi committed Jun 28, 2024
1 parent 00aaed0 commit 2449752
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/geth/dbcmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Remove blockchain and state databases`,
dbExportCmd,
dbMetadataCmd,
ancientInspectCmd,
blockInspectCmd,
// no legacy stored receipts for bsc
// dbMigrateFreezerCmd,
dbCheckStateContentCmd,
Expand Down Expand Up @@ -284,6 +285,18 @@ WARNING: This is a low-level operation which may cause database corruption!`,
},
Usage: "Inspect the ancientStore information",
Description: `This commands will read current offset from kvdb, which is the current offset and starting BlockNumber
of ancientStore, will also displays the reserved number of blocks in ancientStore `,
}
blockInspectCmd = &cli.Command{
Action: blockInspect,
Name: "inspect-blocks",
Flags: []cli.Flag{
utils.DataDirFlag,
utils.EndFlag,
utils.StartFlag,
},
Usage: "Inspect the ancientStore information",
Description: `This commands will read current offset from kvdb, which is the current offset and starting BlockNumber
of ancientStore, will also displays the reserved number of blocks in ancientStore `,
}
)
Expand Down Expand Up @@ -504,6 +517,19 @@ func inspect(ctx *cli.Context) error {
return rawdb.InspectDatabase(db, prefix, start)
}

func blockInspect(ctx *cli.Context) error {
stack, _ := makeConfigNode(ctx)
defer stack.Close()

db := utils.MakeChainDatabase(ctx, stack, true, false)
defer db.Close()
var (
start = ctx.Int(utils.StartFlag.Name)
end = ctx.Int(utils.EndFlag.Name)
)
return rawdb.BlocksInspect(db, uint64(start), uint64(end))
}

func ancientInspect(ctx *cli.Context) error {
stack, _ := makeConfigNode(ctx)
defer stack.Close()
Expand Down
12 changes: 12 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,18 @@ var (
Value: 1024,
Category: flags.PerfCategory,
}
StartFlag = &cli.IntFlag{
Name: "start",
Usage: "Megabytes of memory allocated to internal caching (default = 4096 mainnet full node, 128 light mode)",
Value: 1024,
Category: flags.PerfCategory,
}
EndFlag = &cli.IntFlag{
Name: "end",
Usage: "Megabytes of memory allocated to internal caching (default = 4096 mainnet full node, 128 light mode)",
Value: 1024,
Category: flags.PerfCategory,
}
CacheDatabaseFlag = &cli.IntFlag{
Name: "cache.database",
Usage: "Percentage of cache memory allowance to use for database io",
Expand Down
14 changes: 14 additions & 0 deletions core/rawdb/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,20 @@ func AncientInspect(db ethdb.Database) error {
return nil
}

func BlocksInspect(db ethdb.Database, start, end uint64) error {
for num := start; num < end; num++ {
hash := ReadCanonicalHash(db, num)
if hash == (common.Hash{}) {
return nil
}
block := ReadBlock(db, hash, num)

log.Info("blocksInspect", "number", num, "block", block)
}

return nil
}

func PruneHashTrieNodeInDataBase(db ethdb.Database) error {
it := db.NewIterator([]byte{}, []byte{})
defer it.Release()
Expand Down

0 comments on commit 2449752

Please sign in to comment.