From 43d6b048efc65ae52482d0416b722428ba247e1e Mon Sep 17 00:00:00 2001 From: David Terpay <35130517+davidterpay@users.noreply.github.com> Date: Wed, 6 Dec 2023 12:25:52 -0500 Subject: [PATCH] req size check (#269) --- abci/abci.go | 6 +++++- abci/abci_test.go | 52 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 17 deletions(-) diff --git a/abci/abci.go b/abci/abci.go index 74367138..4ea64a66 100644 --- a/abci/abci.go +++ b/abci/abci.go @@ -74,9 +74,13 @@ func (h *ProposalHandler) PrepareProposalHandler() sdk.PrepareProposalHandler { return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err } + // 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. prepareLanesHandler := ChainPrepareLanes(registry) - finalProposal, err := prepareLanesHandler(ctx, proposals.NewProposalWithContext(ctx, h.logger)) + finalProposal, err := prepareLanesHandler(ctx, proposal) if err != nil { h.logger.Error("failed to prepare proposal", "err", err) return &abci.ResponsePrepareProposal{Txs: make([][]byte, 0)}, err diff --git a/abci/abci_test.go b/abci/abci_test.go index b9dd7fb0..d215fbc5 100644 --- a/abci/abci_test.go +++ b/abci/abci_test.go @@ -90,7 +90,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) s.Require().Equal(0, len(resp.Txs)) @@ -114,7 +115,9 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx)) proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NotNil(resp) s.Require().NoError(err) @@ -154,7 +157,9 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx2)) proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NotNil(resp) s.Require().NoError(err) @@ -194,7 +199,9 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { s.Require().NoError(defaultLane.Insert(sdk.Context{}, tx2)) proposalHandler := s.setUpProposalHandlers([]block.Lane{defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NotNil(resp) s.Require().NoError(err) @@ -209,7 +216,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) s.Require().Equal(0, len(resp.Txs)) @@ -239,7 +247,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -278,7 +287,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -318,7 +328,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { proposalHandler := s.setUpProposalHandlers([]block.Lane{mevLane, defaultLane}).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -355,7 +366,8 @@ func (s *ProposalsTestSuite) TestPrepareProposal() { proposal := s.getTxBytes(freeTx) - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -422,7 +434,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, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -474,7 +487,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, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -539,7 +553,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() { mempool, ).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -603,7 +618,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() { mempool, ).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -674,7 +690,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() { mempool, ).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -745,7 +762,8 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() { mempool, ).PrepareProposalHandler() - resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp) @@ -1407,7 +1425,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, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2}) + + maxTxBytes := s.ctx.ConsensusParams().Block.MaxBytes + resp, err := proposalHandler(s.ctx, &cometabci.RequestPrepareProposal{Height: 2, MaxTxBytes: maxTxBytes}) s.Require().NoError(err) s.Require().NotNil(resp)