Skip to content
This repository was archived by the owner on Jan 31, 2025. It is now read-only.

Commit d19bdf9

Browse files
mergify[bot]nivasan1Eric-Warehime
authored
fix(check-tx): remove txs failing recheck from app-side mempool (backport #476) (#478)
* fix(check-tx): remove txs failing recheck from app-side mempool (#476) * remove txs failing recheck from app-side mempool * linting (cherry picked from commit 6080de1) * Fix test --------- Co-authored-by: Nikhil Vasan <97126437+nivasan1@users.noreply.github.com> Co-authored-by: Eric <eric.warehime@gmail.com>
1 parent 85d53ff commit d19bdf9

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

abci/checktx/check_tx_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,52 @@ func (s *CheckTxTestSuite) TestCheckTxMempoolParity() {
111111
})
112112
}
113113

114+
func (s *CheckTxTestSuite) TestRemovalOnRecheckTx() {
115+
// create a tx that should not be inserted in the mev-lane
116+
tx, _, err := testutils.CreateAuctionTx(
117+
s.EncCfg.TxConfig,
118+
s.Accounts[0],
119+
sdk.NewCoin(s.GasTokenDenom, math.NewInt(100)),
120+
1,
121+
0,
122+
nil,
123+
100,
124+
)
125+
s.Require().NoError(err)
126+
127+
mevLane := s.InitLane(math.LegacyOneDec(), nil)
128+
mempool, err := block.NewLanedMempool(s.Ctx.Logger(), []block.Lane{mevLane})
129+
s.Require().NoError(err)
130+
131+
handler := checktx.NewMempoolParityCheckTx(
132+
s.Ctx.Logger(),
133+
mempool,
134+
s.EncCfg.TxConfig.TxDecoder(),
135+
func(*cometabci.RequestCheckTx) (*cometabci.ResponseCheckTx, error) {
136+
// always fail
137+
return &cometabci.ResponseCheckTx{Code: 1}, nil
138+
},
139+
).CheckTx()
140+
141+
s.Run("tx is removed on check-tx failure when re-check", func() {
142+
// check that tx exists in mempool
143+
txBz, err := s.EncCfg.TxConfig.TxEncoder()(tx)
144+
s.Require().NoError(err)
145+
146+
s.Require().NoError(mempool.Insert(s.Ctx, tx))
147+
s.Require().True(mempool.Contains(tx))
148+
149+
// check tx
150+
res, err := handler(&cometabci.RequestCheckTx{Tx: txBz, Type: cometabci.CheckTxType_Recheck})
151+
s.Require().NoError(err)
152+
153+
s.Require().Equal(uint32(1), res.Code)
154+
155+
// check that tx is removed from mempool
156+
s.Require().False(mempool.Contains(tx))
157+
})
158+
}
159+
114160
func (s *CheckTxTestSuite) TestMempoolParityCheckTx() {
115161
s.Run("tx fails tx-decoding", func() {
116162
handler := checktx.NewMempoolParityCheckTx(

abci/checktx/mempool_parity_check_tx.go

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ func (m MempoolParityCheckTx) CheckTx() CheckTx {
5454
), nil
5555
}
5656

57+
isReCheck := req.Type == cmtabci.CheckTxType_Recheck
58+
5759
// if the mode is ReCheck and the app's mempool does not contain the given tx, we fail
5860
// immediately, to purge the tx from the comet mempool.
59-
if req.Type == cmtabci.CheckTxType_Recheck && !m.mempl.Contains(tx) {
61+
if isReCheck && !m.mempl.Contains(tx) {
6062
m.logger.Debug(
6163
"tx from comet mempool not found in app-side mempool",
6264
"tx", tx,
@@ -72,6 +74,28 @@ func (m MempoolParityCheckTx) CheckTx() CheckTx {
7274
}
7375

7476
// run the checkTxHandler
75-
return m.checkTxHandler(req)
77+
res, checkTxError := m.checkTxHandler(req)
78+
79+
// if re-check fails for a transaction, we'll need to explicitly purge the tx from
80+
// the app-side mempool
81+
if isInvalidCheckTxExecution(res, checkTxError) && isReCheck {
82+
// check if the tx exists first
83+
if m.mempl.Contains(tx) {
84+
// remove the tx
85+
if err := m.mempl.Remove(tx); err != nil {
86+
m.logger.Debug(
87+
"failed to remove tx from app-side mempool when purging for re-check failure",
88+
"removal-err", err,
89+
"check-tx-err", checkTxError,
90+
)
91+
}
92+
}
93+
}
94+
95+
return res, checkTxError
7696
}
7797
}
98+
99+
func isInvalidCheckTxExecution(resp *cmtabci.ResponseCheckTx, checkTxErr error) bool {
100+
return resp == nil || resp.Code != 0 || checkTxErr != nil
101+
}

0 commit comments

Comments
 (0)