mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
cmd, triedb: address comments from martin
This commit is contained in:
parent
6eff5e2eef
commit
b6db26b01b
2 changed files with 30 additions and 25 deletions
|
|
@ -808,28 +808,29 @@ func inspectHistory(ctx *cli.Context) error {
|
|||
|
||||
var (
|
||||
err error
|
||||
start uint64 // the first history object to query
|
||||
end uint64 // the last history object to query (included)
|
||||
|
||||
// State histories are sorted by state ID rather than block number.
|
||||
// To address this, load the corresponding block header and perform
|
||||
// the conversion by this function.
|
||||
blockToID = func(blockNumber uint64) (uint64, error) {
|
||||
header := rawdb.ReadHeader(db, rawdb.ReadCanonicalHash(db, blockNumber), blockNumber)
|
||||
if header == nil {
|
||||
return 0, fmt.Errorf("block #%d is not existent", blockNumber)
|
||||
}
|
||||
id := rawdb.ReadStateID(db, header.Root)
|
||||
if id == nil {
|
||||
first, last, err := triedb.HistoryRange()
|
||||
if err == nil {
|
||||
return 0, fmt.Errorf("history of block #%d is not existent, available history range: [#%d-#%d]", blockNumber, first, last)
|
||||
}
|
||||
return 0, fmt.Errorf("history of block #%d is not existent", blockNumber)
|
||||
}
|
||||
return *id, nil
|
||||
}
|
||||
start uint64 // the id of first history object to query
|
||||
end uint64 // the id (included) of last history object to query
|
||||
stats *pathdb.HistoryStats // inspection result
|
||||
)
|
||||
// State histories are identified by state ID rather than block number.
|
||||
// To address this, load the corresponding block header and perform the
|
||||
// conversion by this function.
|
||||
blockToID := func(blockNumber uint64) (uint64, error) {
|
||||
header := rawdb.ReadHeader(db, rawdb.ReadCanonicalHash(db, blockNumber), blockNumber)
|
||||
if header == nil {
|
||||
return 0, fmt.Errorf("block #%d is not existent", blockNumber)
|
||||
}
|
||||
id := rawdb.ReadStateID(db, header.Root)
|
||||
if id == nil {
|
||||
first, last, err := triedb.HistoryRange()
|
||||
if err == nil {
|
||||
return 0, fmt.Errorf("history of block #%d is not existent, available history range: [#%d-#%d]", blockNumber, first, last)
|
||||
}
|
||||
return 0, fmt.Errorf("history of block #%d is not existent", blockNumber)
|
||||
}
|
||||
return *id, nil
|
||||
}
|
||||
// Parse the starting block number for inspection.
|
||||
startNumber := ctx.Uint64("start")
|
||||
if startNumber != 0 {
|
||||
start, err = blockToID(startNumber)
|
||||
|
|
@ -837,6 +838,7 @@ func inspectHistory(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
// Parse the ending block number for inspection.
|
||||
endBlock := ctx.Uint64("end")
|
||||
if endBlock != 0 {
|
||||
end, err = blockToID(endBlock)
|
||||
|
|
@ -844,7 +846,7 @@ func inspectHistory(ctx *cli.Context) error {
|
|||
return err
|
||||
}
|
||||
}
|
||||
var stats *pathdb.HistoryStats
|
||||
// Inspect the state history.
|
||||
if slot == (common.Hash{}) {
|
||||
stats, err = triedb.AccountHistory(address, start, end)
|
||||
} else {
|
||||
|
|
@ -856,14 +858,15 @@ func inspectHistory(ctx *cli.Context) error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Print out the result.
|
||||
if slot == (common.Hash{}) {
|
||||
fmt.Printf("Account history: %s\n", address.Hex())
|
||||
fmt.Printf("Account history:\n\taddress: %s\n", address.Hex())
|
||||
} else {
|
||||
fmt.Printf("Storage history: %s-%s\n", address.Hex(), slot.Hex())
|
||||
fmt.Printf("Storage history:\n\taddress: %s\n\tslot: %s\n", address.Hex(), slot.Hex())
|
||||
}
|
||||
fmt.Printf("Range: [#%d-#%d]\n\n", stats.Start, stats.End)
|
||||
for i := 0; i < len(stats.Blocks); i++ {
|
||||
fmt.Printf("#%d: %x\n", stats.Blocks[i], stats.Origins[i])
|
||||
fmt.Printf("#%d: %#x\n", stats.Blocks[i], stats.Origins[i])
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,6 +71,8 @@ func inspectHistory(freezer *rawdb.ResettableFreezer, start, end uint64, onHisto
|
|||
return nil, err
|
||||
}
|
||||
for id := start; id <= end; id += 1 {
|
||||
// The entire history object is decoded, although it's unnecessary for
|
||||
// account inspection. TODO(rjl493456442) optimization is worthwhile.
|
||||
h, err := readHistory(freezer, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
|||
Loading…
Reference in a new issue