mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +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,13 +808,14 @@ func inspectHistory(ctx *cli.Context) error {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
start uint64 // the first history object to query
|
start uint64 // the id of first history object to query
|
||||||
end uint64 // the last history object to query (included)
|
end uint64 // the id (included) of last history object to query
|
||||||
|
stats *pathdb.HistoryStats // inspection result
|
||||||
// State histories are sorted by state ID rather than block number.
|
)
|
||||||
// To address this, load the corresponding block header and perform
|
// State histories are identified by state ID rather than block number.
|
||||||
// the conversion by this function.
|
// To address this, load the corresponding block header and perform the
|
||||||
blockToID = func(blockNumber uint64) (uint64, error) {
|
// conversion by this function.
|
||||||
|
blockToID := func(blockNumber uint64) (uint64, error) {
|
||||||
header := rawdb.ReadHeader(db, rawdb.ReadCanonicalHash(db, blockNumber), blockNumber)
|
header := rawdb.ReadHeader(db, rawdb.ReadCanonicalHash(db, blockNumber), blockNumber)
|
||||||
if header == nil {
|
if header == nil {
|
||||||
return 0, fmt.Errorf("block #%d is not existent", blockNumber)
|
return 0, fmt.Errorf("block #%d is not existent", blockNumber)
|
||||||
|
|
@ -829,7 +830,7 @@ func inspectHistory(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
return *id, nil
|
return *id, nil
|
||||||
}
|
}
|
||||||
)
|
// Parse the starting block number for inspection.
|
||||||
startNumber := ctx.Uint64("start")
|
startNumber := ctx.Uint64("start")
|
||||||
if startNumber != 0 {
|
if startNumber != 0 {
|
||||||
start, err = blockToID(startNumber)
|
start, err = blockToID(startNumber)
|
||||||
|
|
@ -837,6 +838,7 @@ func inspectHistory(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Parse the ending block number for inspection.
|
||||||
endBlock := ctx.Uint64("end")
|
endBlock := ctx.Uint64("end")
|
||||||
if endBlock != 0 {
|
if endBlock != 0 {
|
||||||
end, err = blockToID(endBlock)
|
end, err = blockToID(endBlock)
|
||||||
|
|
@ -844,7 +846,7 @@ func inspectHistory(ctx *cli.Context) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var stats *pathdb.HistoryStats
|
// Inspect the state history.
|
||||||
if slot == (common.Hash{}) {
|
if slot == (common.Hash{}) {
|
||||||
stats, err = triedb.AccountHistory(address, start, end)
|
stats, err = triedb.AccountHistory(address, start, end)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -856,14 +858,15 @@ func inspectHistory(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Print out the result.
|
||||||
if slot == (common.Hash{}) {
|
if slot == (common.Hash{}) {
|
||||||
fmt.Printf("Account history: %s\n", address.Hex())
|
fmt.Printf("Account history:\n\taddress: %s\n", address.Hex())
|
||||||
} else {
|
} 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)
|
fmt.Printf("Range: [#%d-#%d]\n\n", stats.Start, stats.End)
|
||||||
for i := 0; i < len(stats.Blocks); i++ {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,8 @@ func inspectHistory(freezer *rawdb.ResettableFreezer, start, end uint64, onHisto
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
for id := start; id <= end; id += 1 {
|
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)
|
h, err := readHistory(freezer, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue