Skip to content

Commit

Permalink
fix: Evict txs from mempool exceeding size limits (#550) (#552)
Browse files Browse the repository at this point in the history
* init

* nit test case

(cherry picked from commit b8d9c22)

Co-authored-by: David Terpay <[email protected]>
  • Loading branch information
mergify[bot] and davidterpay authored Jun 25, 2024
1 parent cb0d9bd commit 9d3be7b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
26 changes: 26 additions & 0 deletions block/base/proposals.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 7 additions & 0 deletions lanes/base/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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() {
Expand All @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down
1 change: 0 additions & 1 deletion lanes/mev/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions lanes/mev/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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())
})
}

Expand Down

0 comments on commit 9d3be7b

Please sign in to comment.