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

Commit

Permalink
fix: only one lane can use unlimited block space (backport #348) (#352)
Browse files Browse the repository at this point in the history
* fix (#348)

(cherry picked from commit a135d8f)

# Conflicts:
#	block/mempool_test.go

* fix

---------

Co-authored-by: Alex Johnson <[email protected]>
  • Loading branch information
mergify[bot] and Alex Johnson authored Jan 3, 2024
1 parent 95436d1 commit ef32b48
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 19 deletions.
27 changes: 13 additions & 14 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
defaultLane := s.setUpStandardLane(math.LegacyMustNewDecFromStr("0.0"), map[sdk.Tx]bool{})

proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, freeLane, defaultLane}).ProcessProposalHandler()
proposal := [][]byte{}
var proposal [][]byte

resp := proposalHandler(s.ctx, cometabci.RequestProcessProposal{Txs: proposal, Height: 2})
s.Require().NotNil(resp)
Expand Down Expand Up @@ -730,11 +730,10 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
tx2: true,
})

defaultLane.Insert(sdk.Context{}, tx1)
defaultLane.Insert(sdk.Context{}, tx2)

txs := [][]sdk.Tx{}
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx1))
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx2))

var txs [][]sdk.Tx
for iterator := defaultLane.Select(context.Background(), nil); iterator != nil; iterator = iterator.Next() {
txs = append(txs, []sdk.Tx{iterator.Tx()})
}
Expand Down Expand Up @@ -1006,7 +1005,7 @@ func (s *ProposalsTestSuite) TestProcessProposal() {
s.Require().NoError(err)

// Mev lane
mevLane := s.setUpTOBLane(math.LegacyMustNewDecFromStr("0.0"), map[sdk.Tx]bool{})
mevLane := s.setUpTOBLane(math.LegacyMustNewDecFromStr("0.3"), map[sdk.Tx]bool{})

// Set up the default lane
defaultLane := s.setUpStandardLane(math.LegacyMustNewDecFromStr("0.0"), map[sdk.Tx]bool{tx2: true, tx1: true})
Expand Down Expand Up @@ -1272,13 +1271,13 @@ func (s *ProposalsTestSuite) TestPrepareProcessParity() {
}

// Set up the default lane with the transactions
defaultLane := s.setUpStandardLane(math.LegacyMustNewDecFromStr("0.0"), validationMap)
defaultLane := s.setUpStandardLane(math.LegacyZeroDec(), validationMap)
for _, tx := range txsToInsert {
s.Require().NoError(defaultLane.Insert(s.ctx, tx))
}

// Create a bunch of transactions to insert into the free lane
freeTxsToInsert := []sdk.Tx{}
var freeTxsToInsert []sdk.Tx
freeValidationMap := make(map[sdk.Tx]bool)
for _, account := range accounts {
for nonce := uint64(0); nonce < numTxsPerAccount; nonce++ {
Expand All @@ -1300,20 +1299,20 @@ func (s *ProposalsTestSuite) TestPrepareProcessParity() {
}
}

freelane := s.setUpFreeLane(math.LegacyMustNewDecFromStr("0.0"), freeValidationMap)
freelane := s.setUpFreeLane(math.LegacyMustNewDecFromStr("0.25"), freeValidationMap)
for _, tx := range freeTxsToInsert {
s.Require().NoError(freelane.Insert(s.ctx, tx))
}

// Retrieve the transactions from the default lane in the same way the prepare function would.
retrievedTxs := []sdk.Tx{}
var retrievedTxs []sdk.Tx
for iterator := defaultLane.Select(context.Background(), nil); iterator != nil; iterator = iterator.Next() {
retrievedTxs = append(retrievedTxs, iterator.Tx())
}
s.Require().Equal(len(txsToInsert), len(retrievedTxs))

// Retrieve the transactions from the free lane in the same way the prepare function would.
freeRetrievedTxs := []sdk.Tx{}
var freeRetrievedTxs []sdk.Tx
for iterator := freelane.Select(context.Background(), nil); iterator != nil; iterator = iterator.Next() {
freeRetrievedTxs = append(freeRetrievedTxs, iterator.Tx())
}
Expand Down Expand Up @@ -1389,13 +1388,13 @@ func (s *ProposalsTestSuite) TestIterateMempoolAndProcessProposalParity() {
}

// Set up the default lane with the transactions
defaultLane := s.setUpStandardLane(math.LegacyMustNewDecFromStr("0.0"), validationMap)
defaultLane := s.setUpStandardLane(math.LegacyZeroDec(), validationMap)
for _, tx := range txsToInsert {
s.Require().NoError(defaultLane.Insert(s.ctx, tx))
}

// Create a bunch of transactions to insert into the free lane
freeTxsToInsert := []sdk.Tx{}
var freeTxsToInsert []sdk.Tx
freeValidationMap := make(map[sdk.Tx]bool)
for _, account := range accounts {
for nonce := uint64(0); nonce < numTxsPerAccount; nonce++ {
Expand All @@ -1417,7 +1416,7 @@ func (s *ProposalsTestSuite) TestIterateMempoolAndProcessProposalParity() {
}
}

freelane := s.setUpFreeLane(math.LegacyMustNewDecFromStr("0.0"), freeValidationMap)
freelane := s.setUpFreeLane(math.LegacyMustNewDecFromStr("0.3"), freeValidationMap)
for _, tx := range freeTxsToInsert {
s.Require().NoError(freelane.Insert(s.ctx, tx))
}
Expand Down
4 changes: 3 additions & 1 deletion block/mempool.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ func (m *LanedMempool) ValidateBasic() error {
}

maxBlockSpace := lane.GetMaxBlockSpace()
if maxBlockSpace.IsZero() {
if seenZeroMaxBlockSpace && maxBlockSpace.IsZero() {
return fmt.Errorf("only one lane can have unlimited max block space")
} else if maxBlockSpace.IsZero() {
seenZeroMaxBlockSpace = true
}

Expand Down
4 changes: 2 additions & 2 deletions block/mempool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (suite *BlockBusterTestSuite) SetupTest() {
TxDecoder: suite.encodingConfig.TxConfig.TxDecoder(),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
AnteHandler: nil,
MaxBlockSpace: math.LegacyZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.3"),
}
factory := mev.NewDefaultAuctionFactory(suite.encodingConfig.TxConfig.TxDecoder(), signer_extraction.NewDefaultAdapter())
suite.mevLane = mev.NewMEVLane(
Expand All @@ -82,7 +82,7 @@ func (suite *BlockBusterTestSuite) SetupTest() {
TxDecoder: suite.encodingConfig.TxConfig.TxDecoder(),
SignerExtractor: signer_extraction.NewDefaultAdapter(),
AnteHandler: nil,
MaxBlockSpace: math.LegacyZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.3"),
}
suite.freeLane = free.NewFreeLane(
freeConfig,
Expand Down
4 changes: 2 additions & 2 deletions testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func CreateMempool() *block.LanedMempool {
TxEncoder: encodingConfig.TxConfig.TxEncoder(),
TxDecoder: encodingConfig.TxConfig.TxDecoder(),
AnteHandler: nil,
MaxBlockSpace: math.LegacyZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.3"),
MaxTxs: 0, // unlimited
}
factory := mev.NewDefaultAuctionFactory(encodingConfig.TxConfig.TxDecoder(), signerExtractor)
Expand All @@ -73,7 +73,7 @@ func CreateMempool() *block.LanedMempool {
TxEncoder: encodingConfig.TxConfig.TxEncoder(),
TxDecoder: encodingConfig.TxConfig.TxDecoder(),
AnteHandler: nil,
MaxBlockSpace: math.LegacyZeroDec(),
MaxBlockSpace: math.LegacyMustNewDecFromStr("0.3"),
MaxTxs: 0, // unlimited
}
freeLane := free.NewFreeLane[string](freeConfig, base.DefaultTxPriority(), free.DefaultMatchHandler())
Expand Down

0 comments on commit ef32b48

Please sign in to comment.