fix: support custom p2p port for gentx/validator creation (#12075)
This commit is contained in:
parent
dc110e6cd3
commit
3504dd387c
@ -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.
|
||||
|
||||
@ -31,6 +31,7 @@ const (
|
||||
FlagGenesisFormat = "genesis-format"
|
||||
FlagNodeID = "node-id"
|
||||
FlagIP = "ip"
|
||||
FlagP2PPort = "p2p-port"
|
||||
)
|
||||
|
||||
// common flagsets to add to various functions
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ func TestPrepareConfigForTxCreateValidator(t *testing.T) {
|
||||
IP: ip,
|
||||
ChainID: chainID,
|
||||
NodeID: nodeID,
|
||||
P2PPort: 26656,
|
||||
PubKey: valPubKey,
|
||||
Moniker: moniker,
|
||||
Amount: amount,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user