From 9d3be7bfed50274a6b098a6b37f51eacf974f9d0 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 25 Jun 2024 13:21:21 -0400 Subject: [PATCH] fix: Evict txs from mempool exceeding size limits (#550) (#552) * init * nit test case (cherry picked from commit b8d9c22833230380e9a2edf8edbf8d0b058fe023) Co-authored-by: David Terpay <35130517+davidterpay@users.noreply.github.com> --- block/base/proposals.go | 26 ++++++++++++++++++++++++++ lanes/base/abci_test.go | 7 +++++++ lanes/mev/abci.go | 1 - lanes/mev/abci_test.go | 2 ++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/block/base/proposals.go b/block/base/proposals.go index ed0f2f6a..b1f5edab 100644 --- a/block/base/proposals.go +++ b/block/base/proposals.go @@ -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( diff --git a/lanes/base/abci_test.go b/lanes/base/abci_test.go index d94ae1a8..2964ff23 100644 --- a/lanes/base/abci_test.go +++ b/lanes/base/abci_test.go @@ -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() { diff --git a/lanes/mev/abci.go b/lanes/mev/abci.go index ecab72f5..b79ce6c4 100644 --- a/lanes/mev/abci.go +++ b/lanes/mev/abci.go @@ -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( diff --git a/lanes/mev/abci_test.go b/lanes/mev/abci_test.go index 2db057eb..dfabb29a 100644 --- a/lanes/mev/abci_test.go +++ b/lanes/mev/abci_test.go @@ -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()) }) }