fix(x/feegrant): fix sims (#19362)

This commit is contained in:
Julien Robert 2024-02-07 00:30:52 +01:00 committed by GitHub
parent d26fe653c7
commit 41b188d64e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 17 deletions

View File

@ -46,4 +46,4 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#15347](https://github.com/cosmos/cosmos-sdk/pull/15347) `ValidateBasic` is treated as a no op now with with acceptance of RFC001
* [#17869](https://github.com/cosmos/cosmos-sdk/pull/17869) `NewGrant`, `NewMsgGrantAllowance` & `NewMsgRevokeAllowance` takes strings instead of `sdk.AccAddress`
* [#16535](https://github.com/cosmos/cosmos-sdk/pull/16535) Use collections for `FeeAllowance`, `FeeAllowanceQueue`.
* [#18815](https://github.com/cosmos/cosmos-sdk/pull/18815) Add the implementation of the `UpdatePeriodReset` interface to update the value of the `PeriodReset` field.
* [#18815](https://github.com/cosmos/cosmos-sdk/pull/18815) Add the implementation of the `UpdatePeriodReset` interface to update the value of the `PeriodReset` field.

View File

@ -9,12 +9,10 @@ import (
"cosmossdk.io/core/store"
errorsmod "cosmossdk.io/errors"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
"cosmossdk.io/x/auth/ante"
"cosmossdk.io/x/feegrant"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/runtime"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
@ -85,7 +83,8 @@ func (k Keeper) GrantAllowance(ctx context.Context, granter, grantee sdk.AccAddr
// expiration shouldn't be in the past.
sdkCtx := sdk.UnwrapSDKContext(ctx)
if exp != nil && exp.Before(sdkCtx.HeaderInfo().Time) {
now := sdkCtx.HeaderInfo().Time
if exp != nil && exp.Before(now) {
return errorsmod.Wrap(sdkerrors.ErrInvalidRequest, "expiration is before current block time")
}
@ -106,9 +105,13 @@ func (k Keeper) GrantAllowance(ctx context.Context, granter, grantee sdk.AccAddr
return err
}
err = feeAllowance.UpdatePeriodReset(sdkCtx.HeaderInfo().Time)
if err != nil {
return err
// if block time is not zero, update the period reset
// if it is zero, it could be genesis initialization, so we don't need to update the period reset
if !now.IsZero() {
err = feeAllowance.UpdatePeriodReset(now)
if err != nil {
return err
}
}
grant, err := feegrant.NewGrant(granterStr, granteeStr, feeAllowance)
@ -224,18 +227,9 @@ func (k Keeper) GetAllowance(ctx context.Context, granter, grantee sdk.AccAddres
// Callback to get all data, returns true to stop, false to keep reading
// Calling this without pagination is very expensive and only designed for export genesis
func (k Keeper) IterateAllFeeAllowances(ctx context.Context, cb func(grant feegrant.Grant) bool) error {
store := k.storeService.OpenKVStore(ctx)
iter := storetypes.KVStorePrefixIterator(runtime.KVStoreAdapter(store), feegrant.FeeAllowanceKeyPrefix)
defer iter.Close()
err := k.FeeAllowance.Walk(ctx, nil, func(key collections.Pair[sdk.AccAddress, sdk.AccAddress], grant feegrant.Grant) (stop bool, err error) {
return k.FeeAllowance.Walk(ctx, nil, func(key collections.Pair[sdk.AccAddress, sdk.AccAddress], grant feegrant.Grant) (stop bool, err error) {
return cb(grant), nil
})
if err != nil {
return err
}
return nil
}
// UseGrantedFees will try to pay the given fee from the granter's account as requested by the grantee