core/state, cmd/geth: streaming json output for dump command (#15475)

* core/state, cmd/geth: streaming json output dump cmd + optional code+storage

* dump: add option to continue even if preimages are missing

* core, evm: lint nits

* cmd: use local flags for dump, omit empty code/storage

* core/state: fix state dump test
This commit is contained in:
Martin Holst Swende
2019-06-24 16:16:44 +02:00
committed by Péter Szilágyi
parent e4a1488b2f
commit 1da5e0ebb0
7 changed files with 143 additions and 45 deletions

View File

@ -209,7 +209,7 @@ func runCmd(ctx *cli.Context) error {
if ctx.GlobalBool(DumpFlag.Name) {
statedb.Commit(true)
statedb.IntermediateRoot(true)
fmt.Println(string(statedb.Dump()))
fmt.Println(string(statedb.Dump(false, false, true)))
}
if memProfilePath := ctx.GlobalString(MemProfileFlag.Name); memProfilePath != "" {

View File

@ -105,7 +105,7 @@ func stateTestCmd(ctx *cli.Context) error {
// Test failed, mark as so and dump any state to aid debugging
result.Pass, result.Error = false, err.Error()
if ctx.GlobalBool(DumpFlag.Name) && state != nil {
dump := state.RawDump()
dump := state.RawDump(false, false, true)
result.State = &dump
}
}

View File

@ -162,6 +162,10 @@ Remove blockchain and state databases`,
utils.DataDirFlag,
utils.CacheFlag,
utils.SyncModeFlag,
utils.IterativeOutputFlag,
utils.ExcludeCodeFlag,
utils.ExcludeStorageFlag,
utils.IncludeIncompletesFlag,
},
Category: "BLOCKCHAIN COMMANDS",
Description: `
@ -287,7 +291,7 @@ func importChain(ctx *cli.Context) error {
fmt.Printf("Allocations: %.3f million\n", float64(mem.Mallocs)/1000000)
fmt.Printf("GC pause: %v\n\n", time.Duration(mem.PauseTotalNs))
if ctx.GlobalIsSet(utils.NoCompactionFlag.Name) {
if ctx.GlobalBool(utils.NoCompactionFlag.Name) {
return nil
}
@ -504,6 +508,7 @@ func dump(ctx *cli.Context) error {
defer stack.Close()
chain, chainDb := utils.MakeChain(ctx, stack)
defer chainDb.Close()
for _, arg := range ctx.Args() {
var block *types.Block
if hashish(arg) {
@ -520,10 +525,20 @@ func dump(ctx *cli.Context) error {
if err != nil {
utils.Fatalf("could not create new state: %v", err)
}
fmt.Printf("%s\n", state.Dump())
excludeCode := ctx.Bool(utils.ExcludeCodeFlag.Name)
excludeStorage := ctx.Bool(utils.ExcludeStorageFlag.Name)
includeMissing := ctx.Bool(utils.IncludeIncompletesFlag.Name)
if ctx.Bool(utils.IterativeOutputFlag.Name) {
state.IterativeDump(excludeCode, excludeStorage, !includeMissing, json.NewEncoder(os.Stdout))
} else {
if includeMissing {
fmt.Printf("If you want to include accounts with missing preimages, you need iterative output, since" +
" otherwise the accounts will overwrite each other in the resulting mapping.")
}
fmt.Printf("%v %s\n", includeMissing, state.Dump(excludeCode, excludeStorage, false))
}
}
}
chainDb.Close()
return nil
}

View File

@ -196,6 +196,22 @@ var (
Name: "ulc.trusted",
Usage: "List of trusted ULC servers",
}
IterativeOutputFlag = cli.BoolFlag{
Name: "iterative",
Usage: "Print streaming JSON iteratively, delimited by newlines",
}
ExcludeStorageFlag = cli.BoolFlag{
Name: "nostorage",
Usage: "Exclude storage entries (save db lookups)",
}
IncludeIncompletesFlag = cli.BoolFlag{
Name: "incompletes",
Usage: "Include accounts for which we don't have the address (missing preimage)",
}
ExcludeCodeFlag = cli.BoolFlag{
Name: "nocode",
Usage: "Exclude contract code (save db lookups)",
}
defaultSyncMode = eth.DefaultConfig.SyncMode
SyncModeFlag = TextMarshalerFlag{
Name: "syncmode",