From 3ac5b7c912a8adcaffe04c7a9f430b4e6a9e4e90 Mon Sep 17 00:00:00 2001 From: Hoang Do Date: Tue, 18 Mar 2025 04:32:39 +0700 Subject: [PATCH] feat(genutil): Allow manually setting the consensus key type in genesis (#24018) Co-authored-by: Alex | Interchain Labs --- CHANGELOG.md | 1 + crypto/keys/ed25519/ed25519.go | 6 +++--- x/genutil/client/cli/init.go | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3ca16392e..60990dbfe7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * Adds a `--timeout-timestamp` flag that allows users to specify a block time at which the unordered transactions should expire from the mempool. * (x/epochs) [#23815](https://github.com/cosmos/cosmos-sdk/pull/23815) Upstream `x/epochs` from Osmosis * (client) [#23811](https://github.com/cosmos/cosmos-sdk/pull/23811) Add auto cli for node service. +* (genutil) [#24018](https://github.com/cosmos/cosmos-sdk/pull/24018) Allow manually setting the consensus key type in genesis ### Improvements diff --git a/crypto/keys/ed25519/ed25519.go b/crypto/keys/ed25519/ed25519.go index 122be97cb2..680b9f0700 100644 --- a/crypto/keys/ed25519/ed25519.go +++ b/crypto/keys/ed25519/ed25519.go @@ -33,7 +33,7 @@ const ( // private key representations used by RFC 8032. SeedSize = 32 - keyType = "ed25519" + KeyType = "ed25519" ) var ( @@ -91,7 +91,7 @@ func (privKey *PrivKey) Equals(other cryptotypes.LedgerPrivKey) bool { } func (privKey *PrivKey) Type() string { - return keyType + return KeyType } // MarshalAmino overrides Amino binary marshaling. @@ -192,7 +192,7 @@ func (pubKey *PubKey) String() string { } func (pubKey *PubKey) Type() string { - return keyType + return KeyType } func (pubKey *PubKey) Equals(other cryptotypes.PubKey) bool { diff --git a/x/genutil/client/cli/init.go b/x/genutil/client/cli/init.go index 0461713a0e..8e31e516f8 100644 --- a/x/genutil/client/cli/init.go +++ b/x/genutil/client/cli/init.go @@ -9,6 +9,7 @@ import ( "path/filepath" cfg "github.com/cometbft/cometbft/config" + cmttypes "github.com/cometbft/cometbft/types" "github.com/cosmos/go-bip39" "github.com/spf13/cobra" @@ -18,6 +19,7 @@ import ( "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/client/flags" "github.com/cosmos/cosmos-sdk/client/input" + "github.com/cosmos/cosmos-sdk/crypto/keys/ed25519" "github.com/cosmos/cosmos-sdk/server" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/types/module" @@ -35,6 +37,9 @@ const ( // FlagDefaultBondDenom defines the default denom to use in the genesis file. FlagDefaultBondDenom = "default-denom" + + // FlagConsensusKeyAlgo defines the algorithm to use for the consensus signing key. + FlagConsensusKeyAlgo = "consensus-key-algo" ) type printInfo struct { @@ -160,8 +165,16 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { appGenesis.InitialHeight = initHeight appGenesis.Consensus = &types.ConsensusGenesis{ Validators: nil, + Params: cmttypes.DefaultConsensusParams(), } + consensusKey, err := cmd.Flags().GetString(FlagConsensusKeyAlgo) + if err != nil { + return errorsmod.Wrap(err, "Failed to get consensus key algo") + } + + appGenesis.Consensus.Params.Validator.PubKeyTypes = []string{consensusKey} + if err = genutil.ExportGenesisFile(appGenesis, genFile); err != nil { return errorsmod.Wrap(err, "Failed to export genesis file") } @@ -179,6 +192,7 @@ func InitCmd(mbm module.BasicManager, defaultNodeHome string) *cobra.Command { cmd.Flags().String(flags.FlagChainID, "", "genesis file chain-id, if left blank will be randomly created") cmd.Flags().String(FlagDefaultBondDenom, "", "genesis file default denomination, if left blank default value is 'stake'") cmd.Flags().Int64(flags.FlagInitHeight, 1, "specify the initial block height at genesis") + cmd.Flags().String(FlagConsensusKeyAlgo, ed25519.KeyType, "algorithm to use for the consensus key") return cmd }