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 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
434d0ea
feat(x/staking/types): allow empty allow and deny list
ziscky Nov 14, 2024
84f688a
test(x/staking/types): add test for empty allow and deny list
ziscky Nov 14, 2024
043233b
docs(x/staking/types): update docs
ziscky Nov 14, 2024
8e701bf
chore(x/staking/types): changelog
ziscky Nov 14, 2024
5482612
test(systemtests/authz): update empty allow and deny list
ziscky Nov 14, 2024
2897005
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Nov 19, 2024
7748dcc
test(systemtests/authz): update empty allow and deny list tests
ziscky Nov 19, 2024
823b935
test(systemtests/authz): fix tests
ziscky Nov 19, 2024
3a78451
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Nov 28, 2024
2e8e34a
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Dec 4, 2024
0f4507d
test(systemtests/authz): fix test cases
ziscky Dec 4, 2024
e712e1f
test(systemtests/authz): fix test cases
ziscky Dec 5, 2024
b25e270
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Dec 5, 2024
178c0bd
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Jan 7, 2025
4f62e5d
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Jan 8, 2025
c6fca06
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Jan 10, 2025
f89efdd
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Jan 12, 2025
74a8250
Merge branch 'main' into ziscky/11126-authz-delegate-all
ziscky Jan 20, 2025
f63c701
Merge branch 'main' into ziscky/11126-authz-delegate-all
aljo242 Jan 21, 2025
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