diff --git a/CHANGELOG.md b/CHANGELOG.md index 065c0768f06c..0c9cf3f83191 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -233,6 +233,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (CLI) [#12075](https://github.com/cosmos/cosmos-sdk/pull/12075) Add `p2p-port` to the `gentx` and `create-validator` CLI commands to support custom P2P ports. * [#11969](https://github.com/cosmos/cosmos-sdk/pull/11969) Fix the panic error in `x/upgrade` when `AppVersion` is not set. * (tests) [\#11940](https://github.com/cosmos/cosmos-sdk/pull/11940) Fix some client tests in the `x/gov` module * [\#11772](https://github.com/cosmos/cosmos-sdk/pull/11772) Limit types.Dec length to avoid overflow. diff --git a/x/staking/client/cli/flags.go b/x/staking/client/cli/flags.go index 85879567a6af..2bdc93168b6a 100644 --- a/x/staking/client/cli/flags.go +++ b/x/staking/client/cli/flags.go @@ -31,6 +31,7 @@ const ( FlagGenesisFormat = "genesis-format" FlagNodeID = "node-id" FlagIP = "ip" + FlagP2PPort = "p2p-port" ) // common flagsets to add to various functions diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index f184d27d6a94..6426df2f31fe 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -397,10 +397,11 @@ func newBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *fl genOnly, _ := fs.GetBool(flags.FlagGenerateOnly) if genOnly { ip, _ := fs.GetString(FlagIP) + p2pPort, _ := fs.GetUint(FlagP2PPort) nodeID, _ := fs.GetString(FlagNodeID) - if nodeID != "" && ip != "" { - txf = txf.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip)) + if nodeID != "" && ip != "" && p2pPort > 0 { + txf = txf.WithMemo(fmt.Sprintf("%s@%s:%d", nodeID, ip, p2pPort)) } } @@ -411,7 +412,8 @@ func newBuildCreateValidatorMsg(clientCtx client.Context, txf tx.Factory, fs *fl // this is anticipated to be used with the gen-tx func CreateValidatorMsgFlagSet(ipDefault string) (fs *flag.FlagSet, defaultsDesc string) { fsCreateValidator := flag.NewFlagSet("", flag.ContinueOnError) - fsCreateValidator.String(FlagIP, ipDefault, "The node's public IP") + fsCreateValidator.String(FlagIP, ipDefault, "The node's public P2P IP") + fsCreateValidator.Uint(FlagP2PPort, 26656, "The node's public P2P port") fsCreateValidator.String(FlagNodeID, "", "The node's NodeID") fsCreateValidator.String(FlagMoniker, "", "The validator's (optional) moniker") fsCreateValidator.String(FlagWebsite, "", "The validator's (optional) website") @@ -451,6 +453,7 @@ type TxCreateValidatorConfig struct { PubKey cryptotypes.PubKey IP string + P2PPort uint Website string SecurityContact string Details string @@ -464,35 +467,35 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c if err != nil { return c, err } + if ip == "" { - _, _ = fmt.Fprintf(os.Stderr, "couldn't retrieve an external IP; "+ - "the tx's memo field will be unset") + _, _ = fmt.Fprintf(os.Stderr, "failed to retrieve an external IP; the tx's memo field will be unset") + } + + p2pPort, err := flagSet.GetUint(FlagP2PPort) + if err != nil { + return c, err } - c.IP = ip website, err := flagSet.GetString(FlagWebsite) if err != nil { return c, err } - c.Website = website securityContact, err := flagSet.GetString(FlagSecurityContact) if err != nil { return c, err } - c.SecurityContact = securityContact details, err := flagSet.GetString(FlagDetails) if err != nil { return c, err } - c.SecurityContact = details identity, err := flagSet.GetString(FlagIdentity) if err != nil { return c, err } - c.Identity = identity c.Amount, err = flagSet.GetString(FlagAmount) if err != nil { @@ -519,6 +522,11 @@ func PrepareConfigForTxCreateValidator(flagSet *flag.FlagSet, moniker, nodeID, c return c, err } + c.IP = ip + c.P2PPort = p2pPort + c.Website = website + c.SecurityContact = securityContact + c.Identity = identity c.NodeID = nodeID c.PubKey = valPubKey c.Website = website @@ -586,17 +594,24 @@ func BuildCreateValidatorMsg(clientCtx client.Context, config TxCreateValidatorC } msg, err := types.NewMsgCreateValidator( - sdk.ValAddress(valAddr), config.PubKey, amount, description, commissionRates, minSelfDelegation, + sdk.ValAddress(valAddr), + config.PubKey, + amount, + description, + commissionRates, + minSelfDelegation, ) if err != nil { return txBldr, msg, err } + if generateOnly { ip := config.IP + p2pPort := config.P2PPort nodeID := config.NodeID - if nodeID != "" && ip != "" { - txBldr = txBldr.WithMemo(fmt.Sprintf("%s@%s:26656", nodeID, ip)) + if nodeID != "" && ip != "" && p2pPort > 0 { + txBldr = txBldr.WithMemo(fmt.Sprintf("%s@%s:%d", nodeID, ip, p2pPort)) } } diff --git a/x/staking/client/cli/tx_test.go b/x/staking/client/cli/tx_test.go index 243780bc6e03..a60a2a309731 100644 --- a/x/staking/client/cli/tx_test.go +++ b/x/staking/client/cli/tx_test.go @@ -22,6 +22,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) { IP: ip, ChainID: chainID, NodeID: nodeID, + P2PPort: 26656, PubKey: valPubKey, Moniker: moniker, Amount: amount,