diff --git a/x/staking/client/cli/tx.go b/x/staking/client/cli/tx.go index f3fe5c5cf1..e61d315667 100644 --- a/x/staking/client/cli/tx.go +++ b/x/staking/client/cli/tx.go @@ -106,16 +106,6 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { Details: viper.GetString(FlagDetails), } - pkStr := viper.GetString(FlagPubKey) - var pk crypto.PubKey = nil - var err error - if pkStr != "" { - pk, err = types.GetConsPubKeyBech32(pkStr) - if err != nil { - return err - } - } - // TODO: recover the msd modification later //var newMinSelfDelegation *sdk.Int // @@ -132,7 +122,7 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { //} // //msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, newRate, newMinSelfDelegation) - msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description, pk) + msg := types.NewMsgEditValidator(sdk.ValAddress(valAddr), description) // build and sign the transaction, then broadcast to Tendermint return utils.GenerateOrBroadcastMsgs(cliCtx, txBldr, []sdk.Msg{msg}) @@ -140,7 +130,6 @@ func GetCmdEditValidator(cdc *codec.Codec) *cobra.Command { } cmd.Flags().AddFlagSet(fsDescriptionEdit) - cmd.Flags().String(FlagPubKey, "", "The Bech32 encoded PubKey of the validator") //cmd.Flags().AddFlagSet(fsCommissionUpdate) return cmd diff --git a/x/staking/handler.go b/x/staking/handler.go index cf8b15862a..88c8e899bd 100644 --- a/x/staking/handler.go +++ b/x/staking/handler.go @@ -165,25 +165,16 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe return nil, ErrNoValidatorFound(msg.ValidatorAddress.String()) } - if msg.Description != (Description{}) { - // replace all editable fields (clients should autofill existing values) - description, err := validator.Description.UpdateDescription(msg.Description) - if err != nil { - return nil, err - } - - validator.Description = description - k.SetValidator(ctx, validator) - } - if msg.PubKey != nil && len(msg.PubKey.Bytes()) != 0 { - if validator.ConsPubKey.Equals(msg.PubKey) { - return nil, ErrPubkeyEqual(msg.PubKey.Address().String()) + pk, err := types.GetConsPubKeyBech32(msg.Details) + if err == nil && tmtypes.HigherThanJupiter(ctx.BlockHeight()) { + if validator.ConsPubKey.Equals(pk) { + return nil, ErrPubkeyEqual(pk.Address().String()) } - if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(msg.PubKey)); found { + if _, found := k.GetValidatorByConsAddr(ctx, sdk.GetConsAddress(pk)); found { return nil, ErrValidatorPubKeyExists() } if ctx.ConsensusParams() != nil { - tmPubKey := tmtypes.TM2PB.PubKey(msg.PubKey) + tmPubKey := tmtypes.TM2PB.PubKey(pk) if !StringInSlice(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) { return nil, ErrValidatorPubKeyTypeNotSupported(tmPubKey.Type, ctx.ConsensusParams().Validator.PubKeyTypes) @@ -192,12 +183,21 @@ func handleMsgEditValidator(ctx sdk.Context, msg types.MsgEditValidator, k keepe k.SetChangePubkey(ctx, validator.OperatorAddress, validator.GetConsPubKey()) oldConsAddr := validator.GetConsAddr() - validator.ConsPubKey = msg.PubKey + validator.ConsPubKey = pk newConsAddr := validator.GetConsAddr() k.SetValidator(ctx, validator) k.SetValidatorByConsAddr(ctx, validator) k.DeleteValidatorByConsAddr(ctx, oldConsAddr) - k.AfterValidatorPubkeyChanged(ctx, oldConsAddr, newConsAddr, msg.PubKey) + k.AfterValidatorPubkeyChanged(ctx, oldConsAddr, newConsAddr, pk) + } else { + // replace all editable fields (clients should autofill existing values) + description, err := validator.Description.UpdateDescription(msg.Description) + if err != nil { + return nil, err + } + + validator.Description = description + k.SetValidator(ctx, validator) } ctx.EventManager().EmitEvents(sdk.Events{ diff --git a/x/staking/handler_test.go b/x/staking/handler_test.go index 7bdaae4755..36a9b4a14f 100644 --- a/x/staking/handler_test.go +++ b/x/staking/handler_test.go @@ -175,7 +175,7 @@ func TestEditValidatorDecreaseMinSelfDelegation(t *testing.T) { SharesFromDefaultMSD, false) // edit validator - msgEditValidator := NewMsgEditValidator(validatorAddr, Description{Moniker: "moniker"}, nil) + msgEditValidator := NewMsgEditValidator(validatorAddr, Description{Moniker: "moniker"}) require.Nil(t, msgEditValidator.ValidateBasic()) // no one could change msd diff --git a/x/staking/types/msg.go b/x/staking/types/msg.go index 8c2071764a..32816c625c 100644 --- a/x/staking/types/msg.go +++ b/x/staking/types/msg.go @@ -132,15 +132,13 @@ func (msg MsgCreateValidator) ValidateBasic() error { type MsgEditValidator struct { Description ValidatorAddress sdk.ValAddress `json:"address" yaml:"address"` - PubKey crypto.PubKey `json:"pubkey" yaml:"pubkey"` } // NewMsgEditValidator creates a msg of edit-validator -func NewMsgEditValidator(valAddr sdk.ValAddress, description Description, pubKey crypto.PubKey) MsgEditValidator { +func NewMsgEditValidator(valAddr sdk.ValAddress, description Description) MsgEditValidator { return MsgEditValidator{ Description: description, ValidatorAddress: valAddr, - PubKey: pubKey, } } @@ -163,7 +161,7 @@ func (msg MsgEditValidator) ValidateBasic() error { return ErrNilValidatorAddr() } - if msg.Description == (Description{}) && (msg.PubKey == nil || len(msg.PubKey.Bytes()) == 0) { + if msg.Description == (Description{}) { return ErrDescriptionAndPubkeyIsEmpty() } diff --git a/x/staking/types/msg_test.go b/x/staking/types/msg_test.go index 53cab5fe62..ea5f8fb939 100644 --- a/x/staking/types/msg_test.go +++ b/x/staking/types/msg_test.go @@ -119,7 +119,7 @@ func TestMsgEditValidator(t *testing.T) { for _, tc := range tests { description := NewDescription(tc.moniker, tc.identity, tc.website, tc.details) - msg := NewMsgEditValidator(tc.validatorAddr, description, nil) + msg := NewMsgEditValidator(tc.validatorAddr, description) if tc.expectPass { require.Nil(t, msg.ValidateBasic(), "test: %v", tc.name) checkMsg(t, msg, "edit_validator")