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!: make grant expiration optional #11060

Merged
merged 32 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
90570f3
feat!: make grant expiration optional
robert-zaremba Jan 28, 2022
5201088
proto regeneration
robert-zaremba Feb 24, 2022
5ede9ca
update grant msg
robert-zaremba Mar 2, 2022
df83f4b
update authz.GrantAuthorization
robert-zaremba Mar 2, 2022
37e8c7b
update simulations
robert-zaremba Mar 2, 2022
f8602da
fix SaveGrant
robert-zaremba Mar 2, 2022
0689d24
fixing tests
robert-zaremba Mar 3, 2022
4e8e5a4
fixing tests2
robert-zaremba Mar 3, 2022
a6a52b5
update tests
robert-zaremba Mar 10, 2022
458aba1
Merge remote-tracking branch 'origin/master' into robert/authz-expira…
robert-zaremba Mar 17, 2022
580acb3
fix keeper_test
robert-zaremba Mar 17, 2022
7e6ebeb
fix keeper tests
robert-zaremba Mar 17, 2022
9f5e473
fix nil pointer
robert-zaremba Mar 17, 2022
b4c12c5
fix sim test compilation
robert-zaremba Mar 17, 2022
ed46c73
update authz grant CLI
robert-zaremba Mar 18, 2022
d25a473
add null expire time to authz simulations
robert-zaremba Mar 18, 2022
5224e6d
update sime test
robert-zaremba Mar 18, 2022
a309dfc
changelog
robert-zaremba Mar 18, 2022
f5773df
update changelog
robert-zaremba Mar 18, 2022
2c4025b
add comment
robert-zaremba Mar 18, 2022
cc6cb8f
fixing sim tests
robert-zaremba Mar 18, 2022
7375a06
cleanup sim tests
robert-zaremba Mar 18, 2022
cf7ab0d
Merge remote-tracking branch 'origin/master' into robert/authz-expira…
robert-zaremba Mar 18, 2022
9317533
removed debug logs
robert-zaremba Mar 18, 2022
84e95ff
Merge remote-tracking branch 'origin/master' into robert/authz-expira…
robert-zaremba Mar 22, 2022
bdc40b2
fix init genesis
robert-zaremba Mar 24, 2022
cb2e328
fix dispatch
robert-zaremba Mar 24, 2022
0c1b02e
adding comment
robert-zaremba Mar 24, 2022
7d3f8c4
Merge remote-tracking branch 'origin/master' into robert/authz-expira…
robert-zaremba Mar 24, 2022
dafb921
Merge branch 'master' into robert/authz-expiration
amaury1093 Mar 24, 2022
5eb446e
Merge branch 'master' into robert/authz-expiration
robert-zaremba Mar 24, 2022
0bce508
rename createCoinAuthorization
robert-zaremba Mar 24, 2022
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#11234](https://github.com/cosmos/cosmos-sdk/pull/11234) Add `GRPCClient` field to Client Context. If `GRPCClient` field is set to nil, the `Invoke` method would use ABCI query, otherwise use gprc.
* [\#10962](https://github.com/cosmos/cosmos-sdk/pull/10962) ADR-040: Add state migration from iavl (v1Store) to smt (v2Store)
* (types) [\#10948](https://github.com/cosmos/cosmos-sdk/issues/10948) Add `app-db-backend` to the `app.toml` config to replace the compile-time `types.DBbackend` variable.
* (authz)[\#11060](https://github.com/cosmos/cosmos-sdk/pull/11060) Support grant with no expire time.

### API Breaking Changes

Expand Down Expand Up @@ -142,6 +143,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/authz) [\#10447](https://github.com/cosmos/cosmos-sdk/pull/10447) authz `NewGrant` takes a new argument: block time, to correctly validate expire time.
* [\#10961](https://github.com/cosmos/cosmos-sdk/pull/10961) Support third-party modules to add extension snapshots to state-sync.
* [\#11274](https://github.com/cosmos/cosmos-sdk/pull/11274) `types/errors.New` now is an alias for `types/errors.Register` and should only be used in initialization code.
* (authz)[\#11060](https://github.com/cosmos/cosmos-sdk/pull/11060) `authz.NewMsgGrant` `expiration` is now a pointer. When `nil` is used then no expiration will be set (grant won't expire).


### Client Breaking Changes
Expand All @@ -161,6 +163,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#10625](https://github.com/cosmos/cosmos-sdk/pull/10625) Rename `--fee-account` CLI flag to `--fee-granter`
* [\#10684](https://github.com/cosmos/cosmos-sdk/pull/10684) Rename `edit-validator` command's `--moniker` flag to `--new-moniker`
* [\#11116](https://github.com/cosmos/cosmos-sdk/pull/11116) `software-upgrade` and `cancel-software-upgrade` gov proposal commands have changed to `legacy-software-upgrade` and `legacy-cancel-software-upgrade`.
* (authz)[\#11060](https://github.com/cosmos/cosmos-sdk/pull/11060) Changed the default value of the `--expiration` `tx grant` CLI Flag: was now + 1year, update: null (no expire date).

### Improvements

Expand Down Expand Up @@ -250,6 +253,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#11019](https://github.com/cosmos/cosmos-sdk/pull/11019) Add `MsgCreatePermanentLockedAccount` and CLI method for creating permanent locked account
* (x/feegrant) [\#10830](https://github.com/cosmos/cosmos-sdk/pull/10830) Expired allowances will be pruned from state.
* (x/authz,x/feegrant) [\#11214](https://github.com/cosmos/cosmos-sdk/pull/11214) Fix Amino JSON encoding of authz and feegrant Msgs to be consistent with other modules.
* (authz)[\#11060](https://github.com/cosmos/cosmos-sdk/pull/11060) Support grant with no expire time.

### Deprecated

Expand Down
53 changes: 28 additions & 25 deletions api/cosmos/authz/v1beta1/authz.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 7 additions & 4 deletions proto/cosmos/authz/v1beta1/authz.proto
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ message GenericAuthorization {
// Grant gives permissions to execute
// the provide method with expiration time.
message Grant {
google.protobuf.Any authorization = 1 [(cosmos_proto.accepts_interface) = "Authorization"];
google.protobuf.Timestamp expiration = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
google.protobuf.Any authorization = 1 [(cosmos_proto.accepts_interface) = "Authorization"];
// time when the grant will expire and will be pruned. If null, then the grant
// doesn't have a time expiration (other conditions in `authorization`
// may apply to invalidate the grant)
google.protobuf.Timestamp expiration = 2 [(gogoproto.stdtime) = true, (gogoproto.nullable) = true];
amaury1093 marked this conversation as resolved.
Show resolved Hide resolved
}

// GrantAuthorization extends a grant with both the addresses of the grantee and granter.
Expand All @@ -33,11 +36,11 @@ message GrantAuthorization {
string grantee = 2 [(cosmos_proto.scalar) = "cosmos.AddressString"];

google.protobuf.Any authorization = 3 [(cosmos_proto.accepts_interface) = "Authorization"];
google.protobuf.Timestamp expiration = 4 [(gogoproto.nullable) = false, (gogoproto.stdtime) = true];
google.protobuf.Timestamp expiration = 4 [(gogoproto.stdtime) = true];
}

// GrantQueueItem contains the list of TypeURL of a sdk.Msg.
message GrantQueueItem {
// msg_type_urls contains the list of TypeURL of a sdk.Msg.
repeated string msg_type_urls = 1;
repeated string msg_type_urls = 1;
}
20 changes: 9 additions & 11 deletions x/authz/authorization_grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,25 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// NewGrant returns new Grant. It returns an error if the expiration is before
// the current block time, which is passed into the `blockTime` arg.
func NewGrant(blockTime time.Time, a Authorization, expiration time.Time) (Grant, error) {
if !expiration.After(blockTime) {
// NewGrant returns new Grant. Expiration is optional and noop if null.
// It returns an error if the expiration is before the current block time,
// which is passed into the `blockTime` arg.
func NewGrant(blockTime time.Time, a Authorization, expiration *time.Time) (Grant, error) {
if expiration != nil && !expiration.After(blockTime) {
return Grant{}, sdkerrors.ErrInvalidRequest.Wrapf("expiration must be after the current block time (%v), got %v", blockTime.Format(time.RFC3339), expiration.Format(time.RFC3339))
}
g := Grant{
Expiration: expiration,
}
msg, ok := a.(proto.Message)
if !ok {
return Grant{}, sdkerrors.Wrapf(sdkerrors.ErrPackAny, "cannot proto marshal %T", a)
}

any, err := cdctypes.NewAnyWithValue(msg)
if err != nil {
return Grant{}, err
}
g.Authorization = any

return g, nil
return Grant{
Expiration: expiration,
Authorization: any,
}, nil
}

var (
Expand Down
16 changes: 11 additions & 5 deletions x/authz/authorization_grant_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ func TestNewGrant(t *testing.T) {
title string
a Authorization
blockTime time.Time
expire time.Time
expire *time.Time
err string
}{
{"wrong expire time (1)", a, time.Unix(10, 0), time.Unix(8, 0), "expiration must be after"},
{"wrong expire time (2)", a, time.Unix(10, 0), time.Unix(10, 0), "expiration must be after"},
{"good expire time (1)", a, time.Unix(10, 0), time.Unix(10, 1), ""},
{"good expire time (2)", a, time.Unix(10, 0), time.Unix(11, 0), ""},
{"wrong expire time (1)", a, time.Unix(10, 0), unixTime(8, 0), "expiration must be after"},
{"wrong expire time (2)", a, time.Unix(10, 0), unixTime(10, 0), "expiration must be after"},
{"good expire time (1)", a, time.Unix(10, 0), unixTime(10, 1), ""},
{"good expire time (2)", a, time.Unix(10, 0), unixTime(11, 0), ""},
{"good expire time (nil)", a, time.Unix(10, 0), nil, ""},
}

for _, tc := range tcs {
Expand All @@ -41,3 +42,8 @@ func TestNewGrant(t *testing.T) {
}

}

func unixTime(s, ns int64) *time.Time {
t := time.Unix(s, ns)
return &t
}
Loading