Skip to content

Commit

Permalink
fix: remove delegator addess from MsgCreateValidator (#14567)
Browse files Browse the repository at this point in the history
Co-authored-by: Julien Robert <julien@rbrt.fr>
Co-authored-by: samricotta <37125168+samricotta@users.noreply.github.com>
Co-authored-by: Marko <marbar3778@yahoo.com>
Co-authored-by: Noel Ukwa <noeluchechukwu@gmail.com>
Co-authored-by: JayT106 <JayT106@users.noreply.github.com>
Co-authored-by: Matt Kocubinski <mkocubinski@gmail.com>
Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com>
Co-authored-by: Amaury <1293565+amaurym@users.noreply.github.com>
Co-authored-by: Likhita Polavarapu <78951027+likhita-809@users.noreply.github.com>
Co-authored-by: atheeshp <59333759+atheeshp@users.noreply.github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Denver <aeharvlee@gmail.com>
Co-authored-by: Hyunwoo Lee <denver@Hyunwoos-MacBook-Pro-2.local>
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
  • Loading branch information
15 people committed Jan 17, 2023
1 parent 874d9bd commit 7b8ab8e
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 318 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ extension interfaces. `module.Manager.Modules` is now of type `map[string]interf
The information can now be accessed using the BankKeeper.
Setting can be done using MsgSetSendEnabled as a governance proposal.
A SendEnabled query has been added to both GRPC and CLI.
* (x/staking) [#14567](https://github.com/cosmos/cosmos-sdk/pull/14567) The `delegator_address` field of `MsgCreateValidator` has been deprecated.
The validator address bytes and delegator address bytes refer to the same account while creating validator (defer only in bech32 notation).

## [v0.46.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.46.7) - 2022-12-13

Expand Down
429 changes: 216 additions & 213 deletions api/cosmos/staking/v1beta1/tx.pulsar.go

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions proto/cosmos/staking/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,6 @@ service Msg {

// MsgCreateValidator defines a SDK message for creating a new validator.
message MsgCreateValidator {
// NOTE(fdymylja): this is a particular case in which
// if validator_address == delegator_address then only one
// is expected to sign, otherwise both are.
option (cosmos.msg.v1.signer) = "delegator_address";
option (cosmos.msg.v1.signer) = "validator_address";
option (amino.name) = "cosmos-sdk/MsgCreateValidator";

Expand All @@ -66,7 +62,9 @@ message MsgCreateValidator {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
string delegator_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString"];
// Deprecated: Use of Delegator Address in MsgCreateValidator is deprecated.
// The validator address bytes and delegator address bytes refer to the same account while creating validator (defer only in bech32 notation).
string delegator_address = 4 [(cosmos_proto.scalar) = "cosmos.AddressString", deprecated = true];
string validator_address = 5 [(cosmos_proto.scalar) = "cosmos.AddressString"];
google.protobuf.Any pubkey = 6 [(cosmos_proto.accepts_interface) = "cosmos.crypto.PubKey"];
cosmos.base.v1beta1.Coin value = 7 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
Expand Down
9 changes: 5 additions & 4 deletions x/genutil/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,22 @@ func CollectTxs(cdc codec.JSONCodec, txJSONDecoder sdk.TxDecoder, moniker, genTx
// TODO abstract out staking message validation back to staking
msg := msgs[0].(*stakingtypes.MsgCreateValidator)

// validate delegator and validator addresses and funds against the accounts in the state
delAddr := msg.DelegatorAddress
// validate validator addresses and funds against the accounts in the state
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
return appGenTxs, persistentPeers, err
}

delBal, delOk := balancesMap[delAddr]
valAccAddr := sdk.AccAddress(valAddr).String()

delBal, delOk := balancesMap[valAccAddr]
if !delOk {
_, file, no, ok := runtime.Caller(1)
if ok {
fmt.Printf("CollectTxs-1, called from %s#%d\n", file, no)
}

return appGenTxs, persistentPeers, fmt.Errorf("account %s balance not in genesis state: %+v", delAddr, balancesMap)
return appGenTxs, persistentPeers, fmt.Errorf("account %s balance not in genesis state: %+v", valAccAddr, balancesMap)
}

_, valOk := balancesMap[sdk.AccAddress(valAddr).String()]
Expand Down
7 changes: 1 addition & 6 deletions x/staking/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,6 @@ func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateVa
return nil, err
}

delegatorAddress, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
return nil, err
}

validator.MinSelfDelegation = msg.MinSelfDelegation

k.SetValidator(ctx, validator)
Expand All @@ -119,7 +114,7 @@ func (k msgServer) CreateValidator(goCtx context.Context, msg *types.MsgCreateVa
// move coins from the msg.Address account to a (self-delegation) delegator account
// the validator account and global shares are updated within here
// NOTE source will always be from a wallet which are unbonded
_, err = k.Keeper.Delegate(ctx, delegatorAddress, msg.Value.Amount, types.Unbonded, validator, true)
_, err = k.Keeper.Delegate(ctx, sdk.AccAddress(valAddr), msg.Value.Amount, types.Unbonded, validator, true)
if err != nil {
return nil, err
}
Expand Down
4 changes: 3 additions & 1 deletion x/staking/simulation/operations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ func (s *SimTestSuite) TestSimulateMsgCreateValidator() {

require.True(operationMsg.OK)
require.Equal(types.TypeMsgCreateValidator, msg.Type())
require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", msg.DelegatorAddress)
valaddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
require.NoError(err)
require.Equal("cosmos1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7u4x9a0", sdk.AccAddress(valaddr).String())
require.Equal("cosmosvaloper1p8wcgrjr4pjju90xg6u9cgq55dxwq8j7epjs3u", msg.ValidatorAddress)
require.Len(futureOperations, 0)
}
Expand Down
18 changes: 2 additions & 16 deletions x/staking/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewMsgCreateValidator(
}
return &MsgCreateValidator{
Description: description,
DelegatorAddress: sdk.AccAddress(valAddr).String(),
ValidatorAddress: valAddr.String(),
Pubkey: pkAny,
Value: selfDelegation,
Expand All @@ -66,17 +65,11 @@ func (msg MsgCreateValidator) Type() string { return TypeMsgCreateValidator }
// If the validator address is not same as delegator's, then the validator must
// sign the msg as well.
func (msg MsgCreateValidator) GetSigners() []sdk.AccAddress {
// delegator is first signer so delegator pays fees
delegator, _ := sdk.AccAddressFromBech32(msg.DelegatorAddress)
addrs := []sdk.AccAddress{delegator}
valAddr, _ := sdk.ValAddressFromBech32(msg.ValidatorAddress)

valAccAddr := sdk.AccAddress(valAddr)
if !delegator.Equals(valAccAddr) {
addrs = append(addrs, valAccAddr)
}

return addrs
return []sdk.AccAddress{valAccAddr}
}

// GetSignBytes returns the message bytes to sign over.
Expand All @@ -88,17 +81,10 @@ func (msg MsgCreateValidator) GetSignBytes() []byte {
// ValidateBasic implements the sdk.Msg interface.
func (msg MsgCreateValidator) ValidateBasic() error {
// note that unmarshaling from bech32 ensures both non-empty and valid
delAddr, err := sdk.AccAddressFromBech32(msg.DelegatorAddress)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid delegator address: %s", err)
}
valAddr, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
_, err := sdk.ValAddressFromBech32(msg.ValidatorAddress)
if err != nil {
return sdkerrors.ErrInvalidAddress.Wrapf("invalid validator address: %s", err)
}
if !sdk.AccAddress(valAddr).Equals(delAddr) {
return sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "validator address is invalid")
}

if msg.Pubkey == nil {
return ErrEmptyValidatorPubKey
Expand Down
Loading

0 comments on commit 7b8ab8e

Please sign in to comment.