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

CreateValidator self delegation must be at least one consensus power #8909

Merged
merged 14 commits into from
Mar 22, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements

* (x/staking) [\#8909](https://github.com/cosmos/cosmos-sdk/pull/8909) Require self delegation in `MsgCreateValidator` to be at least one consensus power.
* (x/bank) [\#8614](https://github.com/cosmos/cosmos-sdk/issues/8614) Add `Name` and `Symbol` fields to denom metadata
* (x/auth) [\#8522](https://github.com/cosmos/cosmos-sdk/pull/8522) Allow to query all stored accounts
* (crypto/types) [\#8600](https://github.com/cosmos/cosmos-sdk/pull/8600) `CompactBitArray`: optimize the `NumTrueBitsBefore` method and add an `Equal` method.
Expand Down
5 changes: 5 additions & 0 deletions x/staking/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ func (msg MsgCreateValidator) ValidateBasic() error {
return ErrMinSelfDelegationInvalid
}

// ensure delegation is at least one consensus power
if sdk.TokensToConsensusPower(msg.Value.Amount) <= 0 {
return sdkerrors.Wrapf(ErrBadDelegationAmount, "self delegation amount (%s) must be at least one consensus power (%s)", msg.Value.Amount, sdk.PowerReduction)
}

if msg.Value.Amount.LT(msg.MinSelfDelegation) {
return ErrSelfDelegationBelowMinimum
}
Expand Down
3 changes: 2 additions & 1 deletion x/staking/types/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var (
coinPos = sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000)
coinPos = sdk.NewInt64Coin(sdk.DefaultBondDenom, sdk.PowerReduction.Int64())
coinZero = sdk.NewInt64Coin(sdk.DefaultBondDenom, 0)
)

Expand Down Expand Up @@ -75,6 +75,7 @@ func TestMsgCreateValidator(t *testing.T) {
{"zero min self delegation", "a", "b", "c", "d", "e", commission1, sdk.ZeroInt(), valAddr1, pk1, coinPos, false},
{"negative min self delegation", "a", "b", "c", "d", "e", commission1, sdk.NewInt(-1), valAddr1, pk1, coinPos, false},
{"delegation less than min self delegation", "a", "b", "c", "d", "e", commission1, coinPos.Amount.Add(sdk.OneInt()), valAddr1, pk1, coinPos, false},
{"delegation less than one consensus power", "a", "b", "c", "d", "e", commission1, sdk.OneInt(), valAddr1, pk1, sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000), false},
}

for _, tc := range tests {
Expand Down