From 097a126d8b4e8cb5ae9e1093aac97b1934870967 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 4 Oct 2024 19:32:39 +0400 Subject: [PATCH 01/19] feat: limit the number of msg send and PFBs in prepare proposal --- app/test/prepare_proposal_test.go | 126 ++++++++++++++++++++++++++++++ app/validate_txs.go | 36 ++++++++- pkg/appconsts/v3/app_consts.go | 5 ++ 3 files changed, 166 insertions(+), 1 deletion(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 8bfcc281f8..123c04adda 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -1,6 +1,15 @@ package app_test import ( + "fmt" + v3consts "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" + "github.com/celestiaorg/celestia-app/v3/pkg/user" + "github.com/celestiaorg/celestia-app/v3/test/util/testnode" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/auth/types" + banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" + "github.com/stretchr/testify/assert" + "math/rand" "testing" "time" @@ -204,6 +213,123 @@ func TestPrepareProposalFiltering(t *testing.T) { } } +func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { + // creating a big number of accounts so that every account + // only creates a single transaction. This is for transactions + // to be skipped without worrying about the sequence number being + // sequential. + numberOfAccounts := 8000 + accounts := make([]string, 0, numberOfAccounts) + for i := 0; i < numberOfAccounts; i++ { + accounts = append(accounts, fmt.Sprintf("account%d", i)) + } + consensusParams := app.DefaultConsensusParams() + consensusParams.Block.MaxBytes = 128 + testApp, kr := testutil.SetupTestAppWithGenesisValSet(consensusParams, accounts...) + enc := encoding.MakeConfig(app.ModuleEncodingRegisters...) + + addrs := make([]sdk.AccAddress, 0, numberOfAccounts) + accs := make([]types.AccountI, 0, numberOfAccounts) + signers := make([]*user.Signer, 0, numberOfAccounts) + for index, account := range accounts { + addr := testfactory.GetAddress(kr, account) + addrs = append(addrs, addr) + acc := testutil.DirectQueryAccount(testApp, addrs[index]) + accs = append(accs, acc) + signer, err := user.NewSigner(kr, enc.TxConfig, testutil.ChainID, appconsts.LatestVersion, user.NewAccount(account, acc.GetAccountNumber(), acc.GetSequence())) + require.NoError(t, err) + signers = append(signers, signer) + } + + numberOfPFBs := v3consts.PFBTransactionCap + 500 + pfbTxs := make([][]byte, 0, numberOfPFBs) + randomBytes := make([]byte, 2000) + _, err := rand.Read(randomBytes) + require.NoError(t, err) + accountIndex := 0 + for i := 0; i < numberOfPFBs; i++ { + blob, err := share.NewBlob(share.RandomNamespace(), randomBytes, 1, accs[accountIndex].GetAddress().Bytes()) + require.NoError(t, err) + tx, _, err := signers[accountIndex].CreatePayForBlobs(accounts[accountIndex], []*share.Blob{blob}, user.SetGasLimit(2549760000), user.SetFee(10000)) + require.NoError(t, err) + pfbTxs = append(pfbTxs, tx) + accountIndex++ + } + + numberOfMsgSends := v3consts.MsgSendTransactionCap + 500 + msgSendTxs := make([][]byte, 0, numberOfMsgSends) + for i := 0; i < numberOfMsgSends; i++ { + msg := banktypes.NewMsgSend( + addrs[accountIndex], + testnode.RandomAddress().(sdk.AccAddress), + sdk.NewCoins(sdk.NewInt64Coin(appconsts.BondDenom, 10)), + ) + rawTx, err := signers[accountIndex].CreateTx([]sdk.Msg{msg}, user.SetGasLimit(1000000), user.SetFee(10)) + require.NoError(t, err) + msgSendTxs = append(msgSendTxs, rawTx) + accountIndex++ + } + + testCases := []struct { + name string + inputTransactions [][]byte + expectedTransactions [][]byte + }{ + { + name: "capping only PFB transactions", + inputTransactions: pfbTxs[:v3consts.PFBTransactionCap+50], + expectedTransactions: pfbTxs[:v3consts.PFBTransactionCap], + }, + { + name: "capping only msg send transactions", + inputTransactions: msgSendTxs[:v3consts.MsgSendTransactionCap+50], + expectedTransactions: msgSendTxs[:v3consts.MsgSendTransactionCap], + }, + { + name: "capping msg send after pfb transactions", + inputTransactions: func() [][]byte { + input := make([][]byte, 0, len(msgSendTxs)+100) + input = append(input, pfbTxs[:100]...) + input = append(input, msgSendTxs...) + return input + }(), + expectedTransactions: func() [][]byte { + expected := make([][]byte, 0, v3consts.MsgSendTransactionCap+100) + expected = append(expected, msgSendTxs[:v3consts.MsgSendTransactionCap]...) + expected = append(expected, pfbTxs[:100]...) + return expected + }(), + }, + { + name: "capping pfb after msg send transactions", + inputTransactions: func() [][]byte { + input := make([][]byte, 0, len(pfbTxs)+100) + input = append(input, msgSendTxs[:100]...) + input = append(input, pfbTxs...) + return input + }(), + expectedTransactions: func() [][]byte { + expected := make([][]byte, 0, v3consts.PFBTransactionCap+100) + expected = append(expected, msgSendTxs[:100]...) + expected = append(expected, pfbTxs[:v3consts.PFBTransactionCap]...) + return expected + }(), + }, + } + for _, testCase := range testCases { + t.Run(testCase.name, func(t *testing.T) { + resp := testApp.PrepareProposal(abci.RequestPrepareProposal{ + BlockData: &tmproto.Data{ + Txs: testCase.inputTransactions, + }, + ChainId: testApp.GetChainID(), + Height: 10, + }) + assert.Equal(t, testCase.expectedTransactions, resp.BlockData.Txs) + }) + } +} + func queryAccountInfo(capp *app.App, accs []string, kr keyring.Keyring) []blobfactory.AccountInfo { infos := make([]blobfactory.AccountInfo, len(accs)) for i, acc := range accs { diff --git a/app/validate_txs.go b/app/validate_txs.go index 3538e221a0..ac8828a045 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -1,10 +1,13 @@ package app import ( + v3consts "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" + types2 "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/x/bank/types" tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" coretypes "github.com/tendermint/tendermint/types" @@ -44,12 +47,22 @@ 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 + msgSendTransactionCount := 0 for _, tx := range txs { sdkTx, err := dec(tx) if err != nil { logger.Error("decoding already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err) continue } + msgTypes := msgTypes(sdkTx) + if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types.MsgSend{})); count != 0 { + if msgSendTransactionCount+count > v3consts.MsgSendTransactionCap { + logger.Debug("skipping tx because the msg send transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) + continue + } + msgSendTransactionCount += count + } + ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we // simply want to remove this tx, or we're catching a panic from one @@ -59,7 +72,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler "filtering already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err, - "msgs", msgTypes(sdkTx), + "msgs", msgTypes, ) telemetry.IncrCounter(1, "prepare_proposal", "invalid_std_txs") continue @@ -77,12 +90,21 @@ 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 for _, tx := range txs { sdkTx, err := dec(tx.Tx) if err != nil { logger.Error("decoding already checked blob transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()), "error", err) continue } + msgTypes := msgTypes(sdkTx) + if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types2.MsgPayForBlobs{})); count != 0 { + if pfbTransactionCount+count > v3consts.PFBTransactionCap { + logger.Debug("skipping tx because the msg pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) + continue + } + pfbTransactionCount += count + } ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we // simply want to remove this tx, or we're catching a panic from one @@ -122,3 +144,15 @@ func encodeBlobTxs(blobTxs []*tx.BlobTx) [][]byte { } return txs } + +// countOccurrence takes a strings slice and counts the number +// of time the provided item exists in that slice. +func countOccurrence(slice []string, item string) int { + count := 0 + for _, v := range slice { + if v == item { + count++ + } + } + return count +} diff --git a/pkg/appconsts/v3/app_consts.go b/pkg/appconsts/v3/app_consts.go index 3fa92f49a0..af8873f701 100644 --- a/pkg/appconsts/v3/app_consts.go +++ b/pkg/appconsts/v3/app_consts.go @@ -6,4 +6,9 @@ const ( SubtreeRootThreshold int = 64 TxSizeCostPerByte uint64 = 10 GasPerBlobByte uint32 = 8 + // MsgSendTransactionCap maximum number of msg send transactions that a block can contain + MsgSendTransactionCap = 3200 + + // PFBTransactionCap maximum number of PFB messages a block can contain + PFBTransactionCap = 2700 ) From a2469036cb1efd5199b98f41d446a5ab51bd0b31 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 4 Oct 2024 19:35:43 +0400 Subject: [PATCH 02/19] chore: fmt --- app/test/prepare_proposal_test.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 123c04adda..9aad7b51c1 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -1,7 +1,11 @@ package app_test import ( + "crypto/rand" "fmt" + "testing" + "time" + v3consts "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" @@ -9,9 +13,6 @@ import ( "github.com/cosmos/cosmos-sdk/x/auth/types" banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" "github.com/stretchr/testify/assert" - "math/rand" - "testing" - "time" tmrand "github.com/tendermint/tendermint/libs/rand" From 72194dd19b3e74ddc9ee058714519067992e69f2 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 4 Oct 2024 19:36:42 +0400 Subject: [PATCH 03/19] chore: better logs --- app/validate_txs.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/validate_txs.go b/app/validate_txs.go index ac8828a045..3651b54a28 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -100,7 +100,7 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle msgTypes := msgTypes(sdkTx) if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types2.MsgPayForBlobs{})); count != 0 { if pfbTransactionCount+count > v3consts.PFBTransactionCap { - logger.Debug("skipping tx because the msg pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) + logger.Debug("skipping tx because the pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) continue } pfbTransactionCount += count From de20c34afa1de2e581e3ef74b4808f1e57480ece Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 4 Oct 2024 20:05:23 +0400 Subject: [PATCH 04/19] chore: hacky way of setting the maxSquareSize --- app/test/prepare_proposal_test.go | 2 +- test/util/test_app.go | 35 ++++++++++++++++++++++++++++--- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 9aad7b51c1..20d9e0c609 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -226,7 +226,7 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { } consensusParams := app.DefaultConsensusParams() consensusParams.Block.MaxBytes = 128 - testApp, kr := testutil.SetupTestAppWithGenesisValSet(consensusParams, accounts...) + testApp, kr := testutil.SetupTestAppWithGenesisValSetAndMaxSquareSize(consensusParams, 128, accounts...) enc := encoding.MakeConfig(app.ModuleEncodingRegisters...) addrs := make([]sdk.AccAddress, 0, numberOfAccounts) diff --git a/test/util/test_app.go b/test/util/test_app.go index 8b4a433e9c..300d020e9d 100644 --- a/test/util/test_app.go +++ b/test/util/test_app.go @@ -4,6 +4,7 @@ import ( "encoding/json" "fmt" "os" + "strings" "testing" "time" @@ -63,7 +64,17 @@ func (ao EmptyAppOptions) Get(_ string) interface{} { // of the app from first genesis account. A no-op logger is set in app. func SetupTestAppWithGenesisValSet(cparams *tmproto.ConsensusParams, genAccounts ...string) (*app.App, keyring.Keyring) { testApp, valSet, kr := NewTestAppWithGenesisSet(cparams, genAccounts...) + initialiseTestApp(testApp, valSet, cparams) + return testApp, kr +} + +func SetupTestAppWithGenesisValSetAndMaxSquareSize(cparams *tmproto.ConsensusParams, maxSquareSize int, genAccounts ...string) (*app.App, keyring.Keyring) { + testApp, valSet, kr := NewTestAppWithGenesisSetAndMaxSquareSize(cparams, maxSquareSize, genAccounts...) + initialiseTestApp(testApp, valSet, cparams) + return testApp, kr +} +func initialiseTestApp(testApp *app.App, valSet *tmtypes.ValidatorSet, cparams *tmproto.ConsensusParams) { // commit genesis changes testApp.Commit() testApp.BeginBlock(abci.RequestBeginBlock{Header: tmproto.Header{ @@ -76,8 +87,6 @@ func SetupTestAppWithGenesisValSet(cparams *tmproto.ConsensusParams, genAccounts App: cparams.Version.AppVersion, }, }}) - - return testApp, kr } // NewTestApp creates a new app instance with an empty memDB and a no-op logger. @@ -178,7 +187,27 @@ func SetupDeterministicGenesisState(testApp *app.App, pubKeys []cryptotypes.PubK func NewTestAppWithGenesisSet(cparams *tmproto.ConsensusParams, genAccounts ...string) (*app.App, *tmtypes.ValidatorSet, keyring.Keyring) { testApp := NewTestApp() genesisState, valSet, kr := GenesisStateWithSingleValidator(testApp, genAccounts...) + testApp = InitialiseTestAppWithGenesis(testApp, cparams, genesisState) + return testApp, valSet, kr +} +// NewTestAppWithGenesisSetAndMaxSquareSize initializes a new app with genesis accounts and a specific max square size +// and returns the testApp, validator set and keyring. +func NewTestAppWithGenesisSetAndMaxSquareSize(cparams *tmproto.ConsensusParams, maxSquareSize int, genAccounts ...string) (*app.App, *tmtypes.ValidatorSet, keyring.Keyring) { + testApp := NewTestApp() + genesisState, valSet, kr := GenesisStateWithSingleValidator(testApp, genAccounts...) + + // hacky way of changing the gov max square size without changing the consts + blobJSON := string(genesisState["blob"]) + replace := strings.Replace(blobJSON, fmt.Sprintf("%d", appconsts.DefaultGovMaxSquareSize), fmt.Sprintf("%d", maxSquareSize), 1) + genesisState["blob"] = json.RawMessage(replace) + + testApp = InitialiseTestAppWithGenesis(testApp, cparams, genesisState) + return testApp, valSet, kr +} + +// InitialiseTestAppWithGenesis initializes the provided app with the provided genesis. +func InitialiseTestAppWithGenesis(testApp *app.App, cparams *tmproto.ConsensusParams, genesisState app.GenesisState) *app.App { stateBytes, err := json.MarshalIndent(genesisState, "", " ") if err != nil { panic(err) @@ -208,7 +237,7 @@ func NewTestAppWithGenesisSet(cparams *tmproto.ConsensusParams, genAccounts ...s ChainId: ChainID, }, ) - return testApp, valSet, kr + return testApp } // AddDeterministicValidatorToGenesis adds a set of five validators to the genesis. From 02b22410f5152a0f2a9d1510244a805b456f49c2 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 4 Oct 2024 20:18:36 +0400 Subject: [PATCH 05/19] chore: skip test in short mode --- app/test/prepare_proposal_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 20d9e0c609..e5704eea2f 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -215,6 +215,9 @@ func TestPrepareProposalFiltering(t *testing.T) { } func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { + if testing.Short() { + t.Skip("skipping prepare proposal capping number of transactions test in short mode.") + } // creating a big number of accounts so that every account // only creates a single transaction. This is for transactions // to be skipped without worrying about the sequence number being From 54583ae722bffa9a4c6756c17b3b00278ded1f3b Mon Sep 17 00:00:00 2001 From: sweexordious Date: Thu, 10 Oct 2024 13:21:24 +0400 Subject: [PATCH 06/19] chore: merge msg types and count occurrence --- app/validate_txs.go | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/app/validate_txs.go b/app/validate_txs.go index 3651b54a28..8e08d10dfb 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -54,8 +54,8 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler logger.Error("decoding already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err) continue } - msgTypes := msgTypes(sdkTx) - if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types.MsgSend{})); count != 0 { + msgTypes, occurrences := msgTypes(sdkTx) + if count := occurrences[sdk.MsgTypeURL(&types.MsgSend{})]; count != 0 { if msgSendTransactionCount+count > v3consts.MsgSendTransactionCap { logger.Debug("skipping tx because the msg send transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) continue @@ -97,8 +97,8 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle logger.Error("decoding already checked blob transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()), "error", err) continue } - msgTypes := msgTypes(sdkTx) - if count := countOccurrence(msgTypes, sdk.MsgTypeURL(&types2.MsgPayForBlobs{})); count != 0 { + _, occurrences := msgTypes(sdkTx) + if count := occurrences[sdk.MsgTypeURL(&types2.MsgPayForBlobs{})]; count != 0 { if pfbTransactionCount+count > v3consts.PFBTransactionCap { logger.Debug("skipping tx because the pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) continue @@ -124,13 +124,18 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle return txs[:n], ctx } -func msgTypes(sdkTx sdk.Tx) []string { +// msgTypes takes an sdk transaction and returns the types of the messages +// included in it along with. +func msgTypes(sdkTx sdk.Tx) ([]string, map[string]int) { msgs := sdkTx.GetMsgs() - msgNames := make([]string, len(msgs)) - for i, msg := range msgs { - msgNames[i] = sdk.MsgTypeURL(msg) + types := make([]string, 0, len(msgs)) + occurrences := make(map[string]int) + for _, msg := range msgs { + msgType := sdk.MsgTypeURL(msg) + types = append(types, msgType) + occurrences[msgType]++ } - return msgNames + return types, occurrences } func encodeBlobTxs(blobTxs []*tx.BlobTx) [][]byte { @@ -144,15 +149,3 @@ func encodeBlobTxs(blobTxs []*tx.BlobTx) [][]byte { } return txs } - -// countOccurrence takes a strings slice and counts the number -// of time the provided item exists in that slice. -func countOccurrence(slice []string, item string) int { - count := 0 - for _, v := range slice { - if v == item { - count++ - } - } - return count -} From ba7ae0e52a4c34566b96c5bbcc7f41762d933009 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 11 Oct 2024 11:52:29 +0400 Subject: [PATCH 07/19] chore: update the caps and use a cap for all non-pfb msgs --- app/test/prepare_proposal_test.go | 10 +++---- app/validate_txs.go | 43 ++++++++++++------------------- pkg/appconsts/v3/app_consts.go | 8 +++--- 3 files changed, 25 insertions(+), 36 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index e5704eea2f..3f62c0c34f 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -260,7 +260,7 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { accountIndex++ } - numberOfMsgSends := v3consts.MsgSendTransactionCap + 500 + numberOfMsgSends := v3consts.SdkMsgTransactionCap + 500 msgSendTxs := make([][]byte, 0, numberOfMsgSends) for i := 0; i < numberOfMsgSends; i++ { msg := banktypes.NewMsgSend( @@ -286,8 +286,8 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { }, { name: "capping only msg send transactions", - inputTransactions: msgSendTxs[:v3consts.MsgSendTransactionCap+50], - expectedTransactions: msgSendTxs[:v3consts.MsgSendTransactionCap], + inputTransactions: msgSendTxs[:v3consts.SdkMsgTransactionCap+50], + expectedTransactions: msgSendTxs[:v3consts.SdkMsgTransactionCap], }, { name: "capping msg send after pfb transactions", @@ -298,8 +298,8 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { return input }(), expectedTransactions: func() [][]byte { - expected := make([][]byte, 0, v3consts.MsgSendTransactionCap+100) - expected = append(expected, msgSendTxs[:v3consts.MsgSendTransactionCap]...) + expected := make([][]byte, 0, v3consts.SdkMsgTransactionCap+100) + expected = append(expected, msgSendTxs[:v3consts.SdkMsgTransactionCap]...) expected = append(expected, pfbTxs[:100]...) return expected }(), diff --git a/app/validate_txs.go b/app/validate_txs.go index 8e08d10dfb..ca00473154 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -2,12 +2,10 @@ package app import ( v3consts "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" - types2 "github.com/celestiaorg/celestia-app/v3/x/blob/types" "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/telemetry" sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/x/bank/types" tmbytes "github.com/tendermint/tendermint/libs/bytes" "github.com/tendermint/tendermint/libs/log" coretypes "github.com/tendermint/tendermint/types" @@ -47,21 +45,19 @@ 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 - msgSendTransactionCount := 0 + sdkTransactionsCount := 0 for _, tx := range txs { sdkTx, err := dec(tx) if err != nil { logger.Error("decoding already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err) continue } - msgTypes, occurrences := msgTypes(sdkTx) - if count := occurrences[sdk.MsgTypeURL(&types.MsgSend{})]; count != 0 { - if msgSendTransactionCount+count > v3consts.MsgSendTransactionCap { - logger.Debug("skipping tx because the msg send transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) - continue - } - msgSendTransactionCount += count + msgTypes := msgTypes(sdkTx) + if sdkTransactionsCount+len(sdkTx.GetMsgs()) > v3consts.SdkMsgTransactionCap { + logger.Debug("skipping tx because the sdk message cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) + continue } + sdkTransactionsCount += len(sdkTx.GetMsgs()) ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we @@ -97,14 +93,12 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle logger.Error("decoding already checked blob transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()), "error", err) continue } - _, occurrences := msgTypes(sdkTx) - if count := occurrences[sdk.MsgTypeURL(&types2.MsgPayForBlobs{})]; count != 0 { - if pfbTransactionCount+count > v3consts.PFBTransactionCap { - logger.Debug("skipping tx because the pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) - continue - } - pfbTransactionCount += count + if pfbTransactionCount+len(sdkTx.GetMsgs()) > v3consts.PFBTransactionCap { + logger.Debug("skipping tx because the pfb transaction cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash())) + continue } + pfbTransactionCount += len(sdkTx.GetMsgs()) + ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we // simply want to remove this tx, or we're catching a panic from one @@ -124,18 +118,13 @@ func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handle return txs[:n], ctx } -// msgTypes takes an sdk transaction and returns the types of the messages -// included in it along with. -func msgTypes(sdkTx sdk.Tx) ([]string, map[string]int) { +func msgTypes(sdkTx sdk.Tx) []string { msgs := sdkTx.GetMsgs() - types := make([]string, 0, len(msgs)) - occurrences := make(map[string]int) - for _, msg := range msgs { - msgType := sdk.MsgTypeURL(msg) - types = append(types, msgType) - occurrences[msgType]++ + msgNames := make([]string, len(msgs)) + for i, msg := range msgs { + msgNames[i] = sdk.MsgTypeURL(msg) } - return types, occurrences + return msgNames } func encodeBlobTxs(blobTxs []*tx.BlobTx) [][]byte { diff --git a/pkg/appconsts/v3/app_consts.go b/pkg/appconsts/v3/app_consts.go index af8873f701..b9fba5288d 100644 --- a/pkg/appconsts/v3/app_consts.go +++ b/pkg/appconsts/v3/app_consts.go @@ -6,9 +6,9 @@ const ( SubtreeRootThreshold int = 64 TxSizeCostPerByte uint64 = 10 GasPerBlobByte uint32 = 8 - // MsgSendTransactionCap maximum number of msg send transactions that a block can contain - MsgSendTransactionCap = 3200 + // SdkMsgTransactionCap maximum number of sdk messages, aside from PFBs, that a block can contain. + SdkMsgTransactionCap = 200 - // PFBTransactionCap maximum number of PFB messages a block can contain - PFBTransactionCap = 2700 + // PFBTransactionCap maximum number of PFB messages a block can contain. + PFBTransactionCap = 600 ) From 0a3ed233d0acdd72c4f700603283ea976b2b3e5a Mon Sep 17 00:00:00 2001 From: sweexordious Date: Fri, 11 Oct 2024 23:03:37 +0400 Subject: [PATCH 08/19] chore: merge format --- app/test/prepare_proposal_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index d9f3d3f85b..51f0bdb429 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -1,9 +1,9 @@ package app_test import ( - "strings" "crypto/rand" "fmt" + "strings" "testing" "time" @@ -27,7 +27,6 @@ import ( "github.com/celestiaorg/celestia-app/v3/app" "github.com/celestiaorg/celestia-app/v3/app/encoding" "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" - "github.com/celestiaorg/celestia-app/v3/pkg/user" testutil "github.com/celestiaorg/celestia-app/v3/test/util" "github.com/celestiaorg/celestia-app/v3/test/util/blobfactory" "github.com/celestiaorg/celestia-app/v3/test/util/testfactory" From d7605a339b37de8fb61da52e5049da22a66dd924 Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Sat, 12 Oct 2024 00:12:48 +0200 Subject: [PATCH 09/19] Update pkg/appconsts/v3/app_consts.go Co-authored-by: Rootul P --- pkg/appconsts/v3/app_consts.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/appconsts/v3/app_consts.go b/pkg/appconsts/v3/app_consts.go index 3416091e33..9259fb2f6f 100644 --- a/pkg/appconsts/v3/app_consts.go +++ b/pkg/appconsts/v3/app_consts.go @@ -7,9 +7,9 @@ const ( TxSizeCostPerByte uint64 = 10 GasPerBlobByte uint32 = 8 MaxTxSize int = 2097152 // 2 MiB in bytes - // SdkMsgTransactionCap maximum number of sdk messages, aside from PFBs, that a block can contain. + // SdkMsgTransactionCap is the maximum number of SDK messages, aside from PFBs, that a block can contain. SdkMsgTransactionCap = 200 - // PFBTransactionCap maximum number of PFB messages a block can contain. + // PFBTransactionCap is maximum number of PFB messages a block can contain. PFBTransactionCap = 600 ) From c59b82eff6d10ce6ababc65b358e4223d084ec11 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Sat, 12 Oct 2024 02:23:55 +0400 Subject: [PATCH 10/19] chore: remove unnecessary line --- app/test/prepare_proposal_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 51f0bdb429..f3558ece07 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -283,7 +283,6 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { accounts = append(accounts, fmt.Sprintf("account%d", i)) } consensusParams := app.DefaultConsensusParams() - consensusParams.Block.MaxBytes = 128 testApp, kr := testutil.SetupTestAppWithGenesisValSetAndMaxSquareSize(consensusParams, 128, accounts...) enc := encoding.MakeConfig(app.ModuleEncodingRegisters...) From 230594ffa8b81726be35c424bece9e2af5bc2443 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Sat, 12 Oct 2024 02:25:39 +0400 Subject: [PATCH 11/19] chore: use Generate accunts --- app/test/prepare_proposal_test.go | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index f3558ece07..e0601a59a6 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -2,7 +2,6 @@ package app_test import ( "crypto/rand" - "fmt" "strings" "testing" "time" @@ -278,10 +277,7 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { // to be skipped without worrying about the sequence number being // sequential. numberOfAccounts := 8000 - accounts := make([]string, 0, numberOfAccounts) - for i := 0; i < numberOfAccounts; i++ { - accounts = append(accounts, fmt.Sprintf("account%d", i)) - } + accounts := testnode.GenerateAccounts(numberOfAccounts) consensusParams := app.DefaultConsensusParams() testApp, kr := testutil.SetupTestAppWithGenesisValSetAndMaxSquareSize(consensusParams, 128, accounts...) enc := encoding.MakeConfig(app.ModuleEncodingRegisters...) From 098f7cc97ccd049ec31ba444fe6f1c2c7a4495b2 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Sat, 12 Oct 2024 11:00:14 +0400 Subject: [PATCH 12/19] chore: move the consts to app consts and comment that theyre not consensus critical --- app/test/prepare_proposal_test.go | 21 ++++++++++----------- app/validate_txs.go | 6 +++--- pkg/appconsts/global_consts.go | 9 +++++++++ pkg/appconsts/v3/app_consts.go | 5 ----- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index e0601a59a6..69df604627 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -6,7 +6,6 @@ import ( "testing" "time" - v3consts "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" sdk "github.com/cosmos/cosmos-sdk/types" @@ -295,7 +294,7 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { signers = append(signers, signer) } - numberOfPFBs := v3consts.PFBTransactionCap + 500 + numberOfPFBs := appconsts.PFBTransactionCap + 500 pfbTxs := make([][]byte, 0, numberOfPFBs) randomBytes := make([]byte, 2000) _, err := rand.Read(randomBytes) @@ -310,7 +309,7 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { accountIndex++ } - numberOfMsgSends := v3consts.SdkMsgTransactionCap + 500 + numberOfMsgSends := appconsts.SdkMsgTransactionCap + 500 msgSendTxs := make([][]byte, 0, numberOfMsgSends) for i := 0; i < numberOfMsgSends; i++ { msg := banktypes.NewMsgSend( @@ -331,13 +330,13 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { }{ { name: "capping only PFB transactions", - inputTransactions: pfbTxs[:v3consts.PFBTransactionCap+50], - expectedTransactions: pfbTxs[:v3consts.PFBTransactionCap], + inputTransactions: pfbTxs[:appconsts.PFBTransactionCap+50], + expectedTransactions: pfbTxs[:appconsts.PFBTransactionCap], }, { name: "capping only msg send transactions", - inputTransactions: msgSendTxs[:v3consts.SdkMsgTransactionCap+50], - expectedTransactions: msgSendTxs[:v3consts.SdkMsgTransactionCap], + inputTransactions: msgSendTxs[:appconsts.SdkMsgTransactionCap+50], + expectedTransactions: msgSendTxs[:appconsts.SdkMsgTransactionCap], }, { name: "capping msg send after pfb transactions", @@ -348,8 +347,8 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { return input }(), expectedTransactions: func() [][]byte { - expected := make([][]byte, 0, v3consts.SdkMsgTransactionCap+100) - expected = append(expected, msgSendTxs[:v3consts.SdkMsgTransactionCap]...) + expected := make([][]byte, 0, appconsts.SdkMsgTransactionCap+100) + expected = append(expected, msgSendTxs[:appconsts.SdkMsgTransactionCap]...) expected = append(expected, pfbTxs[:100]...) return expected }(), @@ -363,9 +362,9 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { return input }(), expectedTransactions: func() [][]byte { - expected := make([][]byte, 0, v3consts.PFBTransactionCap+100) + expected := make([][]byte, 0, appconsts.PFBTransactionCap+100) expected = append(expected, msgSendTxs[:100]...) - expected = append(expected, pfbTxs[:v3consts.PFBTransactionCap]...) + expected = append(expected, pfbTxs[:appconsts.PFBTransactionCap]...) return expected }(), }, diff --git a/app/validate_txs.go b/app/validate_txs.go index ff35109d43..6ab998187a 100644 --- a/app/validate_txs.go +++ b/app/validate_txs.go @@ -1,7 +1,7 @@ package app import ( - v3consts "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3" + "github.com/celestiaorg/celestia-app/v3/pkg/appconsts" "github.com/celestiaorg/go-square/v2/tx" "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/telemetry" @@ -57,7 +57,7 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler ctx = ctx.WithTxBytes(tx) msgTypes := msgTypes(sdkTx) - if sdkTransactionsCount+len(sdkTx.GetMsgs()) > v3consts.SdkMsgTransactionCap { + if sdkTransactionsCount+len(sdkTx.GetMsgs()) > appconsts.SdkMsgTransactionCap { 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()) > v3consts.PFBTransactionCap { + 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())) continue } diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index 2903da0414..0fd6ee2c66 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -67,3 +67,12 @@ 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 ( + // SdkMsgTransactionCap is the maximum number of SDK messages, aside from PFBs, that a block can contain. + SdkMsgTransactionCap = 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 9259fb2f6f..4b65941de1 100644 --- a/pkg/appconsts/v3/app_consts.go +++ b/pkg/appconsts/v3/app_consts.go @@ -7,9 +7,4 @@ const ( TxSizeCostPerByte uint64 = 10 GasPerBlobByte uint32 = 8 MaxTxSize int = 2097152 // 2 MiB in bytes - // SdkMsgTransactionCap is the maximum number of SDK messages, aside from PFBs, that a block can contain. - SdkMsgTransactionCap = 200 - - // PFBTransactionCap is maximum number of PFB messages a block can contain. - PFBTransactionCap = 600 ) From 4cada58b0bcbe58d3191a4a189c4dbc03e6da3aa Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 14 Oct 2024 12:25:08 +0400 Subject: [PATCH 13/19] chore: increase test race timeout to 15m --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 83c8fe3a03..708b2e286d 100644 --- a/Makefile +++ b/Makefile @@ -152,7 +152,7 @@ test-race: # TODO: Remove the -skip flag once the following tests no longer contain data races. # https://github.com/celestiaorg/celestia-app/issues/1369 @echo "--> Running tests in race mode" - @go test ./... -v -race -skip "TestPrepareProposalConsistency|TestIntegrationTestSuite|TestBlobstreamRPCQueries|TestSquareSizeIntegrationTest|TestStandardSDKIntegrationTestSuite|TestTxsimCommandFlags|TestTxsimCommandEnvVar|TestMintIntegrationTestSuite|TestBlobstreamCLI|TestUpgrade|TestMaliciousTestNode|TestBigBlobSuite|TestQGBIntegrationSuite|TestSignerTestSuite|TestPriorityTestSuite|TestTimeInPrepareProposalContext|TestBlobstream|TestCLITestSuite|TestLegacyUpgrade|TestSignerTwins|TestConcurrentTxSubmission|TestTxClientTestSuite|Test_testnode|TestEvictions" + @go test -timeout 15m ./... -v -race -skip "TestPrepareProposalConsistency|TestIntegrationTestSuite|TestBlobstreamRPCQueries|TestSquareSizeIntegrationTest|TestStandardSDKIntegrationTestSuite|TestTxsimCommandFlags|TestTxsimCommandEnvVar|TestMintIntegrationTestSuite|TestBlobstreamCLI|TestUpgrade|TestMaliciousTestNode|TestBigBlobSuite|TestQGBIntegrationSuite|TestSignerTestSuite|TestPriorityTestSuite|TestTimeInPrepareProposalContext|TestBlobstream|TestCLITestSuite|TestLegacyUpgrade|TestSignerTwins|TestConcurrentTxSubmission|TestTxClientTestSuite|Test_testnode|TestEvictions" .PHONY: test-race ## test-bench: Run unit tests in bench mode. From 5a59b882b2282460a75d539f3f3675fb8cc597be Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 14 Oct 2024 17:44:42 +0400 Subject: [PATCH 14/19] chore: rename to NonPFBTransactionCap --- app/test/prepare_proposal_test.go | 10 +++++----- app/validate_txs.go | 2 +- pkg/appconsts/global_consts.go | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 69df604627..671d6e8532 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -309,7 +309,7 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { accountIndex++ } - numberOfMsgSends := appconsts.SdkMsgTransactionCap + 500 + numberOfMsgSends := appconsts.NonPFBTransactionCap + 500 msgSendTxs := make([][]byte, 0, numberOfMsgSends) for i := 0; i < numberOfMsgSends; i++ { msg := banktypes.NewMsgSend( @@ -335,8 +335,8 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { }, { name: "capping only msg send transactions", - inputTransactions: msgSendTxs[:appconsts.SdkMsgTransactionCap+50], - expectedTransactions: msgSendTxs[:appconsts.SdkMsgTransactionCap], + inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap+50], + expectedTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap], }, { name: "capping msg send after pfb transactions", @@ -347,8 +347,8 @@ func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { return input }(), expectedTransactions: func() [][]byte { - expected := make([][]byte, 0, appconsts.SdkMsgTransactionCap+100) - expected = append(expected, msgSendTxs[:appconsts.SdkMsgTransactionCap]...) + expected := make([][]byte, 0, appconsts.NonPFBTransactionCap+100) + expected = append(expected, msgSendTxs[:appconsts.NonPFBTransactionCap]...) expected = append(expected, pfbTxs[:100]...) return expected }(), diff --git a/app/validate_txs.go b/app/validate_txs.go index 6ab998187a..1f0c5fbbf2 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 sdkTransactionsCount+len(sdkTx.GetMsgs()) > appconsts.SdkMsgTransactionCap { + if sdkTransactionsCount+len(sdkTx.GetMsgs()) > appconsts.NonPFBTransactionCap { logger.Debug("skipping tx because the sdk message cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash())) continue } diff --git a/pkg/appconsts/global_consts.go b/pkg/appconsts/global_consts.go index 0fd6ee2c66..9b87e1d6e6 100644 --- a/pkg/appconsts/global_consts.go +++ b/pkg/appconsts/global_consts.go @@ -70,8 +70,8 @@ func HashLength() int { // The following consts are not consensus breaking and will be applied straight after this binary is started. const ( - // SdkMsgTransactionCap is the maximum number of SDK messages, aside from PFBs, that a block can contain. - SdkMsgTransactionCap = 200 + // 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 From b04ab8116774e3da1b8a56e363fe6662ad63015c Mon Sep 17 00:00:00 2001 From: CHAMI Rachid Date: Mon, 14 Oct 2024 17:32:34 +0200 Subject: [PATCH 15/19] Update app/test/prepare_proposal_test.go Co-authored-by: Rootul P --- app/test/prepare_proposal_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 671d6e8532..bf226ce676 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -267,7 +267,7 @@ func TestPrepareProposalFiltering(t *testing.T) { } } -func TestPrepareProposalCappingNumberOfTransactions(t *testing.T) { +func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { if testing.Short() { t.Skip("skipping prepare proposal capping number of transactions test in short mode.") } From 01e4cb4cf6c75a4567a9c88c609e32c0bcebd6c5 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 14 Oct 2024 19:33:42 +0400 Subject: [PATCH 16/19] chore: rename to NonPFBTransactionCap --- app/validate_txs.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/validate_txs.go b/app/validate_txs.go index 1f0c5fbbf2..7ff37a8fbb 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 - sdkTransactionsCount := 0 + nonPFBTransactionsCount := 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 sdkTransactionsCount+len(sdkTx.GetMsgs()) > appconsts.NonPFBTransactionCap { + 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())) continue } - sdkTransactionsCount += len(sdkTx.GetMsgs()) + nonPFBTransactionsCount += len(sdkTx.GetMsgs()) ctx, err = handler(ctx, sdkTx, false) // either the transaction is invalid (ie incorrect nonce) and we From c5071a3a3aaa8eea231492f1398123492b195508 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 14 Oct 2024 22:38:40 +0400 Subject: [PATCH 17/19] chore: add the multiple messages per transaction test --- app/test/prepare_proposal_test.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index bf226ce676..dcf051346a 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -2,6 +2,8 @@ package app_test import ( "crypto/rand" + blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" + blobtx "github.com/celestiaorg/go-square/v2/tx" "strings" "testing" "time" @@ -309,6 +311,26 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { accountIndex++ } + multiPFBsPerTxs := make([][]byte, 0, numberOfPFBs) + numberOfMsgsPerTx := 10 + for i := 0; i < numberOfPFBs; i++ { + msgs := make([]sdk.Msg, 0) + blobs := make([]*share.Blob, 0) + for j := 0; j < numberOfMsgsPerTx; j++ { + blob, err := share.NewBlob(share.RandomNamespace(), randomBytes, 1, accs[accountIndex].GetAddress().Bytes()) + require.NoError(t, err) + msg, err := blobtypes.NewMsgPayForBlobs(addrs[accountIndex].String(), appconsts.LatestVersion, blob) + msgs = append(msgs, msg) + blobs = append(blobs, blob) + } + txBytes, err := signers[accountIndex].CreateTx(msgs, user.SetGasLimit(2549760000), user.SetFee(10000)) + require.NoError(t, err) + blobTx, err := blobtx.MarshalBlobTx(txBytes, blobs...) + require.NoError(t, err) + multiPFBsPerTxs = append(multiPFBsPerTxs, blobTx) + accountIndex++ + } + numberOfMsgSends := appconsts.NonPFBTransactionCap + 500 msgSendTxs := make([][]byte, 0, numberOfMsgSends) for i := 0; i < numberOfMsgSends; i++ { @@ -333,6 +355,11 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { inputTransactions: pfbTxs[:appconsts.PFBTransactionCap+50], expectedTransactions: pfbTxs[:appconsts.PFBTransactionCap], }, + { + name: "capping only PFB transactions with multiple messages", + inputTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap], + expectedTransactions: multiPFBsPerTxs[:appconsts.PFBTransactionCap/numberOfMsgsPerTx], + }, { name: "capping only msg send transactions", inputTransactions: msgSendTxs[:appconsts.NonPFBTransactionCap+50], From ca7e28213b2c90e0a9d7bbcb31fd85010f048819 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 14 Oct 2024 22:44:09 +0400 Subject: [PATCH 18/19] chore: fmt --- app/test/prepare_proposal_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index dcf051346a..07a8483c72 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -2,12 +2,13 @@ package app_test import ( "crypto/rand" - blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" - blobtx "github.com/celestiaorg/go-square/v2/tx" "strings" "testing" "time" + blobtypes "github.com/celestiaorg/celestia-app/v3/x/blob/types" + blobtx "github.com/celestiaorg/go-square/v2/tx" + "github.com/celestiaorg/celestia-app/v3/pkg/user" "github.com/celestiaorg/celestia-app/v3/test/util/testnode" sdk "github.com/cosmos/cosmos-sdk/types" From 98ecf6df513d29d28be6c3daf4808564b22a0c47 Mon Sep 17 00:00:00 2001 From: sweexordious Date: Mon, 14 Oct 2024 22:56:55 +0400 Subject: [PATCH 19/19] chore: fmt --- app/test/prepare_proposal_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/app/test/prepare_proposal_test.go b/app/test/prepare_proposal_test.go index 07a8483c72..e0c963de8f 100644 --- a/app/test/prepare_proposal_test.go +++ b/app/test/prepare_proposal_test.go @@ -321,6 +321,7 @@ func TestPrepareProposalCappingNumberOfMessages(t *testing.T) { blob, err := share.NewBlob(share.RandomNamespace(), randomBytes, 1, accs[accountIndex].GetAddress().Bytes()) require.NoError(t, err) msg, err := blobtypes.NewMsgPayForBlobs(addrs[accountIndex].String(), appconsts.LatestVersion, blob) + require.NoError(t, err) msgs = append(msgs, msg) blobs = append(blobs, blob) }