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

refactor: rename limits from tx to msg #3984

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
24 changes: 12 additions & 12 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand All @@ -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",
Expand All @@ -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
}(),
Expand All @@ -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
}(),
},
Expand Down
16 changes: 8 additions & 8 deletions app/validate_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand Down
12 changes: 7 additions & 5 deletions pkg/appconsts/global_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Loading