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) #271

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 @@ -70,8 +70,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)}, err
Expand Down
60 changes: 40 additions & 20 deletions abci/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,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))
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, 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)

Expand Down Expand Up @@ -124,7 +127,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)

Expand Down Expand Up @@ -164,7 +169,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)

Expand All @@ -179,7 +186,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))
Expand Down Expand Up @@ -209,7 +217,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)

Expand Down Expand Up @@ -248,7 +257,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)

Expand Down Expand Up @@ -288,7 +298,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)

Expand Down Expand Up @@ -325,7 +336,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)

Expand Down Expand Up @@ -392,7 +404,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)

Expand Down Expand Up @@ -444,7 +457,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)

Expand Down Expand Up @@ -485,13 +499,14 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
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)

Expand Down Expand Up @@ -531,13 +546,14 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
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)

Expand Down Expand Up @@ -579,13 +595,14 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
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)

Expand Down Expand Up @@ -627,13 +644,14 @@ func (s *ProposalsTestSuite) TestPrepareProposalEdgeCases() {
s.Require().NoError(err)

proposalHandler := abci.NewProposalHandler(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
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)

Expand Down Expand Up @@ -1295,7 +1313,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)

Expand Down
10 changes: 5 additions & 5 deletions abci/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (s *ProposalsTestSuite) setUpCustomMatchHandlerLane(maxBlockSpace math.Lega

func (s *ProposalsTestSuite) setUpStandardLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool) *defaultlane.DefaultLane {
cfg := base.LaneConfig{
Logger: log.NewTestLogger(s.T()),
Logger: log.NewNopLogger(),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
Expand All @@ -91,7 +91,7 @@ func (s *ProposalsTestSuite) setUpStandardLane(maxBlockSpace math.LegacyDec, exp

func (s *ProposalsTestSuite) setUpTOBLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool) *mev.MEVLane {
cfg := base.LaneConfig{
Logger: log.NewTestLogger(s.T()),
Logger: log.NewNopLogger(),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
Expand All @@ -105,7 +105,7 @@ func (s *ProposalsTestSuite) setUpTOBLane(maxBlockSpace math.LegacyDec, expected

func (s *ProposalsTestSuite) setUpFreeLane(maxBlockSpace math.LegacyDec, expectedExecution map[sdk.Tx]bool) *free.FreeLane {
cfg := base.LaneConfig{
Logger: log.NewTestLogger(s.T()),
Logger: log.NewNopLogger(),
TxEncoder: s.encodingConfig.TxConfig.TxEncoder(),
TxDecoder: s.encodingConfig.TxConfig.TxDecoder(),
AnteHandler: s.setUpAnteHandler(expectedExecution),
Expand Down Expand Up @@ -139,11 +139,11 @@ func (s *ProposalsTestSuite) setUpPanicLane(name string, maxBlockSpace math.Lega
}

func (s *ProposalsTestSuite) setUpProposalHandlers(lanes []block.Lane) *abci.ProposalHandler {
mempool, err := block.NewLanedMempool(log.NewTestLogger(s.T()), lanes)
mempool, err := block.NewLanedMempool(log.NewNopLogger(), lanes)
s.Require().NoError(err)

return abci.NewProposalHandler(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxDecoder(),
s.encodingConfig.TxConfig.TxEncoder(),
mempool,
Expand Down
2 changes: 1 addition & 1 deletion lanes/base/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1632,7 +1632,7 @@ func (s *BaseTestSuite) initLane(
expectedExecution map[sdk.Tx]bool,
) *defaultlane.DefaultLane {
config := base.NewLaneConfig(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encodingConfig.TxConfig.TxEncoder(),
s.encodingConfig.TxConfig.TxDecoder(),
s.setUpAnteHandler(expectedExecution),
Expand Down
2 changes: 1 addition & 1 deletion lanes/mev/mev_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (s *MEVTestSuite) initLane(
expectedExecution map[sdk.Tx]bool,
) *mev.MEVLane {
config := base.NewLaneConfig(
log.NewTestLogger(s.T()),
log.NewNopLogger(),
s.encCfg.TxConfig.TxEncoder(),
s.encCfg.TxConfig.TxDecoder(),
s.setUpAnteHandler(expectedExecution),
Expand Down
Loading