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

feat(x/staking): StakeAuthorization: Allow delegating to all validators #22527

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 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
52 changes: 29 additions & 23 deletions tests/systemtests/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func TestAuthzGrantTxCmd(t *testing.T) {
require.NotEqual(t, granterAddr, grantee5Addr)
grantee6Addr := cli.AddKey("grantee6")
require.NotEqual(t, granterAddr, grantee6Addr)
grantee7Addr := cli.AddKey("grantee7")
require.NotEqual(t, granterAddr, grantee7Addr)
grantee8Addr := cli.AddKey("grantee8")
require.NotEqual(t, granterAddr, grantee8Addr)
grantee9Addr := cli.AddKey("grantee9")
require.NotEqual(t, granterAddr, grantee9Addr)

systest.Sut.StartChain(t)

Expand Down Expand Up @@ -89,13 +95,6 @@ func TestAuthzGrantTxCmd(t *testing.T) {
"msg type cannot be empty",
true,
},
{
"delegate authorization without allow or deny list",
grantee1Addr,
[]string{"delegate"},
"both allowed & deny list cannot be empty",
false,
},
{
"delegate authorization with invalid allowed validator address",
grantee1Addr,
Expand All @@ -110,13 +109,6 @@ func TestAuthzGrantTxCmd(t *testing.T) {
"decoding bech32 failed",
false,
},
{
"unbond authorization without allow or deny list",
grantee1Addr,
[]string{"unbond"},
"both allowed & deny list cannot be empty",
false,
},
{
"unbond authorization with invalid allowed validator address",
grantee1Addr,
Expand All @@ -131,13 +123,6 @@ func TestAuthzGrantTxCmd(t *testing.T) {
"decoding bech32 failed",
false,
},
{
"redelegate authorization without allow or deny list",
grantee1Addr,
[]string{"redelegate"},
"both allowed & deny list cannot be empty",
false,
},
{
"redelegate authorization with invalid allowed validator address",
grantee1Addr,
Expand Down Expand Up @@ -181,19 +166,40 @@ func TestAuthzGrantTxCmd(t *testing.T) {
false,
},
{
"valid unbond authorization",
"valid delegate authorization without allow or deny list",
grantee5Addr,
[]string{"delegate", "--spend-limit=1000" + testDenom},
"",
false,
},
{
"valid unbond authorization",
grantee6Addr,
[]string{"unbond", "--deny-validators=" + valOperAddr},
"",
false,
},
{
"valid unbond authorization without allow or deny list",
grantee7Addr,
[]string{"unbond", "--spend-limit=1000" + testDenom},
"",
false,
},
{
"valid redelegate authorization",
grantee6Addr,
grantee8Addr,
[]string{"redelegate", "--allowed-validators=" + valOperAddr},
"",
false,
},
{
"valid redelegate authorization without allow or deny list",
grantee9Addr,
[]string{"redelegate", "--spend-limit=1000" + testDenom},
"",
false,
},
}

grantsCount := 0
Expand Down
2 changes: 1 addition & 1 deletion x/authz/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/bank/types/send_autho

#### StakeAuthorization

`StakeAuthorization` implements the `Authorization` interface for messages in the [staking module](https://docs.cosmos.network/main/build/modules/staking). It takes an `AuthorizationType` to specify whether you want to authorize delegation, undelegation, redelegation or cancel unbonding delegation, each of which must be authorized separately. It also takes an optional `MaxTokens` that keeps track of a limit to the amount of tokens that can be delegated/undelegated/redelegated. If left empty, the amount is unlimited. Additionally, this Msg takes an `AllowList` or a `DenyList`, enabling you to specify which validators the grantee can or cannot stake with.
`StakeAuthorization` implements the `Authorization` interface for messages in the [staking module](https://docs.cosmos.network/main/build/modules/staking). It takes an `AuthorizationType` to specify whether you want to authorize delegation, undelegation, redelegation or cancel unbonding delegation, each of which must be authorized separately. It also takes an optional `MaxTokens` that keeps track of a limit to the amount of tokens that can be delegated/undelegated/redelegated. If left empty, the amount is unlimited. Additionally, this Msg takes an `AllowList` or a `DenyList`, enabling you to specify which validators the grantee can or cannot stake with. If both `AllowList` and `DenyList` are empty delegation to all validators is allowed.

```protobuf reference
https://github.com/cosmos/cosmos-sdk/blob/v0.52.0-beta.1/x/staking/proto/cosmos/staking/v1beta1/authz.proto#L11-L34
Expand Down
2 changes: 1 addition & 1 deletion x/staking/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#18506](https://github.com/cosmos/cosmos-sdk/pull/18506) Detect the length of the ed25519 pubkey in CreateValidator to prevent panic.

### Bug Fixes

* [#22527](https://github.com/cosmos/cosmos-sdk/pull/22527) Allow delegating `StakeAuthorization` to all validators by leaving `AllowList` and `DenyList` empty.
* [#20688](https://github.com/cosmos/cosmos-sdk/pull/20688) Avoid overslashing unbonding delegations after a redelegation.
* [#19226](https://github.com/cosmos/cosmos-sdk/pull/19226) Ensure `GetLastValidators` in `x/staking` does not return an error when `MaxValidators` exceeds total number of bonded validators.

Expand Down
4 changes: 0 additions & 4 deletions x/staking/types/authz.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,6 @@ func (a StakeAuthorization) Accept(ctx context.Context, msg sdk.Msg) (authz.Acce
}

func validateAllowAndDenyValidators(allowed, denied []sdk.ValAddress, valAddressCodec address.Codec) ([]string, []string, error) {
if len(allowed) == 0 && len(denied) == 0 {
return nil, nil, sdkerrors.ErrInvalidRequest.Wrap("both allowed & deny list cannot be empty")
}

if len(allowed) > 0 && len(denied) > 0 {
return nil, nil, sdkerrors.ErrInvalidRequest.Wrap("cannot set both allowed & deny list")
}
Expand Down
15 changes: 15 additions & 0 deletions x/staking/types/authz_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ func TestAuthzAuthorizations(t *testing.T) {
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
},
},
{
"delegate: testing empty denyList and allowList",
[]sdk.ValAddress{},
[]sdk.ValAddress{},
stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
nil,
stakingtypes.NewMsgDelegate(accAddressToString(t, delAddr), valAddressToString(t, val2), coin100),
false,
false,
&stakingtypes.StakeAuthorization{
Validators: &stakingtypes.StakeAuthorization_DenyList{
DenyList: &stakingtypes.StakeAuthorization_Validators{Address: []string{}},
}, MaxTokens: nil, AuthorizationType: stakingtypes.AuthorizationType_AUTHORIZATION_TYPE_DELEGATE,
},
},
{
"undelegate: expect 0 remaining coins",
[]sdk.ValAddress{val1, val2},
Expand Down
Loading