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

Commit b8d9c22

Browse files
authored
fix: Evict txs from mempool exceeding size limits (#550)
* init * nit test case
1 parent 79d7ef7 commit b8d9c22

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

block/base/proposals.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,32 @@ func (h *DefaultProposalHandler) PrepareLaneHandler() PrepareLaneHandler {
4747
continue
4848
}
4949

50+
if txInfo.GasLimit > limit.MaxGasLimit {
51+
h.lane.Logger().Info(
52+
"failed to select tx for lane; gas limit above the maximum allowed",
53+
"lane", h.lane.Name(),
54+
"tx_gas", txInfo.GasLimit,
55+
"max_gas", limit.MaxGasLimit,
56+
"tx_hash", txInfo.Hash,
57+
)
58+
59+
txsToRemove = append(txsToRemove, tx)
60+
continue
61+
}
62+
63+
if txInfo.Size > limit.MaxTxBytes {
64+
h.lane.Logger().Info(
65+
"failed to select tx for lane; tx bytes above the maximum allowed",
66+
"lane", h.lane.Name(),
67+
"tx_size", txInfo.Size,
68+
"max_tx_bytes", limit.MaxTxBytes,
69+
"tx_hash", txInfo.Hash,
70+
)
71+
72+
txsToRemove = append(txsToRemove, tx)
73+
continue
74+
}
75+
5076
// Double check that the transaction belongs to this lane.
5177
if !h.lane.Match(ctx, tx) {
5278
h.lane.Logger().Info(

lanes/base/abci_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ func (s *BaseTestSuite) TestPrepareLane() {
4040
}
4141
lane := s.initLane(math.LegacyMustNewDecFromStr("0.5"), expectedExecution)
4242
s.Require().NoError(lane.Insert(s.ctx, tx))
43+
s.Require().Equal(1, lane.CountTx())
4344

4445
txBz, err := s.encodingConfig.TxConfig.TxEncoder()(tx)
4546
s.Require().NoError(err)
@@ -57,6 +58,8 @@ func (s *BaseTestSuite) TestPrepareLane() {
5758
s.Require().Equal(0, len(finalProposal.Txs))
5859
s.Require().Equal(int64(0), finalProposal.Info.BlockSize)
5960
s.Require().Equal(uint64(0), finalProposal.Info.GasLimit)
61+
s.Require().Equal(0, lane.CountTx())
62+
s.Require().False(lane.Contains(tx))
6063
})
6164

6265
s.Run("should not build a proposal when gas configured to lane is too small", func() {
@@ -79,6 +82,7 @@ func (s *BaseTestSuite) TestPrepareLane() {
7982

8083
// Insert the transaction into the lane
8184
s.Require().NoError(lane.Insert(s.ctx, tx))
85+
s.Require().Equal(1, lane.CountTx())
8286

8387
txBz, err := s.encodingConfig.TxConfig.TxEncoder()(tx)
8488
s.Require().NoError(err)
@@ -100,6 +104,8 @@ func (s *BaseTestSuite) TestPrepareLane() {
100104
s.Require().Equal(0, len(finalProposal.Txs))
101105
s.Require().Equal(int64(0), finalProposal.Info.BlockSize)
102106
s.Require().Equal(uint64(0), finalProposal.Info.GasLimit)
107+
s.Require().Equal(0, lane.CountTx())
108+
s.Require().False(lane.Contains(tx))
103109
})
104110

105111
s.Run("should not build a proposal when gas configured to lane is too small p2", func() {
@@ -144,6 +150,7 @@ func (s *BaseTestSuite) TestPrepareLane() {
144150
s.Require().Equal(0, len(finalProposal.Txs))
145151
s.Require().Equal(int64(0), finalProposal.Info.BlockSize)
146152
s.Require().Equal(uint64(0), finalProposal.Info.GasLimit)
153+
s.Require().Equal(0, lane.CountTx())
147154
})
148155

149156
s.Run("should be able to build a proposal with a tx that just fits in", func() {

lanes/mev/abci.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ func (h *ProposalHandler) PrepareLaneHandler() base.PrepareLaneHandler {
4949
}
5050

5151
cacheCtx, write := ctx.CacheContext()
52-
5352
bundle, err := h.VerifyBidBasic(cacheCtx, bidTx, proposal, limit)
5453
if err != nil {
5554
h.lane.Logger().Info(

lanes/mev/abci_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ func (s *MEVTestSuite) TestPrepareLane() {
196196
s.Require().Equal(0, len(proposal.Info.TxsByLane))
197197
s.Require().Equal(int64(0), proposal.Info.BlockSize)
198198
s.Require().Equal(uint64(0), proposal.Info.GasLimit)
199+
s.Require().Equal(0, lane.CountTx())
199200
})
200201

201202
s.Run("can reject a bid that is too gas intensive", func() {
@@ -221,6 +222,7 @@ func (s *MEVTestSuite) TestPrepareLane() {
221222
s.Require().Equal(0, len(proposal.Info.TxsByLane))
222223
s.Require().Equal(int64(0), proposal.Info.BlockSize)
223224
s.Require().Equal(uint64(0), proposal.Info.GasLimit)
225+
s.Require().Equal(0, lane.CountTx())
224226
})
225227
}
226228

0 commit comments

Comments
 (0)