-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
refactor(x/feegrant): Rewrite feegrant ante handler as tx validator #19594
Closed
Closed
Changes from 17 commits
Commits
Show all changes
112 commits
Select commit
Hold shift + click to select a range
bd96d6f
wip
likhita-809 200bb26
keep fee decorator only
likhita-809 19c7ed0
wip
likhita-809 5c541bc
small fix
likhita-809 e2cbb1f
go mod tidy
likhita-809 91aac94
add TxValidator for x/circuit
likhita-809 ddd34f6
update circuit TxValidator
likhita-809 91daa9e
Merge branch 'server_modular' of https://github.com/cosmos/cosmos-sdk…
likhita-809 b8f52ac
Fix few tests
likhita-809 e9ee4b5
wip: move FeeDecorator to auth
likhita-809 232da2b
address comments
likhita-809 529423c
update
likhita-809 0bdfded
wip: move fee decorator to feegrant module
likhita-809 6925fc6
remove auth dependency on feegrant ante
likhita-809 252911f
Merge branch 'server_modular' of https://github.com/cosmos/cosmos-sdk…
likhita-809 eb80d82
fix tests
likhita-809 db82004
refactor(x/**)!: genesis return errors (#19740)
chixiaowen 7193d88
chore(proto): add module safe query warning (#19743)
tac0turtle 7341ea6
Merge branch 'server_modular' of https://github.com/cosmos/cosmos-sdk…
likhita-809 069d6cf
build(deps): Bump github.com/cosmos/cosmos-sdk from 0.50.4 to 0.50.5 …
dependabot[bot] abfd79a
build(deps): Bump github.com/cosmos/cosmos-sdk from 0.50.4 to 0.50.5 …
dependabot[bot] 10c1d7c
build(deps): Bump github.com/cosmos/cosmos-sdk from 0.50.4 to 0.50.5 …
dependabot[bot] 9c47292
feat(x/gov): add expedited proposal quorum param (#19741)
julienrbrt 5424b55
fix(crypto): error if incorrect ledger public key (#19691)
rootulp 3ce9224
feat(x/accounts): Add new lockup account type (#19048)
sontrinh16 36981e6
test(client/v2): Fix `TestMsg` flakiness (#19753)
likhita-809 c807aae
refactor!: mv AddressCodecs aliases from runtime -> core (#19747)
kocubinski 1b545a5
chore: fix spelling errors (#19756)
github-prbot d54335e
refactor: rename core.registry.LegacyRegistry -> core.registry.Interf…
kocubinski 0cdf3cf
refactor(core): remove consensus events (#19757)
tac0turtle b239590
build(deps): Bump github.com/cometbft/cometbft from 0.38.5 to 0.38.6 …
dependabot[bot] 59c5f6b
address few comments
likhita-809 6b1e9fc
refactor(store/db): remove unnecessary code and correct error handlin…
0x2d3c 5a733e8
fix(x/upgrade): Stop treating inline JSON as a URL (#19706)
gibson042 26c1db6
fix: align signer extraction adapter for mempool remove (#19759)
mmsqe 6f1658e
feat(core): match store interfaces (#19762)
tac0turtle 25af567
chore: fix the flaky test in store/snapshots (#19774)
cool-develope ed6b3ab
fix(client/v2): fix comment parsing (#19377)
julienrbrt a7f9d92
build(deps): Bump github.com/creachadair/tomledit from 0.0.25 to 0.0.…
dependabot[bot] 65ab253
refactor(x/staking)!: removes the use of Accounts String() method (#1…
JulianToledano a86c2a9
feat(store/v2): support rocksdb and pebbledb as RawDB (#19607)
alexanderbez a1bfe5d
feat(x/staking): allow zero unbonding time (#19779)
ocnc bfa734c
refactor(x/staking,genutil)!: use validatorUpdates (#19754)
chixiaowen 3ed9f7f
build(deps): Bump actions/add-to-project from 0.6.0 to 0.6.1 (#19789)
dependabot[bot] 0c2decd
refactor!: MsgSimulatorFn clean up (#19792)
JulianToledano 0e1d620
build(deps): Bump rtCamp/action-slack-notify from 2.2.1 to 2.3.0 (#19…
dependabot[bot] fa19df1
refactor(x/authz)!: remove Accounts.String() (#19783)
JulianToledano 3166ebb
store: keys as bytes (#19775)
tac0turtle 4952cb2
chore: bump iavl and store to v1.1.0 (#19799)
tac0turtle 27a231a
feat(store/v2): add the catch up process in the migration (#19454)
cool-develope 3cf87f9
chore: fix typos (#19813)
xiaoxianBoy d67d145
build(deps): Bump github.com/pelletier/go-toml/v2 from 2.1.1 to 2.2.0…
dependabot[bot] 13db28a
build(deps): Bump cosmossdk.io/store from 1.0.2 to 1.1.0 in /x/eviden…
dependabot[bot] 9933a44
refactor(x/protocol): remove Accounts.String() (#19815)
JulianToledano 8b4081f
fix(store/v2): clean up resources after the migration is completed (#…
cool-develope 632c3f1
docs(collections): fixed typo in `collections/collections.go` (#19814)
meetrick 32d63e0
build(deps): Bump github.com/cosmos/gogoproto from 1.4.11 to 1.4.12 (…
dependabot[bot] ac61b69
build(deps): Bump github.com/linxGnu/grocksdb from 1.8.12 to 1.8.14 i…
dependabot[bot] 4599439
feat(x/gov): emit proposer address in submit proposal event (#19842)
akaladarshi ea7bdd1
fix: Do not call Remove during Walk (#19833)
facundomedica adc3432
fix(x/tx): default to using gogoproto.HybridResolver wherever possibl…
aaronc 00b2b9d
chore: fix spelling errors (#19852)
github-prbot d1c3547
feat(x/gov): emit depositor in `proposal_deposit` event (#19853)
kienn6034 138db2b
chore: linting fixes (#19855)
tac0turtle c466887
chore(api): clean-up protos (#19858)
julienrbrt a82615b
fix: Do not call Remove during Walk - part 2 (#19851)
facundomedica 160c418
refactor(x/gov)!: remove Accounts.String() (#19850)
JulianToledano 23723be
build(deps): Bump github.com/creachadair/atomicfile from 0.3.3 to 0.3…
dependabot[bot] 6e9528a
test(sims): fix test cases feegrant (#19863)
EmilGeorgiev 6592541
refactor(x/distribution)!: remove Accounts.String() (#19868)
JulianToledano 815c9c5
build(deps): Bump actions/add-to-project from 0.6.1 to 1.0.0 (#19877)
dependabot[bot] def211d
feat(server): add custom start handler (#19854)
julienrbrt 39808e0
feat(x/tx): add custom type encoder (#19786)
pinosu 8488733
feat(client): replace `event-query-tx-for` with `wait-tx` (#19870)
Pitasi 6972e00
refactor(x/feegrant): remove Address.String() (#19886)
JulianToledano f630cfb
refactor(simapp): using maps.Clone to simplify codes (#19885)
cuiweixie 705fad6
refactor(store,x/params): using maps.Copy (#19889)
cuiweixie 4ef1209
build(deps): Bump github.com/prometheus/common from 0.50.0 to 0.51.1 …
dependabot[bot] d54e940
refactor(x/staking): use sdk validator updates (#19788)
julienrbrt b9c8d60
refactor: bump gogoproto (#19869)
raynaudoe cb5d34e
fix(x/accounts/defaults/lockup): rename lockup `go.mod` properly (#19…
julienrbrt 80e1a45
chore: remove repetitive words (#19908)
carehabit f4af84f
refactor(x/group)!: remove Address.String() (#19916)
JulianToledano 319e6e4
feat: Integrate grpc configuration into client.toml (#19905)
lucaslopezf dbff363
build(deps): Bump github.com/regen-network/gocuke from 1.1.0 to 1.1.1…
dependabot[bot] 1574814
docs(x/mint): Fix inconsistency in mint docs (#19915)
likhita-809 fad30cd
refactor(x/genutil)!: remove Address.String() (#19926)
JulianToledano 0e7b7fd
build(deps): Bump bufbuild/buf-setup-action from 1.30.0 to 1.30.1 (#1…
dependabot[bot] 1028e27
feat(x/epochs): upstream osmosis epoch module (#19697)
hieuvubk 6c66267
build(deps): Bump cosmossdk.io/store from 1.0.2 to 1.1.0 in /x/epochs…
dependabot[bot] edd1c71
feat(core): add `TxValidator` interface (#19950)
julienrbrt 649dfaa
refactor(types): loosen module.AppModule interface (#19951)
julienrbrt 15ad85d
fix(x/tx): don't shadow Amino marshalling error messages (#19955)
Pitasi 558c950
chore: fix spelling errors (#19957)
github-prbot 37131cf
build(deps): Bump golang.org/x/crypto from 0.21.0 to 0.22.0 (#19960)
dependabot[bot] ab45a85
fix(x/authz): non utf-8 characters in logs (#19923)
EmilGeorgiev 6049684
feat(core,runtime): transaction service (exec mode) (#19953)
julienrbrt a6039bc
fix(x/epochs): Fix init genesis (#19958)
hieuvubk d881554
build(deps): Bump github.com/prometheus/common from 0.51.1 to 0.52.2 …
dependabot[bot] c753458
refactor(x/bank)!: remove Address.String() (#19954)
JulianToledano dcec6ad
test(types/address): add additional unit tests for address.LengthPref…
EmilGeorgiev cd24915
build(deps): Bump google.golang.org/grpc from 1.62.1 to 1.63.0 (#19929)
dependabot[bot] 5d04deb
build(deps): Bump github.com/decred/dcrd/dcrec/secp256k1/v4 from 4.2.…
dependabot[bot] e5b0e0e
docs: reword upgrading.md (#19900)
julienrbrt b2835eb
chore: linting fixes (#19978)
tac0turtle f8fee96
build(deps): Bump google.golang.org/grpc from 1.63.0 to 1.63.2 (#19982)
dependabot[bot] 9e9cc52
build(ci): Remove staticmajor due to false positives (#19989)
alpe a5d4c40
fix(simapp): use correct store keys for upgrade (#19987)
alpe bc4ca0c
docs: clarify gas-prices option (#19980)
turadg fc3ca2f
docs: fix typo in Contribution guide (#19994)
lukevenediger 24d44b6
build(deps): Bump golang.org/x/sync from 0.6.0 to 0.7.0 (#19961)
dependabot[bot] a3fe9e3
Merge branch 'main' of https://github.com/cosmos/cosmos-sdk into likh…
likhita-809 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package ante | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"fmt" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdkmath "cosmossdk.io/math" | ||
"cosmossdk.io/x/feegrant" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
) | ||
|
||
const feeCollectorName = "fee_collector" | ||
|
||
type FeegrantKeeper interface { | ||
UseGrantedFees(ctx context.Context, granter, grantee sdk.AccAddress, fee sdk.Coins, msgs []sdk.Msg) error | ||
} | ||
|
||
// TxFeeChecker check if the provided fee is enough and returns the effective fee and tx priority, | ||
// the effective fee should be deducted later, and the priority should be returned in abci response. | ||
type TxFeeChecker func(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, error) | ||
|
||
// DeductFeeDecorator deducts fees from the fee payer. The fee payer is the fee granter (if specified) or first signer of the tx. | ||
// If the fee payer does not have the funds to pay for the fees, return an InsufficientFunds error. | ||
// Call next AnteHandler if fees successfully deducted. | ||
// CONTRACT: Tx must implement FeeTx interface to use DeductFeeDecorator | ||
type DeductFeeDecorator struct { | ||
accountKeeper feegrant.AccountKeeper | ||
bankKeeper feegrant.BankKeeper | ||
feegrantKeeper FeegrantKeeper | ||
txFeeChecker TxFeeChecker | ||
} | ||
|
||
func NewDeductFeeDecorator(ak feegrant.AccountKeeper, bk feegrant.BankKeeper, fk FeegrantKeeper, tfc TxFeeChecker) DeductFeeDecorator { | ||
if tfc == nil { | ||
tfc = checkTxFeeWithValidatorMinGasPrices | ||
} | ||
|
||
return DeductFeeDecorator{ | ||
accountKeeper: ak, | ||
bankKeeper: bk, | ||
feegrantKeeper: fk, | ||
txFeeChecker: tfc, | ||
} | ||
} | ||
|
||
func (dfd DeductFeeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, _ bool, next sdk.AnteHandler) (sdk.Context, error) { | ||
feeTx, ok := tx.(sdk.FeeTx) | ||
if !ok { | ||
return ctx, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | ||
} | ||
|
||
if ctx.ExecMode() != sdk.ExecModeSimulate && ctx.BlockHeight() > 0 && feeTx.GetGas() == 0 { | ||
return ctx, errorsmod.Wrap(sdkerrors.ErrInvalidGasLimit, "must provide positive gas") | ||
} | ||
|
||
var err error | ||
fee := feeTx.GetFee() | ||
if ctx.ExecMode() != sdk.ExecModeSimulate { | ||
fee, err = dfd.txFeeChecker(ctx, tx) | ||
if err != nil { | ||
return ctx, err | ||
} | ||
} | ||
if err := dfd.checkDeductFee(ctx, tx, fee); err != nil { | ||
return ctx, err | ||
} | ||
|
||
return next(ctx, tx, ctx.ExecMode() == sdk.ExecModeSimulate) | ||
} | ||
|
||
func (dfd DeductFeeDecorator) checkDeductFee(ctx sdk.Context, sdkTx sdk.Tx, fee sdk.Coins) error { | ||
feeTx, ok := sdkTx.(sdk.FeeTx) | ||
if !ok { | ||
return errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | ||
} | ||
|
||
if addr := dfd.accountKeeper.GetModuleAddress(feeCollectorName); addr == nil { | ||
return fmt.Errorf("fee collector module account (%s) has not been set", feeCollectorName) | ||
} | ||
|
||
feePayer := feeTx.FeePayer() | ||
feeGranter := feeTx.FeeGranter() | ||
deductFeesFrom := feePayer | ||
|
||
// if feegranter set deduct fee from feegranter account. | ||
// this works with only when feegrant enabled. | ||
if feeGranter != nil { | ||
feeGranterAddr := sdk.AccAddress(feeGranter) | ||
|
||
if dfd.feegrantKeeper == nil { | ||
return sdkerrors.ErrInvalidRequest.Wrap("fee grants are not enabled") | ||
} else if !bytes.Equal(feeGranterAddr, feePayer) { | ||
err := dfd.feegrantKeeper.UseGrantedFees(ctx, feeGranterAddr, feePayer, fee, sdkTx.GetMsgs()) | ||
if err != nil { | ||
return errorsmod.Wrapf(err, "%s does not allow to pay fees for %s", feeGranter, feePayer) | ||
} | ||
} | ||
|
||
deductFeesFrom = feeGranterAddr | ||
} | ||
|
||
// deduct the fees | ||
if !fee.IsZero() { | ||
err := DeductFees(dfd.bankKeeper, ctx, deductFeesFrom, fee) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
events := sdk.Events{ | ||
sdk.NewEvent( | ||
sdk.EventTypeTx, | ||
sdk.NewAttribute(sdk.AttributeKeyFee, fee.String()), | ||
sdk.NewAttribute(sdk.AttributeKeyFeePayer, sdk.AccAddress(deductFeesFrom).String()), | ||
), | ||
} | ||
ctx.EventManager().EmitEvents(events) | ||
|
||
return nil | ||
} | ||
|
||
// DeductFees deducts fees from the given account. | ||
func DeductFees(bankKeeper feegrant.BankKeeper, ctx sdk.Context, acc []byte, fees sdk.Coins) error { | ||
if !fees.IsValid() { | ||
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "invalid fee amount: %s", fees) | ||
} | ||
|
||
err := bankKeeper.SendCoinsFromAccountToModule(ctx, sdk.AccAddress(acc), feeCollectorName, fees) | ||
if err != nil { | ||
return errorsmod.Wrapf(sdkerrors.ErrInsufficientFunds, err.Error()) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// checkTxFeeWithValidatorMinGasPrices implements the default fee logic, where the minimum price per | ||
// unit of gas is fixed and set by each validator. | ||
func checkTxFeeWithValidatorMinGasPrices(ctx sdk.Context, tx sdk.Tx) (sdk.Coins, error) { | ||
feeTx, ok := tx.(sdk.FeeTx) | ||
if !ok { | ||
return nil, errorsmod.Wrap(sdkerrors.ErrTxDecode, "Tx must be a FeeTx") | ||
} | ||
|
||
feeCoins := feeTx.GetFee() | ||
gas := feeTx.GetGas() | ||
|
||
// Ensure that the provided fees meet a minimum threshold for the validator, | ||
// if this is a CheckTx. This is only for local mempool purposes, and thus | ||
// is only ran on check tx. | ||
if ctx.ExecMode() == sdk.ExecModeCheck { | ||
minGasPrices := ctx.MinGasPrices() | ||
if !minGasPrices.IsZero() { | ||
requiredFees := make(sdk.Coins, len(minGasPrices)) | ||
|
||
// Determine the required fees by multiplying each required minimum gas | ||
// price by the gas limit, where fee = ceil(minGasPrice * gasLimit). | ||
glDec := sdkmath.LegacyNewDec(int64(gas)) | ||
for i, gp := range minGasPrices { | ||
fee := gp.Amount.Mul(glDec) | ||
requiredFees[i] = sdk.NewCoin(gp.Denom, fee.Ceil().RoundInt()) | ||
} | ||
|
||
if !feeCoins.IsAnyGTE(requiredFees) { | ||
return nil, errorsmod.Wrapf(sdkerrors.ErrInsufficientFee, "insufficient fees; got: %s required: %s", feeCoins, requiredFees) | ||
} | ||
} | ||
} | ||
|
||
return feeCoins, nil | ||
} |
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
Oops, something went wrong.
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 part feels like it should be handled by the wiring, we should not be building the ante handler here
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.
Yes, we should bring in antehandler logic in here, not just create the ante handler inside.
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.
For circuit we will have a tx validator and a pre message handler basically doing the same thing, do we actually then need a pre message handler?
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.
we should be able to drop it in that sense. but for backwards compatibility we still need this