diff --git a/CHANGELOG.md b/CHANGELOG.md index d56c0a355f..58860259a8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -69,6 +69,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (query) [87d3a43](https://github.com/cosmos/cosmos-sdk/commit/87d3a432af95f4cf96aa02351ed5fcc51cca6e7b) Fix collection filtered pagination. * (sims) [#23952](https://github.com/cosmos/cosmos-sdk/pull/23952) Use liveness matrix for validator sign status in sims * (baseapp) [#24055](https://github.com/cosmos/cosmos-sdk/pull/24055) Align block header when query with latest height. +* (baseapp) [#24074](https://github.com/cosmos/cosmos-sdk/pull/24074) Use CometBFT's ComputeProtoSizeForTxs in defaultTxSelector.SelectTxForProposal for consistency. ## [v0.50.12](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.12) - 2025-02-20 diff --git a/baseapp/abci_utils.go b/baseapp/abci_utils.go index 649ad4230b..51b7b94e56 100644 --- a/baseapp/abci_utils.go +++ b/baseapp/abci_utils.go @@ -11,6 +11,7 @@ import ( cryptoenc "github.com/cometbft/cometbft/crypto/encoding" cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto" cmtproto "github.com/cometbft/cometbft/proto/tendermint/types" + cmttypes "github.com/cometbft/cometbft/types" protoio "github.com/cosmos/gogoproto/io" "github.com/cosmos/gogoproto/proto" //nolint: gci // ignore this line for this linter @@ -497,7 +498,7 @@ func (ts *defaultTxSelector) Clear() { } func (ts *defaultTxSelector) SelectTxForProposal(_ context.Context, maxTxBytes, maxBlockGas uint64, memTx sdk.Tx, txBz []byte) bool { - txSize := uint64(len(txBz)) + txSize := uint64(cmttypes.ComputeProtoSizeForTxs([]cmttypes.Tx{txBz})) var txGasLimit uint64 if memTx != nil { diff --git a/baseapp/abci_utils_test.go b/baseapp/abci_utils_test.go index 42e843c2e2..d7593e3bcc 100644 --- a/baseapp/abci_utils_test.go +++ b/baseapp/abci_utils_test.go @@ -493,6 +493,9 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() s.Require().NoError(err) s.Require().Len(txBz, 152) + txDataSize := int(cmttypes.ComputeProtoSizeForTxs([]cmttypes.Tx{txBz})) + s.Require().Equal(txDataSize, 155) + testCases := map[string]struct { ctx sdk.Context req *abci.RequestPrepareProposal @@ -514,7 +517,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() }), req: &abci.RequestPrepareProposal{ Txs: [][]byte{txBz, txBz, txBz, txBz, txBz}, - MaxTxBytes: 456, + MaxTxBytes: 465, }, expectedTxs: 0, }, @@ -522,10 +525,18 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() ctx: s.ctx, req: &abci.RequestPrepareProposal{ Txs: [][]byte{txBz, txBz, txBz, txBz, txBz}, - MaxTxBytes: 456, + MaxTxBytes: 465, }, expectedTxs: 3, }, + "large max tx bytes len calculation": { + ctx: s.ctx, + req: &abci.RequestPrepareProposal{ + Txs: [][]byte{txBz, txBz, txBz, txBz, txBz}, + MaxTxBytes: 456, + }, + expectedTxs: 2, + }, "max gas and tx bytes": { ctx: s.ctx.WithConsensusParams(cmtproto.ConsensusParams{ Block: &cmtproto.BlockParams{ @@ -534,7 +545,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() }), req: &abci.RequestPrepareProposal{ Txs: [][]byte{txBz, txBz, txBz, txBz, txBz}, - MaxTxBytes: 456, + MaxTxBytes: 465, }, expectedTxs: 2, }, @@ -543,7 +554,7 @@ func (s *ABCIUtilsTestSuite) TestDefaultProposalHandler_NoOpMempoolTxSelection() for name, tc := range testCases { s.Run(name, func() { // iterate multiple times to ensure the tx selector is cleared each time - for i := 0; i < 5; i++ { + for i := 0; i < 6; i++ { resp, err := handler(tc.ctx, tc.req) s.Require().NoError(err) s.Require().Len(resp.Txs, tc.expectedTxs)