mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd, core/state: snapshot dump can skip EOA or CA
This commit is contained in:
parent
45a272c7b9
commit
a2ad6e1e86
4 changed files with 27 additions and 2 deletions
|
|
@ -177,6 +177,8 @@ It's deprecated, please use "geth db import" instead.
|
||||||
utils.IterativeOutputFlag,
|
utils.IterativeOutputFlag,
|
||||||
utils.ExcludeCodeFlag,
|
utils.ExcludeCodeFlag,
|
||||||
utils.ExcludeStorageFlag,
|
utils.ExcludeStorageFlag,
|
||||||
|
utils.ExcludeContractFlag,
|
||||||
|
utils.ExcludeEOAFlag,
|
||||||
utils.IncludeIncompletesFlag,
|
utils.IncludeIncompletesFlag,
|
||||||
utils.StartKeyFlag,
|
utils.StartKeyFlag,
|
||||||
utils.DumpLimitFlag,
|
utils.DumpLimitFlag,
|
||||||
|
|
@ -564,13 +566,15 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth
|
||||||
var conf = &state.DumpConfig{
|
var conf = &state.DumpConfig{
|
||||||
SkipCode: ctx.Bool(utils.ExcludeCodeFlag.Name),
|
SkipCode: ctx.Bool(utils.ExcludeCodeFlag.Name),
|
||||||
SkipStorage: ctx.Bool(utils.ExcludeStorageFlag.Name),
|
SkipStorage: ctx.Bool(utils.ExcludeStorageFlag.Name),
|
||||||
|
SkipContract: ctx.Bool(utils.ExcludeContractFlag.Name),
|
||||||
|
SkipEOA: ctx.Bool(utils.ExcludeEOAFlag.Name),
|
||||||
OnlyWithAddresses: !ctx.Bool(utils.IncludeIncompletesFlag.Name),
|
OnlyWithAddresses: !ctx.Bool(utils.IncludeIncompletesFlag.Name),
|
||||||
Start: start.Bytes(),
|
Start: start.Bytes(),
|
||||||
Max: ctx.Uint64(utils.DumpLimitFlag.Name),
|
Max: ctx.Uint64(utils.DumpLimitFlag.Name),
|
||||||
}
|
}
|
||||||
log.Info("State dump configured", "block", header.Number, "hash", header.Hash().Hex(),
|
log.Info("State dump configured", "block", header.Number, "hash", header.Hash().Hex(),
|
||||||
"skipcode", conf.SkipCode, "skipstorage", conf.SkipStorage,
|
"skipcode", conf.SkipCode, "skipstorage", conf.SkipStorage, "skipcontract", conf.SkipContract,
|
||||||
"start", hexutil.Encode(conf.Start), "limit", conf.Max)
|
"skipeoa", conf.SkipEOA, "start", hexutil.Encode(conf.Start), "limit", conf.Max)
|
||||||
return conf, db, header.Root, nil
|
return conf, db, header.Root, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,8 @@ It's also usable without snapshot enabled.
|
||||||
Flags: flags.Merge([]cli.Flag{
|
Flags: flags.Merge([]cli.Flag{
|
||||||
utils.ExcludeCodeFlag,
|
utils.ExcludeCodeFlag,
|
||||||
utils.ExcludeStorageFlag,
|
utils.ExcludeStorageFlag,
|
||||||
|
utils.ExcludeContractFlag,
|
||||||
|
utils.ExcludeEOAFlag,
|
||||||
utils.StartKeyFlag,
|
utils.StartKeyFlag,
|
||||||
utils.DumpLimitFlag,
|
utils.DumpLimitFlag,
|
||||||
}, utils.NetworkFlags, utils.DatabaseFlags),
|
}, utils.NetworkFlags, utils.DatabaseFlags),
|
||||||
|
|
@ -545,6 +547,9 @@ func dumpState(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if conf.SkipEOA && conf.SkipContract {
|
||||||
|
return fmt.Errorf("both EOA and contract accounts are skipped, nothing to dump")
|
||||||
|
}
|
||||||
triedb := utils.MakeTrieDatabase(ctx, db, false, true, false)
|
triedb := utils.MakeTrieDatabase(ctx, db, false, true, false)
|
||||||
defer triedb.Close()
|
defer triedb.Close()
|
||||||
|
|
||||||
|
|
@ -579,6 +584,12 @@ func dumpState(ctx *cli.Context) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
if conf.SkipContract && !bytes.Equal(account.CodeHash, types.EmptyCodeHash.Bytes()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if conf.SkipEOA && bytes.Equal(account.CodeHash, types.EmptyCodeHash.Bytes()) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
da := &state.DumpAccount{
|
da := &state.DumpAccount{
|
||||||
Balance: account.Balance.String(),
|
Balance: account.Balance.String(),
|
||||||
Nonce: account.Nonce,
|
Nonce: account.Nonce,
|
||||||
|
|
|
||||||
|
|
@ -208,6 +208,14 @@ var (
|
||||||
Name: "nocode",
|
Name: "nocode",
|
||||||
Usage: "Exclude contract code (save db lookups)",
|
Usage: "Exclude contract code (save db lookups)",
|
||||||
}
|
}
|
||||||
|
ExcludeContractFlag = &cli.BoolFlag{
|
||||||
|
Name: "nocontract",
|
||||||
|
Usage: "Exclude contract accounts",
|
||||||
|
}
|
||||||
|
ExcludeEOAFlag = &cli.BoolFlag{
|
||||||
|
Name: "noeoa",
|
||||||
|
Usage: "Exclude EOA accounts",
|
||||||
|
}
|
||||||
StartKeyFlag = &cli.StringFlag{
|
StartKeyFlag = &cli.StringFlag{
|
||||||
Name: "start",
|
Name: "start",
|
||||||
Usage: "Start position. Either a hash or address",
|
Usage: "Start position. Either a hash or address",
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,8 @@ import (
|
||||||
type DumpConfig struct {
|
type DumpConfig struct {
|
||||||
SkipCode bool
|
SkipCode bool
|
||||||
SkipStorage bool
|
SkipStorage bool
|
||||||
|
SkipContract bool
|
||||||
|
SkipEOA bool
|
||||||
OnlyWithAddresses bool
|
OnlyWithAddresses bool
|
||||||
Start []byte
|
Start []byte
|
||||||
Max uint64
|
Max uint64
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue