From 839eae55fae446014e5dacdc2b874c74505efc69 Mon Sep 17 00:00:00 2001 From: VM Date: Wed, 17 Jan 2024 16:36:32 +0800 Subject: [PATCH] cmd: optimize parseDumpConfig func --- cmd/geth/chaincmd.go | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 18a8b6f5ff..c407600851 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -607,13 +607,19 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth arg := ctx.Args().First() if hashish(arg) { hash := common.HexToHash(arg) - if contain := triedb.ContainDiffLayer(hash); !contain { - log.Crit("PBSS doesn't contain specified hash", "hash", arg) - } + // if contain := triedb.ContainDiffLayer(hash); !contain { + // log.Crit("PBSS doesn't contain specified hash", "hash", arg) + // } if number := rawdb.ReadHeaderNumber(db, hash); number != nil { header = rawdb.ReadHeader(db, hash, *number) + if header == nil { + return nil, nil, common.Hash{}, fmt.Errorf("block_hash %x header not found", hash) + } } else { - return nil, nil, common.Hash{}, fmt.Errorf("block %x not found", hash) + return nil, nil, common.Hash{}, fmt.Errorf("block_hash %x not found", hash) + } + if contain := triedb.ContainDiffLayer(header.Root); !contain { + log.Crit("PBSS doesn't contain specified hash", "block_hash", arg, "mpt_root", header.Root) } } else { number, err := strconv.ParseUint(arg, 10, 64) @@ -621,12 +627,18 @@ func parseDumpConfig(ctx *cli.Context, stack *node.Node) (*state.DumpConfig, eth return nil, nil, common.Hash{}, err } if hash := rawdb.ReadCanonicalHash(db, number); hash != (common.Hash{}) { - if contain := triedb.ContainDiffLayer(hash); !contain { - log.Crit("PBSS doesn't contain specified block number", "number", number) - } + // if contain := triedb.ContainDiffLayer(hash); !contain { + // log.Crit("PBSS doesn't contain specified block number", "number", number) + // } header = rawdb.ReadHeader(db, hash, number) + if header == nil { + return nil, nil, common.Hash{}, fmt.Errorf("block_id %d header not found", number) + } + if contain := triedb.ContainDiffLayer(header.Root); !contain { + log.Crit("PBSS doesn't contain specified block number", "block_height", number, "mpt_root", header.Root) + } } else { - return nil, nil, common.Hash{}, fmt.Errorf("header for block %d not found", number) + return nil, nil, common.Hash{}, fmt.Errorf("header for block_height %d not found", number) } } } else {