|
|
|
@ -514,13 +514,10 @@ func importPreimages(ctx *cli.Context) error { |
|
|
|
|
return nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, ethdb.Database, common.Hash, error) { |
|
|
|
|
db := utils.MakeChainDatabase(ctx, stack, true) |
|
|
|
|
defer db.Close() |
|
|
|
|
|
|
|
|
|
func parseDumpConfig(ctx *cli.Context, stack *node.Node, db ethdb.Database) (*state.DumpConfig, common.Hash, error) { |
|
|
|
|
var header *types.Header |
|
|
|
|
if ctx.NArg() > 1 { |
|
|
|
|
return nil, nil, common.Hash{}, fmt.Errorf("expected 1 argument (number or hash), got %d", ctx.NArg()) |
|
|
|
|
return nil, common.Hash{}, fmt.Errorf("expected 1 argument (number or hash), got %d", ctx.NArg()) |
|
|
|
|
} |
|
|
|
|
if ctx.NArg() == 1 { |
|
|
|
|
arg := ctx.Args().First() |
|
|
|
@ -529,17 +526,17 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth |
|
|
|
|
if number := rawdb.ReadHeaderNumber(db, hash); number != nil { |
|
|
|
|
header = rawdb.ReadHeader(db, hash, *number) |
|
|
|
|
} else { |
|
|
|
|
return nil, nil, common.Hash{}, fmt.Errorf("block %x not found", hash) |
|
|
|
|
return nil, common.Hash{}, fmt.Errorf("block %x not found", hash) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
number, err := strconv.ParseUint(arg, 10, 64) |
|
|
|
|
if err != nil { |
|
|
|
|
return nil, nil, common.Hash{}, err |
|
|
|
|
return nil, common.Hash{}, err |
|
|
|
|
} |
|
|
|
|
if hash := rawdb.ReadCanonicalHash(db, number); hash != (common.Hash{}) { |
|
|
|
|
header = rawdb.ReadHeader(db, hash, number) |
|
|
|
|
} else { |
|
|
|
|
return nil, nil, common.Hash{}, fmt.Errorf("header for block %d not found", number) |
|
|
|
|
return nil, common.Hash{}, fmt.Errorf("header for block %d not found", number) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
@ -547,7 +544,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth |
|
|
|
|
header = rawdb.ReadHeadHeader(db) |
|
|
|
|
} |
|
|
|
|
if header == nil { |
|
|
|
|
return nil, nil, common.Hash{}, errors.New("no head block found") |
|
|
|
|
return nil, common.Hash{}, errors.New("no head block found") |
|
|
|
|
} |
|
|
|
|
startArg := common.FromHex(ctx.String(utils.StartKeyFlag.Name)) |
|
|
|
|
var start common.Hash |
|
|
|
@ -559,7 +556,7 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth |
|
|
|
|
start = crypto.Keccak256Hash(startArg) |
|
|
|
|
log.Info("Converting start-address to hash", "address", common.BytesToAddress(startArg), "hash", start.Hex()) |
|
|
|
|
default: |
|
|
|
|
return nil, nil, common.Hash{}, fmt.Errorf("invalid start argument: %x. 20 or 32 hex-encoded bytes required", startArg) |
|
|
|
|
return nil, common.Hash{}, fmt.Errorf("invalid start argument: %x. 20 or 32 hex-encoded bytes required", startArg) |
|
|
|
|
} |
|
|
|
|
var conf = &state.DumpConfig{ |
|
|
|
|
SkipCode: ctx.Bool(utils.ExcludeCodeFlag.Name), |
|
|
|
@ -571,14 +568,17 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth |
|
|
|
|
log.Info("State dump configured", "block", header.Number, "hash", header.Hash().Hex(), |
|
|
|
|
"skipcode", conf.SkipCode, "skipstorage", conf.SkipStorage, |
|
|
|
|
"start", hexutil.Encode(conf.Start), "limit", conf.Max) |
|
|
|
|
return conf, db, header.Root, nil |
|
|
|
|
return conf, header.Root, nil |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
func dump(ctx *cli.Context) error { |
|
|
|
|
stack, _ := makeConfigNode(ctx) |
|
|
|
|
defer stack.Close() |
|
|
|
|
|
|
|
|
|
conf, db, root, err := parseDumpConfig(ctx, stack) |
|
|
|
|
db := utils.MakeChainDatabase(ctx, stack, true) |
|
|
|
|
defer db.Close() |
|
|
|
|
|
|
|
|
|
conf, root, err := parseDumpConfig(ctx, stack, db) |
|
|
|
|
if err != nil { |
|
|
|
|
return err |
|
|
|
|
} |
|
|
|
|