-
Notifications
You must be signed in to change notification settings - Fork 4.1k
feat(mempool)!: respect gas wanted returned by ante handler #25338
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
base: main
Are you sure you want to change the base?
Changes from 3 commits
4cd29a5
b54349d
7be0362
8937edb
0936ce1
99707c4
a4d9cfd
c434a76
010dfe1
24b265d
d4980fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -873,7 +873,7 @@ func (app *BaseApp) runTx(mode sdk.ExecMode, txBytes []byte, tx sdk.Tx) (gInfo s | |
|
||
switch mode { | ||
case execModeCheck: | ||
err = app.mempool.Insert(ctx, tx) | ||
err = app.mempool.InsertWithGasWanted(ctx, tx, gasWanted) | ||
if err != nil { | ||
return gInfo, nil, anteEvents, err | ||
} | ||
|
@@ -1067,18 +1067,18 @@ func (app *BaseApp) PrepareProposalVerifyTx(tx sdk.Tx) ([]byte, error) { | |
// ProcessProposal state internally will be discarded. <nil, err> will be | ||
// returned if the transaction cannot be decoded. <Tx, nil> will be returned if | ||
// the transaction is valid, otherwise <Tx, err> will be returned. | ||
func (app *BaseApp) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, error) { | ||
func (app *BaseApp) ProcessProposalVerifyTx(txBz []byte) (sdk.Tx, uint64, error) { | ||
|
||
tx, err := app.txDecoder(txBz) | ||
if err != nil { | ||
return nil, err | ||
return nil, 0, err | ||
} | ||
|
||
_, _, _, err = app.runTx(execModeProcessProposal, txBz, tx) | ||
gInfo, _, _, err := app.runTx(execModeProcessProposal, txBz, tx) | ||
if err != nil { | ||
return nil, err | ||
return nil, 0, err | ||
} | ||
|
||
return tx, nil | ||
return tx, gInfo.GasWanted, nil | ||
} | ||
|
||
func (app *BaseApp) TxDecode(txBytes []byte) (sdk.Tx, error) { | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -7,11 +7,30 @@ import ( | |||
sdk "github.com/cosmos/cosmos-sdk/types" | ||||
) | ||||
|
||||
type Tx struct { | ||||
Tx sdk.Tx | ||||
GasWanted uint64 | ||||
} | ||||
|
||||
func NewMempoolTx(tx sdk.Tx, gasWanted uint64) Tx { | ||||
return Tx{ | ||||
Tx: tx, | ||||
GasWanted: gasWanted, | ||||
} | ||||
} | ||||
|
||||
type GasTx interface { | ||||
GetGas() uint64 | ||||
} | ||||
|
||||
|
||||
type Mempool interface { | ||||
// Insert attempts to insert a Tx into the app-side mempool returning | ||||
// an error upon failure. | ||||
Insert(context.Context, sdk.Tx) error | ||||
|
||||
// Insert with a custom gas wanted value | ||||
InsertWithGasWanted(context.Context, sdk.Tx, uint64) error | ||||
|
||||
|
err = app.mempool.InsertWithGasWanted(ctx, tx, gasWanted) |
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 need to fill mempoolTx with gasWanted from gas meter when runTx
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.
what is the difference between the tx.Gas() vs the gasWanted from the meter 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.
what do you think of removing this method and instead adding an argument to Insert
such as:
type InsertOption struct {
GasWanted uint64
}
type Mempool interface {
// ....
Insert(context.Context, sdk.Tx, InsertOption) error
}
this way, if more is needed in the future, it will be nonbreaking.
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.
There are cases that tx.Gas()
is different from gasWanted returned from context GasMeter()
and we need to override with it. I think we keep Insert
mainly for the tests.
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.
💡 Verification agent
🧩 Analysis chain
Iterator.Tx now returns wrapper Tx — breaking change: verify all usages are updated.
Audit for code still asserting sdk.Tx directly from Iterator.Tx().
Run:
Expected: call sites use iter.Tx().Tx (or equivalent) after this change.
🏁 Script executed:
#!/bin/bash
# Find Iterator.Tx() usages and spot unwraps expecting sdk.Tx.
rg -nP --type=go -C3 '\.Tx\(\)\s*[\),]' # method call contexts
rg -nP --type=go -C3 '\.Tx\(\)\.' # chained member access implying wrapper usage
rg -nP --type=go -C3 '=\s*iter\.Tx\(\)' # direct assignment patterns
Length of output: 3411
Iterator.Tx now returns wrapper Tx — update all call sites that still treat it as sdk.Tx
Call sites still passing/assigning iter.Tx() must unwrap (.Tx) or accept the wrapper:
- types/mempool/mempool.go:83 — for iter != nil && callback(iter.Tx()) {
- types/mempool/sender_nonce.go:216 — for iter != nil && callback(iter.Tx()) {
- types/mempool/priority_nonce.go:395 — for iter != nil && callback(iter.Tx()) {
Tests already access the inner Tx in several places (e.g., types/mempool/mempool_test.go:142; types/mempool/priority_nonce_test.go:391, 938, 973) — ensure expectations/ assertions match the wrapper change.
🤖 Prompt for AI Agents
In types/mempool/mempool.go around lines 65-66 the interface method Tx() now
returns the wrapper type Tx instead of sdk.Tx; update all call sites that still
treat iter.Tx() as sdk.Tx to either unwrap the inner sdk.Tx via iter.Tx.Tx or
change the consumer to accept the wrapper type. Specifically, modify the three
call sites (types/mempool/mempool.go:83, types/mempool/sender_nonce.go:216,
types/mempool/priority_nonce.go:395) to call callback(iter.Tx().Tx) if callback
expects sdk.Tx, or change the callback signature to accept the wrapper; also
update tests that inspect the inner transaction (e.g.,
types/mempool/mempool_test.go:142; types/mempool/priority_nonce_test.go:391,
938, 973) to access the inner sdk.Tx through the wrapper before making
assertions.
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.
uint64 is a bit ambiguous, maybe a named return or comment to help the developer understand the variable