Skip to content
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

fix: remove txs from mempool when antehandler fails in recheck #20144

Merged
merged 12 commits into from
May 2, 2024
7 changes: 7 additions & 0 deletions baseapp/baseapp.go
Expand Up @@ -911,6 +911,13 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
gasWanted = ctx.GasMeter().Limit()

if err != nil {
if mode == execModeReCheck {
// if the ante handler fails on recheck, we want to remove the tx from the mempool
err := app.mempool.Remove(tx)
if err != nil {
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return gInfo, nil, anteEvents, errors.Join(err, err)
facundomedica marked this conversation as resolved.
Show resolved Hide resolved
}
}
tac0turtle marked this conversation as resolved.
Show resolved Hide resolved
return gInfo, nil, nil, err
}

Expand Down
7 changes: 7 additions & 0 deletions baseapp/baseapp_test.go
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/cosmos/cosmos-sdk/testutil"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/mempool"
)

var (
Expand Down Expand Up @@ -80,6 +81,12 @@ func NewBaseAppSuite(t *testing.T, opts ...func(*baseapp.BaseApp)) *BaseAppSuite
app.SetParamStore(paramStore{db: dbm.NewMemDB()})
app.SetTxDecoder(txConfig.TxDecoder())
app.SetTxEncoder(txConfig.TxEncoder())
mem := mempool.NewPriorityMempool[int64](mempool.PriorityNonceMempoolConfig[int64]{
TxPriority: mempool.NewDefaultTxPriority(),
MaxTx: 0,
SignerExtractor: mempool.NewDefaultSignerExtractionAdapter(),
})
app.SetMempool(mem)

// mount stores and seal
require.Nil(t, app.LoadLatestVersion())
Expand Down