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

feat: limit the number of messages in prepare proposal #3942

Merged
merged 26 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
097a126
feat: limit the number of msg send and PFBs in prepare proposal
rach-id Oct 4, 2024
a246903
chore: fmt
rach-id Oct 4, 2024
72194dd
chore: better logs
rach-id Oct 4, 2024
de20c34
chore: hacky way of setting the maxSquareSize
rach-id Oct 4, 2024
02b2241
chore: skip test in short mode
rach-id Oct 4, 2024
54583ae
chore: merge msg types and count occurrence
rach-id Oct 10, 2024
ba7ae0e
chore: update the caps and use a cap for all non-pfb msgs
rach-id Oct 11, 2024
4c98037
Merge branch 'main' into limit-number-of-transactions-in-prepare-prop…
rach-id Oct 11, 2024
0a3ed23
chore: merge format
rach-id Oct 11, 2024
d7605a3
Update pkg/appconsts/v3/app_consts.go
rach-id Oct 11, 2024
c59b82e
chore: remove unnecessary line
rach-id Oct 11, 2024
f3b3061
Merge remote-tracking branch 'origin/limit-number-of-transactions-in-…
rach-id Oct 11, 2024
230594f
chore: use Generate accunts
rach-id Oct 11, 2024
098f7cc
chore: move the consts to app consts and comment that theyre not cons…
rach-id Oct 12, 2024
1b48571
Merge branch 'main' into limit-number-of-transactions-in-prepare-prop…
rach-id Oct 14, 2024
4cada58
chore: increase test race timeout to 15m
rach-id Oct 14, 2024
5a59b88
chore: rename to NonPFBTransactionCap
rach-id Oct 14, 2024
b04ab81
Update app/test/prepare_proposal_test.go
rach-id Oct 14, 2024
01e4cb4
chore: rename to NonPFBTransactionCap
rach-id Oct 14, 2024
0fdc0ab
Merge remote-tracking branch 'origin/limit-number-of-transactions-in-…
rach-id Oct 14, 2024
415bcaa
Merge branch 'main' into limit-number-of-transactions-in-prepare-prop…
ninabarbakadze Oct 14, 2024
c5071a3
chore: add the multiple messages per transaction test
rach-id Oct 14, 2024
ba58bb8
Merge remote-tracking branch 'origin/limit-number-of-transactions-in-…
rach-id Oct 14, 2024
ca7e282
chore: fmt
rach-id Oct 14, 2024
98ecf6d
chore: fmt
rach-id Oct 14, 2024
384ccfe
Merge branch 'main' into limit-number-of-transactions-in-prepare-prop…
rach-id Oct 14, 2024
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
Prev Previous commit
Next Next commit
chore: update the caps and use a cap for all non-pfb msgs
  • Loading branch information
rach-id committed Oct 11, 2024
commit ba7ae0e52a4c34566b96c5bbcc7f41762d933009
10 changes: 5 additions & 5 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -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
}(),
Expand Down
43 changes: 16 additions & 27 deletions app/validate_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
rach-id marked this conversation as resolved.
Show resolved Hide resolved
if sdkTransactionsCount+len(sdkTx.GetMsgs()) > v3consts.SdkMsgTransactionCap {
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
logger.Debug("skipping tx because the sdk message cap was reached", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()))
continue
}
sdkTransactionsCount += len(sdkTx.GetMsgs())
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved

ctx, err = handler(ctx, sdkTx, false)
// either the transaction is invalid (ie incorrect nonce) and we
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions pkg/appconsts/v3/app_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Loading