Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use MaxTxBytes on the PrepareProposal request (backport #269) #270

Merged
merged 2 commits into from
Dec 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading