-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
feegrant filtered msgs #8604
Merged
Merged
feegrant filtered msgs #8604
Changes from 56 commits
Commits
Show all changes
64 commits
Select commit
Hold shift + click to select a range
4d3308e
WIP: add filtered message
atheeshp 6ac7630
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 936f190
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp ee6d860
updated `Accept` interface method
atheeshp 1cb3161
fix tests
atheeshp 5710622
add cli tests for filtered fee allowance
atheeshp 1c36f98
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp cef8f48
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp b2cd491
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp 6343436
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp eea5069
fix tests
atheeshp cd25d55
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 2d76e74
Merge branch 'atheesh/feegrant-filtered-msgs' of github.com:cosmos/co…
atheeshp 2c1868a
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp e741b95
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp 0ab4580
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp a4d53d3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp eeae712
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 6004cf0
review changes
atheeshp d306fb5
rename `filteredFeeAllowance` message
atheeshp 8696f57
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp a9d972d
review changes
atheeshp fb60801
review changes
atheeshp 6bf5399
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 9fd6357
review changes
atheeshp fd2cc4e
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 8a0d0e3
Merge branch 'master' into atheesh/feegrant-filtered-msgs
0dae893
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 0b1830f
Merge branch 'atheesh/feegrant-filtered-msgs' of github.com:cosmos/co…
atheeshp 277cc78
review changes
atheeshp e3e96e8
review changes
atheeshp 47172fc
update errors
atheeshp a007543
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 722664e
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp 0c4146b
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp ab04b31
remove validation
atheeshp 9137a91
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp da8af9b
fix conflicts
atheeshp a5da1d5
add `ctx` to `Accept` method
atheeshp d160707
fix test
atheeshp 97b4a84
add gas consumption
atheeshp c4984e4
review changes
atheeshp 79cfc93
review changes
atheeshp 4dd2bbd
revert
atheeshp a2d1b90
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp 91ffbac
review changes
atheeshp ee30459
Merge branch 'atheesh/feegrant-filtered-msgs' of github.com:cosmos/co…
atheeshp f213a5d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp d730d1d
improve error handling
atheeshp f77ccbb
fix test
atheeshp 53ec16b
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 7f4e213
Merge branch 'master' into atheesh/feegrant-filtered-msgs
atheeshp 3f6bd89
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 2373aa9
review changes
atheeshp 5047ffe
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 45edce5
Merge branch 'atheesh/feegrant-filtered-msgs' of github.com:cosmos/co…
atheeshp a46a603
Merge branch 'master' into atheesh/feegrant-filtered-msgs
sahith-narahari e9f399e
update gas
atheeshp 629c319
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 5b8806b
Merge branch 'atheesh/feegrant-filtered-msgs' of github.com:cosmos/co…
atheeshp 1c58061
update type
atheeshp b5f6070
Merge branch 'master' of github.com:cosmos/cosmos-sdk into atheesh/fe…
atheeshp 05b7f6c
review changes
atheeshp 06a9433
Merge branch 'master' into atheesh/feegrant-filtered-msgs
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package ante | ||
|
||
import ( | ||
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
authante "github.com/cosmos/cosmos-sdk/x/auth/ante" | ||
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" | ||
"github.com/cosmos/cosmos-sdk/x/feegrant/keeper" | ||
"github.com/cosmos/cosmos-sdk/x/feegrant/types" | ||
) | ||
|
||
// DeductGrantedFeeDecorator deducts fees from fee_payer or fee_granter (if exists a valid fee allowance) of the tx | ||
// If the fee_payer or fee_granter does not have the funds to pay for the fees, return with InsufficientFunds error | ||
// Call next AnteHandler if fees successfully deducted | ||
// CONTRACT: Tx must implement GrantedFeeTx interface to use DeductGrantedFeeDecorator | ||
type DeductGrantedFeeDecorator struct { | ||
ak types.AccountKeeper | ||
k keeper.Keeper | ||
bk types.BankKeeper | ||
} | ||
|
||
func NewDeductGrantedFeeDecorator(ak types.AccountKeeper, bk types.BankKeeper, k keeper.Keeper) DeductGrantedFeeDecorator { | ||
return DeductGrantedFeeDecorator{ | ||
ak: ak, | ||
k: k, | ||
bk: bk, | ||
} | ||
} | ||
|
||
// AnteHandle performs a decorated ante-handler responsible for deducting transaction | ||
// fees. Fees will be deducted from the account designated by the FeePayer on a | ||
// transaction by default. However, if the fee payer differs from the transaction | ||
// signer, the handler will check if a fee grant has been authorized. If the | ||
// transaction's signer does not exist, it will be created. | ||
func (d DeductGrantedFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) { | ||
feeTx, ok := tx.(sdk.FeeTx) | ||
if !ok { | ||
return ctx, sdkerrors.Wrap(sdkerrors.ErrTxDecode, "Tx must be a GrantedFeeTx") | ||
} | ||
|
||
// sanity check from DeductFeeDecorator | ||
if addr := d.ak.GetModuleAddress(authtypes.FeeCollectorName); addr == nil { | ||
panic(fmt.Sprintf("%s module account has not been set", authtypes.FeeCollectorName)) | ||
} | ||
|
||
fee := feeTx.GetFee() | ||
feePayer := feeTx.FeePayer() | ||
feeGranter := feeTx.FeeGranter() | ||
|
||
deductFeesFrom := feePayer | ||
|
||
// ensure the grant is allowed, if we request a different fee payer | ||
if feeGranter != nil && !feeGranter.Equals(feePayer) { | ||
err := d.k.UseGrantedFees(ctx, feeGranter, feePayer, fee, tx.GetMsgs()) | ||
amaury1093 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if err != nil { | ||
return ctx, sdkerrors.Wrapf(err, "%s not allowed to pay fees from %s", feeGranter, feePayer) | ||
} | ||
|
||
deductFeesFrom = feeGranter | ||
} | ||
|
||
// now, either way, we know that we are authorized to deduct the fees from the deductFeesFrom account | ||
deductFeesFromAcc := d.ak.GetAccount(ctx, deductFeesFrom) | ||
if deductFeesFromAcc == nil { | ||
return ctx, sdkerrors.Wrapf(sdkerrors.ErrUnknownAddress, "fee payer address: %s does not exist", deductFeesFrom) | ||
} | ||
|
||
// move on if there is no fee to deduct | ||
if fee.IsZero() { | ||
return next(ctx, tx, simulate) | ||
} | ||
|
||
// deduct fee if non-zero | ||
err = authante.DeductFees(d.bk, ctx, deductFeesFromAcc, fee) | ||
if err != nil { | ||
return ctx, err | ||
} | ||
|
||
return next(ctx, tx, simulate) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sense.