fix: Evict txs from mempool exceeding size limits (#550)

* init

* nit test case
This commit is contained in:
David Terpay 2024-06-25 11:58:04 -04:00 committed by GitHub
parent 79d7ef7c33
commit b8d9c22833
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 35 additions and 1 deletions

View File

@ -47,6 +47,32 @@ func (h *DefaultProposalHandler) PrepareLaneHandler() PrepareLaneHandler {
continue
}
if txInfo.GasLimit > limit.MaxGasLimit {
h.lane.Logger().Info(
"failed to select tx for lane; gas limit above the maximum allowed",
"lane", h.lane.Name(),
"tx_gas", txInfo.GasLimit,
"max_gas", limit.MaxGasLimit,
"tx_hash", txInfo.Hash,
)
txsToRemove = append(txsToRemove, tx)
continue
}
if txInfo.Size > limit.MaxTxBytes {
h.lane.Logger().Info(
"failed to select tx for lane; tx bytes above the maximum allowed",
"lane", h.lane.Name(),
"tx_size", txInfo.Size,
"max_tx_bytes", limit.MaxTxBytes,
"tx_hash", txInfo.Hash,
)
txsToRemove = append(txsToRemove, tx)
continue
}
// Double check that the transaction belongs to this lane.
if !h.lane.Match(ctx, tx) {
h.lane.Logger().Info(

View File

@ -40,6 +40,7 @@ func (s *BaseTestSuite) TestPrepareLane() {
}
lane := s.initLane(math.LegacyMustNewDecFromStr("0.5"), expectedExecution)
s.Require().NoError(lane.Insert(s.ctx, tx))
s.Require().Equal(1, lane.CountTx())
txBz, err := s.encodingConfig.TxConfig.TxEncoder()(tx)
s.Require().NoError(err)
@ -57,6 +58,8 @@ func (s *BaseTestSuite) TestPrepareLane() {
s.Require().Equal(0, len(finalProposal.Txs))
s.Require().Equal(int64(0), finalProposal.Info.BlockSize)
s.Require().Equal(uint64(0), finalProposal.Info.GasLimit)
s.Require().Equal(0, lane.CountTx())
s.Require().False(lane.Contains(tx))
})
s.Run("should not build a proposal when gas configured to lane is too small", func() {
@ -79,6 +82,7 @@ func (s *BaseTestSuite) TestPrepareLane() {
// Insert the transaction into the lane
s.Require().NoError(lane.Insert(s.ctx, tx))
s.Require().Equal(1, lane.CountTx())
txBz, err := s.encodingConfig.TxConfig.TxEncoder()(tx)
s.Require().NoError(err)
@ -100,6 +104,8 @@ func (s *BaseTestSuite) TestPrepareLane() {
s.Require().Equal(0, len(finalProposal.Txs))
s.Require().Equal(int64(0), finalProposal.Info.BlockSize)
s.Require().Equal(uint64(0), finalProposal.Info.GasLimit)
s.Require().Equal(0, lane.CountTx())
s.Require().False(lane.Contains(tx))
})
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() {
s.Require().Equal(0, len(finalProposal.Txs))
s.Require().Equal(int64(0), finalProposal.Info.BlockSize)
s.Require().Equal(uint64(0), finalProposal.Info.GasLimit)
s.Require().Equal(0, lane.CountTx())
})
s.Run("should be able to build a proposal with a tx that just fits in", func() {

View File

@ -49,7 +49,6 @@ func (h *ProposalHandler) PrepareLaneHandler() base.PrepareLaneHandler {
}
cacheCtx, write := ctx.CacheContext()
bundle, err := h.VerifyBidBasic(cacheCtx, bidTx, proposal, limit)
if err != nil {
h.lane.Logger().Info(

View File

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