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
4 changes: 2 additions & 2 deletions baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1749,15 +1749,15 @@ func TestABCI_PrepareProposal_Failures(t *testing.T) {

err = pool.Insert(sdk.Context{}, failTx)
require.NoError(t, err)
require.Equal(t, 2, pool.CountTx())
require.Equal(t, 1, pool.CountTx())
facundomedica marked this conversation as resolved.
Show resolved Hide resolved

req := abci.RequestPrepareProposal{
MaxTxBytes: 1000,
Height: 1,
}
res, err := suite.baseApp.PrepareProposal(&req)
require.NoError(t, err)
require.Equal(t, 1, len(res.Txs))
require.Equal(t, 0, len(res.Txs))
facundomedica marked this conversation as resolved.
Show resolved Hide resolved
}

func TestABCI_PrepareProposal_PanicRecovery(t *testing.T) {
Expand Down
7 changes: 7 additions & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
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 {
fmt.Println("here")
facundomedica marked this conversation as resolved.
Show resolved Hide resolved
// if the ante handler fails on recheck, we want to remove the tx from the mempool
if err := app.mempool.Remove(tx); 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
Original file line number Diff line number Diff line change
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
Loading