From 17b3a727e698c298658f329362ab77d5fb045684 Mon Sep 17 00:00:00 2001 From: Rootul Patel Date: Wed, 16 Oct 2024 14:50:56 -0400 Subject: [PATCH] refactor: rename limits from tx to msg --- app/test/prepare_proposal_test.go | 24 ++++++++++++------------ app/validate_txs.go | 16 ++++++++-------- pkg/appconsts/global_consts.go | 12 +++++++----- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index e0c963de8f..f274d9da6a 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -297,7 +297,7 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { signers = append(signers, signer) } - numberOfPFBs := appconsts.PFBTransactionCap + 500 + numberOfPFBs := appconsts.MaxPFBMessages + 500 pfbTxs := make([][]byte, 0, numberOfPFBs) randomBytes := make([]byte, 2000) _, err := rand.Read(randomBytes) @@ -333,7 +333,7 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { accountIndex++ } - numberOfMsgSends := appconsts.NonPFBTransactionCap + 500 + numberOfMsgSends := appconsts.MaxNonPFBMessages + 500 msgSendTxs := make([][]byte, 0, numberOfMsgSends) for i := 0; i < numberOfMsgSends; i++ { msg := banktypes.NewMsgSend( @@ -354,18 +354,18 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { }{ { name: "capping only PFB transactions", - inputTransactions: pfbTxs[:appconsts.PFBTransactionCap+50], - expectedTransactions: pfbTxs[:appconsts.PFBTransactionCap], + inputTransactions: pfbTxs[:appconsts.MaxPFBMessages+50], + expectedTransactions: pfbTxs[:appconsts.MaxPFBMessages], }, { name: "capping only PFB transactions with multiple messages", - inputTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap], - expectedTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap/numberOfMsgsPerTx], + inputTransactions: multiPFBsPerTxs[:appconsts.MaxPFBMessages], + expectedTransactions: multiPFBsPerTxs[:appconsts.MaxPFBMessages/numberOfMsgsPerTx], }, { name: "capping only msg send transactions", - inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap+50], - expectedTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap], + inputTransactions: msgSendTxs[:appconsts.MaxNonPFBMessages+50], + expectedTransactions: msgSendTxs[:appconsts.MaxNonPFBMessages], }, { name: "capping msg send after pfb transactions", @@ -376,8 +376,8 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { return input }(), expectedTransactions: func() [][]byte { - expected := make([][]byte, 0, appconsts.NonPFBTransactionCap+100) - expected = append(expected, msgSendTxs[:appconsts.NonPFBTransactionCap]...) + expected := make([][]byte, 0, appconsts.MaxNonPFBMessages+100) + expected = append(expected, msgSendTxs[:appconsts.MaxNonPFBMessages]...) expected = append(expected, pfbTxs[:100]...) return expected }(), @@ -391,9 +391,9 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { return input }(), expectedTransactions: func() [][]byte { - expected := make([][]byte, 0, appconsts.PFBTransactionCap+100) + expected := make([][]byte, 0, appconsts.MaxPFBMessages+100) expected = append(expected, msgSendTxs[:100]...) - expected = append(expected, pfbTxs[:appconsts.PFBTransactionCap]...) + expected = append(expected, pfbTxs[:appconsts.MaxPFBMessages]...) return expected }(), }, diff --git a/app/validate_txs.go b/app/validate_txs.go index 7ff37a8fbb..ee3edfbb6f 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -45,7 +45,7 @@ func FilterTxs(logger log.Logger, ctx sdk.Context, handler sdk.AnteHandler, txCo // function used to apply the ante handler. func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs [][]byte) ([][]byte, sdk.Context) { n := 0 - nonPFBTransactionsCount := 0 + nonPFBMessageCount := 0 for _, tx := range txs { sdkTx, err := dec(tx) if err != nil { @@ -57,11 +57,11 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler ctx = ctx.WithTxBytes(tx) msgTypes := msgTypes(sdkTx) - if nonPFBTransactionsCount+len(sdkTx.GetMsgs()) > appconsts.NonPFBTransactionCap { - logger.Debug("skipping tx because the sdk message cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) + if nonPFBMessageCount+len(sdkTx.GetMsgs()) > appconsts.MaxNonPFBMessages { + logger.Debug("skipping tx because the max non PFB message count was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) continue } - nonPFBTransactionsCount += len(sdkTx.GetMsgs()) + nonPFBMessageCount += len(sdkTx.GetMsgs()) ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we @@ -90,7 +90,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler // function used to apply the ante handler. func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []*tx.BlobTx) ([]*tx.BlobTx, sdk.Context) { n := 0 - pfbTransactionCount := 0 + pfbMessageCount := 0 for _, tx := range txs { sdkTx, err := dec(tx.Tx) if err != nil { @@ -101,11 +101,11 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle // Set the tx size on the context before calling the AnteHandler ctx = ctx.WithTxBytes(tx.Tx) - if pfbTransactionCount+len(sdkTx.GetMsgs()) > appconsts.PFBTransactionCap { - logger.Debug("skipping tx because the pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) + if pfbMessageCount+len(sdkTx.GetMsgs()) > appconsts.MaxPFBMessages { + logger.Debug("skipping tx because the max pfb message count was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) continue } - pfbTransactionCount += len(sdkTx.GetMsgs()) + pfbMessageCount += len(sdkTx.GetMsgs()) ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index ca73aa8fee..7475c5025b 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -68,11 +68,13 @@ func HashLength() int { return hashLength } -// The following consts are not consensus breaking and will be applied straight after this binary is started. +// The following consts are not consensus breaking and will be applied straight +// after this binary is started. const ( - // NonPFBTransactionCap is the maximum number of SDK messages, aside from PFBs, that a block can contain. - NonPFBTransactionCap = 200 + // MaxNonPFBMessages is the maximum number of SDK messages, aside from + // PFBs, that a block can contain. + MaxNonPFBMessages = 200 - // PFBTransactionCap is the maximum number of PFB messages a block can contain. - PFBTransactionCap = 600 + // MaxPFBMessages is the maximum number of PFB messages a block can contain. + MaxPFBMessages = 600 )