diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index e0c963de8f..cd41a3aa2c 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.PFBTransactionCap(testApp.AppVersion()) + 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.NonPFBTransactionCap(testApp.AppVersion()) + 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.PFBTransactionCap(testApp.AppVersion())+50], + expectedTransactions: pfbTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())], }, { name: "capping only PFB transactions with multiple messages", - inputTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap], - expectedTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap/numberOfMsgsPerTx], + inputTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())], + expectedTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())/numberOfMsgsPerTx], }, { name: "capping only msg send transactions", - inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap+50], - expectedTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap], + inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap(testApp.AppVersion())+50], + expectedTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap(testApp.AppVersion())], }, { 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.NonPFBTransactionCap(testApp.AppVersion())+100) + expected = append(expected, msgSendTxs[:appconsts.NonPFBTransactionCap(testApp.AppVersion())]...) 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.PFBTransactionCap(testApp.AppVersion())+100) expected = append(expected, msgSendTxs[:100]...) - expected = append(expected, pfbTxs[:appconsts.PFBTransactionCap]...) + expected = append(expected, pfbTxs[:appconsts.PFBTransactionCap(testApp.AppVersion())]...) return expected }(), }, diff --git a/app/validate_txs.go b/app/validate_txs.go index 7ff37a8fbb..063fc73fb9 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -57,7 +57,7 @@ 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 { + if nonPFBTransactionsCount+len(sdkTx.GetMsgs()) > appconsts.NonPFBTransactionCap(ctx.ConsensusParams().Version.AppVersion) { logger.Debug("skipping tx because the sdk message cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) continue } @@ -101,7 +101,7 @@ 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 { + if pfbTransactionCount+len(sdkTx.GetMsgs()) > appconsts.PFBTransactionCap(ctx.ConsensusParams().Version.AppVersion) { logger.Debug("skipping tx because the pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) continue } diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index ca73aa8fee..424d4bbe3f 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -67,12 +67,3 @@ func UpgradeHeightDelay() int64 { func HashLength() int { return hashLength } - -// 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 - - // PFBTransactionCap is the maximum number of PFB messages a block can contain. - PFBTransactionCap = 600 -) diff --git a/pkg/appconsts/v2/app_consts.go b/pkg/appconsts/v2/app_consts.go index d5829e84c5..78ed7a529d 100644 --- a/pkg/appconsts/v2/app_consts.go +++ b/pkg/appconsts/v2/app_consts.go @@ -4,4 +4,10 @@ const ( Version uint64 = 2 SquareSizeUpperBound int = 128 SubtreeRootThreshold int = 64 + // NonPFBTransactionCap is the maximum number of SDK messages, aside from + // PFBs, that a block can contain. + NonPFBTransactionCap = 200 + // PFBTransactionCap is the maximum number of PFB messages a block can + // contain. + PFBTransactionCap = 600 ) diff --git a/pkg/appconsts/v3/app_consts.go b/pkg/appconsts/v3/app_consts.go index 4b65941de1..5cd10d173b 100644 --- a/pkg/appconsts/v3/app_consts.go +++ b/pkg/appconsts/v3/app_consts.go @@ -7,4 +7,10 @@ const ( TxSizeCostPerByte uint64 = 10 GasPerBlobByte uint32 = 8 MaxTxSize int = 2097152 // 2 MiB in bytes + // NonPFBTransactionCap is the maximum number of SDK messages, aside from + // PFBs, that a block can contain. + NonPFBTransactionCap = 200 + // PFBTransactionCap is the maximum number of PFB messages a block can + // contain. + PFBTransactionCap = 600 ) diff --git a/pkg/appconsts/versioned_consts.go b/pkg/appconsts/versioned_consts.go index 1eb40deb83..95e89eca11 100644 --- a/pkg/appconsts/versioned_consts.go +++ b/pkg/appconsts/versioned_consts.go @@ -46,6 +46,14 @@ func MaxTxSize(_ uint64) int { return v3.MaxTxSize } +func NonPFBTransactionCap(_ uint64) int { + return v3.NonPFBTransactionCap +} + +func PFBTransactionCap(_ uint64) int { + return v3.PFBTransactionCap +} + var ( DefaultSubtreeRootThreshold = SubtreeRootThreshold(LatestVersion) DefaultSquareSizeUpperBound = SquareSizeUpperBound(LatestVersion) diff --git a/pkg/appconsts/versioned_consts_test.go b/pkg/appconsts/versioned_consts_test.go index f621c0199e..631648e04f 100644 --- a/pkg/appconsts/versioned_consts_test.go +++ b/pkg/appconsts/versioned_consts_test.go @@ -72,6 +72,30 @@ func TestVersionedConsts(t *testing.T) { expectedConstant: v3.MaxTxSize, got: appconsts.MaxTxSize(v3.Version), }, + { + name: "NonPFBTransactionCap v2", + version: v2.Version, + expectedConstant: v2.NonPFBTransactionCap, + got: appconsts.NonPFBTransactionCap(v2.Version), + }, + { + name: "NonPFBTransactionCap v3", + version: v3.Version, + expectedConstant: v3.NonPFBTransactionCap, + got: appconsts.NonPFBTransactionCap(v3.Version), + }, + { + name: "PFBTransactionCap v2", + version: v2.Version, + expectedConstant: v2.PFBTransactionCap, + got: appconsts.PFBTransactionCap(v2.Version), + }, + { + name: "PFBTransactionCap v3", + version: v3.Version, + expectedConstant: v3.PFBTransactionCap, + got: appconsts.PFBTransactionCap(v3.Version), + }, } for _, tc := range testCases {