mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
review feedback
This commit is contained in:
parent
3e49cebdef
commit
2fdc0da8b8
3 changed files with 42 additions and 37 deletions
|
|
@ -171,8 +171,8 @@ This command dumps out the state for a given block (or latest, if none provided)
|
||||||
Action: exportSnapshotPreimages,
|
Action: exportSnapshotPreimages,
|
||||||
Name: "export-snapshot-preimages",
|
Name: "export-snapshot-preimages",
|
||||||
Usage: "Export the preimage in snapshot enumeration order",
|
Usage: "Export the preimage in snapshot enumeration order",
|
||||||
ArgsUsage: "<dumpfile>",
|
ArgsUsage: "<dumpfile> [<root>]",
|
||||||
Flags: flags.Merge([]cli.Flag{utils.TreeRootFlag}, utils.DatabaseFlags),
|
Flags: utils.DatabaseFlags,
|
||||||
Description: `
|
Description: `
|
||||||
The export-snapshot-preimages command exports hash preimages to a flat file, in exactly
|
The export-snapshot-preimages command exports hash preimages to a flat file, in exactly
|
||||||
the expected order for the overlay tree migration.
|
the expected order for the overlay tree migration.
|
||||||
|
|
@ -428,8 +428,8 @@ func exportSnapshotPreimages(ctx *cli.Context) error {
|
||||||
chain, _ := utils.MakeChain(ctx, stack, true)
|
chain, _ := utils.MakeChain(ctx, stack, true)
|
||||||
|
|
||||||
var root common.Hash
|
var root common.Hash
|
||||||
if ctx.String(utils.TreeRootFlag.Name) != "" {
|
if ctx.Args().Len() > 1 {
|
||||||
rootBytes := common.FromHex(ctx.String(utils.StartKeyFlag.Name))
|
rootBytes := common.FromHex(ctx.Args().Get(1))
|
||||||
if len(rootBytes) != common.HashLength {
|
if len(rootBytes) != common.HashLength {
|
||||||
return fmt.Errorf("invalid root hash length")
|
return fmt.Errorf("invalid root hash length")
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -397,9 +397,18 @@ func ExportSnapshotPreimages(chain *core.BlockChain, fn string, root common.Hash
|
||||||
root = chain.CurrentBlock().Root
|
root = chain.CurrentBlock().Root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type hashAndPreimageSize struct {
|
||||||
|
Hash common.Hash
|
||||||
|
Size int
|
||||||
|
}
|
||||||
|
var hashCh chan hashAndPreimageSize
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer close(hashCh)
|
||||||
accIt, err := chain.Snapshots().AccountIterator(root, common.Hash{})
|
accIt, err := chain.Snapshots().AccountIterator(root, common.Hash{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
log.Error("failed to create account iterator", "error", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer accIt.Release()
|
defer accIt.Release()
|
||||||
|
|
||||||
|
|
@ -407,29 +416,19 @@ func ExportSnapshotPreimages(chain *core.BlockChain, fn string, root common.Hash
|
||||||
for accIt.Next() {
|
for accIt.Next() {
|
||||||
acc, err := types.FullAccount(accIt.Account())
|
acc, err := types.FullAccount(accIt.Account())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("invalid account encountered during traversal: %s", err)
|
log.Error("failed to get full account", "error", err)
|
||||||
}
|
return
|
||||||
addr := rawdb.ReadPreimage(statedb.Database().DiskDB(), accIt.Hash())
|
|
||||||
if len(addr) != 20 {
|
|
||||||
return fmt.Errorf("addr len is zero is not 32: %d", len(addr))
|
|
||||||
}
|
|
||||||
if _, err := writer.Write(addr); err != nil {
|
|
||||||
return fmt.Errorf("failed to write addr preimage: %w", err)
|
|
||||||
}
|
}
|
||||||
|
hashCh <- hashAndPreimageSize{Hash: accIt.Hash(), Size: 20}
|
||||||
|
|
||||||
if acc.Root != (common.Hash{}) && acc.Root != types.EmptyRootHash {
|
if acc.Root != (common.Hash{}) && acc.Root != types.EmptyRootHash {
|
||||||
stIt, err := chain.Snapshots().StorageIterator(root, accIt.Hash(), common.Hash{})
|
stIt, err := chain.Snapshots().StorageIterator(root, accIt.Hash(), common.Hash{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to create storage iterator: %w", err)
|
log.Error("failed to create storage iterator", "error", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
for stIt.Next() {
|
for stIt.Next() {
|
||||||
slotnr := rawdb.ReadPreimage(statedb.Database().DiskDB(), stIt.Hash())
|
hashCh <- hashAndPreimageSize{Hash: stIt.Hash(), Size: 32}
|
||||||
if len(slotnr) != 32 {
|
|
||||||
return fmt.Errorf("slotnr not 32 len")
|
|
||||||
}
|
|
||||||
if _, err := writer.Write(slotnr); err != nil {
|
|
||||||
return fmt.Errorf("failed to write slotnr preimage: %w", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
stIt.Release()
|
stIt.Release()
|
||||||
}
|
}
|
||||||
|
|
@ -438,6 +437,17 @@ func ExportSnapshotPreimages(chain *core.BlockChain, fn string, root common.Hash
|
||||||
log.Info("Last exported account", "account", accIt.Hash())
|
log.Info("Last exported account", "account", accIt.Hash())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
for item := range hashCh {
|
||||||
|
preimage := rawdb.ReadPreimage(statedb.Database().DiskDB(), item.Hash)
|
||||||
|
if len(preimage) != item.Size {
|
||||||
|
return fmt.Errorf("invalid preimage size")
|
||||||
|
}
|
||||||
|
if _, err := writer.Write(preimage); err != nil {
|
||||||
|
return fmt.Errorf("failed to write preimage: %w", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Info("Exported preimages", "file", fn)
|
log.Info("Exported preimages", "file", fn)
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
|
|
@ -219,11 +219,6 @@ var (
|
||||||
Usage: "Max number of elements (0 = no limit)",
|
Usage: "Max number of elements (0 = no limit)",
|
||||||
Value: 0,
|
Value: 0,
|
||||||
}
|
}
|
||||||
TreeRootFlag = &cli.StringFlag{
|
|
||||||
Name: "roothash",
|
|
||||||
Usage: "Root hash of the tree (if empty, use that of current block)",
|
|
||||||
Value: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
defaultSyncMode = ethconfig.Defaults.SyncMode
|
defaultSyncMode = ethconfig.Defaults.SyncMode
|
||||||
SnapshotFlag = &cli.BoolFlag{
|
SnapshotFlag = &cli.BoolFlag{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue