-
Notifications
You must be signed in to change notification settings - Fork 166
feat: async recheck support #1062
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 all commits
c54ef7b
2a8c3e8
0ce99fc
0169dc5
b26a6bd
4fe1466
9dd5c85
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 |
|---|---|---|
| @@ -1,49 +1,36 @@ | ||
| package mempool | ||
|
|
||
| import ( | ||
| "errors" | ||
| "context" | ||
| "time" | ||
|
|
||
| abci "github.com/cometbft/cometbft/abci/types" | ||
|
|
||
| "github.com/cosmos/evm/mempool/txpool" | ||
|
|
||
| "github.com/cosmos/cosmos-sdk/types" | ||
| sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
| ) | ||
|
|
||
| // NewCheckTxHandler creates a CheckTx handler that integrates with the EVM mempool for transaction validation. | ||
| // It wraps the standard transaction execution flow to handle EVM-specific nonce gap errors by routing | ||
| // transactions with higher tx sequence numbers to the mempool for potential future execution. | ||
| // Returns a handler function that processes ABCI CheckTx requests and manages EVM transaction sequencing. | ||
| func NewCheckTxHandler(mempool *ExperimentalEVMMempool) types.CheckTxHandler { | ||
| return func(runTx types.RunTx, request *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) { | ||
| gInfo, result, anteEvents, err := runTx(request.Tx, nil) | ||
| // It routes new CheckTx requests through the same async insert worker path used by | ||
| // the app-side mempool and waits for the insert result. | ||
| func NewCheckTxHandler(mempool *ExperimentalEVMMempool, debug bool, timeout time.Duration) types.CheckTxHandler { | ||
| if timeout <= 0 { | ||
| panic("invalid timeout CheckTxHandler timeout value") | ||
| } | ||
| return func(_ types.RunTx, request *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) { | ||
| if request.GetType() == abci.CheckTxType_Recheck { | ||
| panic("checkTx does not support recheck") | ||
| } | ||
| tx, err := mempool.txConfig.TxDecoder()(request.Tx) | ||
| if err != nil { | ||
| // detect if there is a nonce gap error (only returned for EVM transactions) | ||
| if errors.Is(err, ErrNonceGap) || errors.Is(err, ErrNonceLow) { | ||
| // send it to the mempool for further triage | ||
| err := mempool.InsertInvalidNonce(request.Tx) | ||
| if err != nil { | ||
| return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, false), nil | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. were the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i checked on v0.53.x and main, calling broadcast tx sync never returned anything other than code, tx hash, and a log if it failed. you can see comet stripping down the response here: https://github.com/cometbft/cometbft/blob/1bb8b386fc366bc4655dede0535e16d1ad669c7d/rpc/core/mempool.go#L58-L64
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. got it, tested on gaia as well earlier and this was the case too |
||
| } | ||
| } | ||
| // If its already known, this can mean the the tx was promoted from nonce gap to valid | ||
| // and by allowing ErrAlreadyKnown to be silent, we allow re-gossiping of such txs | ||
| // this also covers the case of re-submission of the same tx enforcing overpricing for replacement | ||
| if errors.Is(err, txpool.ErrAlreadyKnown) { | ||
| return sdkerrors.ResponseCheckTxWithEvents(nil, gInfo.GasWanted, gInfo.GasUsed, anteEvents, false), nil | ||
| } | ||
|
|
||
| // anything else, return regular error | ||
| return sdkerrors.ResponseCheckTxWithEvents(err, gInfo.GasWanted, gInfo.GasUsed, anteEvents, false), nil | ||
| return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, nil, debug), nil | ||
| } | ||
|
|
||
| return &abci.ResponseCheckTx{ | ||
| GasWanted: int64(gInfo.GasWanted), // #nosec G115 -- this is copied from the Cosmos SDK | ||
| GasUsed: int64(gInfo.GasUsed), // #nosec G115 -- this is copied from the Cosmos SDK | ||
| Log: result.Log, | ||
| Data: result.Data, | ||
| Events: types.MarkEventsToIndex(result.Events, nil), | ||
| }, nil | ||
| ctx, cancel := context.WithTimeout(context.Background(), timeout) | ||
| defer cancel() | ||
| if err := mempool.Insert(ctx, tx); err != nil { | ||
| return sdkerrors.ResponseCheckTxWithEvents(err, 0, 0, nil, debug), nil | ||
| } | ||
| return &abci.ResponseCheckTx{Code: abci.CodeTypeOK}, nil | ||
greptile-apps[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
+20
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recheck requests not short-circuited — breaks The handler does not inspect Two concrete failure modes follow:
Since the app sets return func(_ types.RunTx, request *abci.RequestCheckTx) (*abci.ResponseCheckTx, error) {
if request.Type == abci.CheckTxType_Recheck {
return &abci.ResponseCheckTx{Code: abci.CodeTypeOK}, nil
}
tx, err := mempool.txConfig.TxDecoder()(request.Tx)
...
} |
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.