cmd/XDC: fixes db unavailability for chain commands #21415 (#1204)

This commit is contained in:
Daniel Liu 2025-07-28 16:56:37 +08:00 committed by GitHub
parent 2eac17980c
commit 390ea247d3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 8 deletions

View file

@ -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)

View file

@ -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)