Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove delegator addess from MsgCreateValidator #14567

Merged
merged 25 commits into from
Jan 17, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
399ed1b
remove delegate address
0xmuralik Jan 10, 2023
fd49247
Merge branch 'cosmos:main' into murali/staking
0xmuralik Jan 10, 2023
1c10167
proto-gen
0xmuralik Jan 10, 2023
6c49ce7
Merge branch 'murali/staking' of https://github.com/0xmuralik/cosmos-…
0xmuralik Jan 10, 2023
c0dc0e2
fix errors
0xmuralik Jan 10, 2023
d500d90
deprecate delegator address in proto
0xmuralik Jan 11, 2023
8f930fa
proto-gen
0xmuralik Jan 11, 2023
eb357ba
proto docs
0xmuralik Jan 12, 2023
9634364
feat: create config fix tool (#14342)
julienrbrt Jan 10, 2023
c6f3d03
refactor: migrate `e2e/evidence` away from testify suite (#14553)
samricotta Jan 10, 2023
ef2671d
chore: add action to add issues to project board when labeled (#14570)
tac0turtle Jan 10, 2023
b44a871
refactor: migrate calls from alias file to appropriate store/types (#…
noelukwa Jan 10, 2023
021aefd
feat(mempool): priority nonce mempool option with tx replacement (#14…
JayT106 Jan 10, 2023
c9c5a77
docs: new key type for keyring (#14573)
JulianToledano Jan 11, 2023
c31fe30
feat(textual): Add Tx envelope Value Renderer (#13600)
amaury1093 Jan 11, 2023
b476810
chore: Replace testify with gotest.tools in staking integration tests…
likhita-809 Jan 11, 2023
771a623
chore: Replace testify with gotest.tools in bank integration tests (#…
likhita-809 Jan 11, 2023
e2bef8f
build(deps): Bump google.golang.org/grpc from 1.51.0 to 1.52.0 (#14580)
dependabot[bot] Jan 11, 2023
4f2eda3
test: Added test cases for precisionMultiplier (#14576)
aeharvlee Jan 12, 2023
cf166e1
proto docs
0xmuralik Jan 12, 2023
6b32a32
fix simulation test
0xmuralik Jan 12, 2023
e878b9a
Merge branch 'main' into murali/staking
0xmuralik Jan 12, 2023
78aac0a
Merge branch 'main' into murali/staking
alexanderbez Jan 16, 2023
bff845a
Merge branch 'main' into murali/staking
tac0turtle Jan 16, 2023
3a01ff4
changelog
0xmuralik Jan 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"];
0xmuralik marked this conversation as resolved.
Show resolved Hide resolved
// 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 {
Copy link
Member

@julienrbrt julienrbrt Jan 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the field is deprecated, we may want to return an error when it is being used?
This makes it state breaking however. But we've done that from bank multisend (going from multiples inputs to only one supported)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can ignore the value without giving 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