From 390ea247d3dbad206d525f321d0f2f32d34a0db2 Mon Sep 17 00:00:00 2001 From: Daniel Liu <139250065@qq.com> Date: Mon, 28 Jul 2025 16:56:37 +0800 Subject: [PATCH] cmd/XDC: fixes db unavailability for chain commands #21415 (#1204) --- cmd/XDC/chaincmd.go | 18 ++++++++++-------- cmd/XDC/config.go | 1 + 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/cmd/XDC/chaincmd.go b/cmd/XDC/chaincmd.go index a9374d4ab4..5025e7a0c4 100644 --- a/cmd/XDC/chaincmd.go +++ b/cmd/XDC/chaincmd.go @@ -151,13 +151,14 @@ func initGenesis(ctx *cli.Context) error { var err error genesis := new(core.Genesis) genesisPath := ctx.Args().First() - if genesisPath == "mainnet" || genesisPath == "xinfin" { + switch genesisPath { + case "mainnet", "xinfin": err = json.Unmarshal(xdc_genesis.MainnetGenesis, genesis) - } else if genesisPath == "testnet" || genesisPath == "apothem" { + case "testnet", "apothem": err = json.Unmarshal(xdc_genesis.TestnetGenesis, genesis) - } else if genesisPath == "devnet" { + case "devnet": err = json.Unmarshal(xdc_genesis.DevnetGenesis, genesis) - } else { + default: if len(genesisPath) == 0 { utils.Fatalf("invalid path to genesis file") } @@ -177,7 +178,7 @@ func initGenesis(ctx *cli.Context) error { common.CopyConstants(genesis.Config.ChainId.Uint64()) } - // Open an initialise both full and light databases + // Open and initialise both full and light databases stack, _ := makeConfigNode(ctx) defer stack.Close() @@ -314,7 +315,7 @@ func importPreimages(ctx *cli.Context) error { utils.Fatalf("This command requires an argument.") } - stack, _, _ := makeFullNode(ctx) + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, false) @@ -333,7 +334,8 @@ func exportPreimages(ctx *cli.Context) error { if ctx.Args().Len() < 1 { utils.Fatalf("This command requires an argument.") } - stack, _, _ := makeFullNode(ctx) + + stack, _ := makeConfigNode(ctx) defer stack.Close() db := utils.MakeChainDatabase(ctx, stack, true) @@ -348,7 +350,7 @@ func exportPreimages(ctx *cli.Context) error { } func dump(ctx *cli.Context) error { - stack, _, _ := makeFullNode(ctx) + stack, _ := makeConfigNode(ctx) defer stack.Close() chain, chainDb := utils.MakeChain(ctx, stack, true) diff --git a/cmd/XDC/config.go b/cmd/XDC/config.go index ca97ec77aa..c151fdf634 100644 --- a/cmd/XDC/config.go +++ b/cmd/XDC/config.go @@ -215,6 +215,7 @@ func makeConfigNode(ctx *cli.Context) (*node.Node, XDCConfig) { return stack, cfg } +// makeFullNode loads geth configuration and creates the Ethereum backend. func makeFullNode(ctx *cli.Context) (*node.Node, ethapi.Backend, XDCConfig) { stack, cfg := makeConfigNode(ctx)