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

Commit

Permalink
fix: Use MaxTxBytes on the PrepareProposal request (backport #269) (
Browse files Browse the repository at this point in the history
#270)

* req size check (#269)

(cherry picked from commit 43d6b04)

# Conflicts:
#	abci/abci.go
#	abci/abci_test.go

* merge conflict fix

---------

Co-authored-by: David Terpay <[email protected]>
Co-authored-by: David Terpay <[email protected]>
  • Loading branch information
3 people authored Dec 6, 2023
1 parent d2a7f21 commit ea5748f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 18 deletions.
6 changes: 5 additions & 1 deletion abci/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler {
"height", req.Height,
)

// Get the max gas limit and max block size for the proposal.
_, maxGasLimit := proposals.GetBlockLimits(ctx)
proposal := proposals.NewProposal(h.logger, req.MaxTxBytes, maxGasLimit)

// Fill the proposal with transactions from each lane.
finalProposal, err := h.prepareLanesHandler(ctx, proposals.NewProposalWithContext(ctx, h.logger))
finalProposal, err := h.prepareLanesHandler(ctx, proposal)
if err != nil {
h.logger.Error("failed to prepare proposal", "err", err)
return abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}
Expand Down
55 changes: 38 additions & 17 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)
s.Require().Equal(0, len(resp.Txs))
})
Expand All @@ -84,7 +85,9 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx))

proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler()
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx)
Expand Down Expand Up @@ -123,7 +126,9 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx2))

proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler()
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx2, tx1)
Expand Down Expand Up @@ -162,7 +167,9 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {
s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx2))

proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler()
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx1)
Expand All @@ -176,7 +183,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)
s.Require().Equal(0, len(resp.Txs))
})
Expand Down Expand Up @@ -205,7 +213,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx, bundleTxs[0])
Expand Down Expand Up @@ -243,7 +252,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx, bundleTxs[0])
Expand Down Expand Up @@ -282,7 +292,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(bundleTxs[0])
Expand Down Expand Up @@ -324,7 +335,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {
size := int64(len(proposal[0]) - 1)

s.setBlockParams(10000000, size)
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

s.Require().Equal(1, len(resp.Txs))
Expand Down Expand Up @@ -359,7 +371,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {

proposal := s.getTxBytes(freeTx)

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

s.Require().Equal(1, len(resp.Txs))
Expand Down Expand Up @@ -425,7 +438,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {
proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, freeLane, defaultLane}).PrepareProposalHandler()
proposal := s.getTxBytes(tx, bundleTxs[0], bundleTxs[1], bundleTxs[2], bundleTxs[3], freeTx, normalTx)

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

s.Require().Equal(7, len(resp.Txs))
Expand Down Expand Up @@ -476,7 +490,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() {
proposal := s.getTxBytes(tx, bundleTxs[0], normalTx)

// Should be theoretically sufficient to fit the bid tx and the bundled tx + normal tx
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

s.Require().Equal(1, len(resp.Txs))
Expand Down Expand Up @@ -522,7 +537,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
mempool,
).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx)
Expand Down Expand Up @@ -567,7 +583,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
mempool,
).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx)
Expand Down Expand Up @@ -614,7 +631,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
mempool,
).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx)
Expand Down Expand Up @@ -661,7 +679,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
mempool,
).PrepareProposalHandler()

resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})
maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

proposal := s.getTxBytes(tx)
Expand Down Expand Up @@ -1308,7 +1327,9 @@ func (s *ProposalsTestSuite) TestPrepareProcessParity() {
// Create a proposal with the retrieved transactions
// Set up the default lane with no transactions
proposalHandler := s.setUpProposalHandlers([]block.Lane{freelane, defaultLane}).PrepareProposalHandler()
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2})

maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes
resp := proposalHandler(s.ctx, cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes})
s.Require().NotNil(resp)

// Ensure the transactions are in the correct order for the free lane
Expand Down

0 comments on commit ea5748f

Please sign in to comment.