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: cap tx size flups #3967

Merged
merged 2 commits into from
Oct 11, 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
8 changes: 4 additions & 4 deletions app/ante/max_tx_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ func (d MaxTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool
}

currentTxSize := len(ctx.TxBytes())
maxTxBytes := appconsts.MaxTxBytes(ctx.BlockHeader().Version.App)
if currentTxSize > maxTxBytes {
bytesOverLimit := currentTxSize - maxTxBytes
return ctx, fmt.Errorf("tx size %d bytes is larger than the application's configured threshold of %d bytes. Please reduce the size by %d bytes", currentTxSize, maxTxBytes, bytesOverLimit)
maxTxSize := appconsts.MaxTxSize(ctx.BlockHeader().Version.App)
if currentTxSize > maxTxSize {
bytesOverLimit := currentTxSize - maxTxSize
return ctx, fmt.Errorf("tx size %d bytes is larger than the application's configured threshold of %d bytes. Please reduce the size by %d bytes", currentTxSize, maxTxSize, bytesOverLimit)
}
return next(ctx, tx, simulate)
}
14 changes: 7 additions & 7 deletions app/ante/max_tx_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,29 @@ func TestMaxTxSizeDecorator(t *testing.T) {
isCheckTx []bool
}{
{
name: "good tx; under max tx bytes threshold",
txSize: v3.MaxTxBytes - 1,
name: "good tx; under max tx size threshold",
txSize: v3.MaxTxSize - 1,
appVersion: v3.Version,
expectError: false,
isCheckTx: []bool{true, false},
},
{
name: "bad tx; over max tx bytes threshold",
txSize: v3.MaxTxBytes + 1,
name: "bad tx; over max tx size threshold",
txSize: v3.MaxTxSize + 1,
appVersion: v3.Version,
expectError: true,
isCheckTx: []bool{true, false},
},
{
name: "good tx; equal to max tx bytes threshold",
txSize: v3.MaxTxBytes,
name: "good tx; equal to max tx size threshold",
txSize: v3.MaxTxSize,
appVersion: v3.Version,
expectError: false,
isCheckTx: []bool{true, false},
},
{
name: "good tx; limit only applies to v3 and above",
txSize: v3.MaxTxBytes + 10,
txSize: v3.MaxTxSize + 10,
appVersion: v2.Version,
expectError: false,
isCheckTx: []bool{true, false},
Expand Down
8 changes: 4 additions & 4 deletions app/test/prepare_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ func TestPrepareProposalFiltering(t *testing.T) {
// memo is 2 MiB resulting in the transaction being over limit
largeString := strings.Repeat("a", 2*1024*1024)

// 3 transactions over MaxTxBytes limit
// 3 transactions over MaxTxSize limit
largeTxs := coretypes.Txs(testutil.SendTxsWithAccounts(t, testApp, encConf.TxConfig, kr, 1000, accounts[0], accounts[:3], testutil.ChainID, user.SetMemo(largeString))).ToSliceOfBytes()

// 3 blobTxs over MaxTxBytes limit
// 3 blobTxs over MaxTxSize limit
largeBlobTxs := blobfactory.ManyMultiBlobTx(
t,
encConf.TxConfig,
Expand Down Expand Up @@ -231,9 +231,9 @@ func TestPrepareProposalFiltering(t *testing.T) {
prunedTxs: [][]byte{tooManyShareBtx},
},
{
name: "blobTxs and sendTxs that exceed MaxTxBytes limit",
name: "blobTxs and sendTxs that exceed MaxTxSize limit",
txs: func() [][]byte {
return append(largeTxs, largeBlobTxs...) // All txs are over MaxTxBytes limit
return append(largeTxs, largeBlobTxs...) // All txs are over MaxTxSize limit
},
prunedTxs: append(largeTxs, largeBlobTxs...),
},
Expand Down
10 changes: 5 additions & 5 deletions app/test/process_proposal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ func TestProcessProposal(t *testing.T) {
blobfactory.DefaultTxOpts()...,
)

largeMemo := strings.Repeat("a", appconsts.MaxTxBytes(appconsts.LatestVersion))
largeMemo := strings.Repeat("a", appconsts.MaxTxSize(appconsts.LatestVersion))

// create 2 single blobTxs that include a large memo making the transaction
// larger than the configured max tx bytes
// larger than the configured max tx size
largeBlobTxs := blobfactory.ManyMultiBlobTx(
t, enc, kr, testutil.ChainID, accounts[3:], infos[3:],
blobfactory.NestedBlobs(
Expand All @@ -68,7 +68,7 @@ func TestProcessProposal(t *testing.T) {
user.SetMemo(largeMemo))

// create 1 large sendTx that includes a large memo making the
// transaction over the configured max tx bytes limit
// transaction over the configured max tx size limit
largeSendTx := testutil.SendTxsWithAccounts(
t, testApp, enc, kr, 1000, accounts[0], accounts[1:2], testutil.ChainID, user.SetMemo(largeMemo),
)
Expand Down Expand Up @@ -349,7 +349,7 @@ func TestProcessProposal(t *testing.T) {
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "blob txs larger than configured max tx bytes",
name: "blob txs larger than configured max tx size",
input: validData(),
mutator: func(d *tmproto.Data) {
d.Txs = append(d.Txs, largeBlobTxs...)
Expand All @@ -359,7 +359,7 @@ func TestProcessProposal(t *testing.T) {
expectedResult: abci.ResponseProcessProposal_REJECT,
},
{
name: "send tx larger than configured max tx bytes",
name: "send tx larger than configured max tx size",
input: validData(),
mutator: func(d *tmproto.Data) {
d.Txs = append(coretypes.Txs(largeSendTx).ToSliceOfBytes(), d.Txs...)
Expand Down
2 changes: 0 additions & 2 deletions app/validate_txs.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ func FilterTxs(logger log.Logger, ctx sdk.Context, handler sdk.AnteHandler, txCo
func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs [][]byte) ([][]byte, sdk.Context) {
n := 0
for _, tx := range txs {
ctx = ctx.WithTxBytes(tx)
sdkTx, err := dec(tx)
if err != nil {
logger.Error("decoding already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err)
Expand Down Expand Up @@ -83,7 +82,6 @@ func filterStdTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler
func filterBlobTxs(logger log.Logger, dec sdk.TxDecoder, ctx sdk.Context, handler sdk.AnteHandler, txs []*tx.BlobTx) ([]*tx.BlobTx, sdk.Context) {
n := 0
for _, tx := range txs {
ctx = ctx.WithTxBytes(tx.Tx)
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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/appconsts/v3/app_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ const (
SubtreeRootThreshold int = 64
TxSizeCostPerByte uint64 = 10
GasPerBlobByte uint32 = 8
MaxTxBytes int = 2097152 // 2 MiB in bytes
MaxTxSize int = 2097152 // 2 MiB in bytes
)
4 changes: 2 additions & 2 deletions pkg/appconsts/versioned_consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ func GasPerBlobByte(_ uint64) uint32 {
return v3.GasPerBlobByte
}

func MaxTxBytes(_ uint64) int {
return v3.MaxTxBytes
func MaxTxSize(_ uint64) int {
return v3.MaxTxSize
}

var (
Expand Down
6 changes: 3 additions & 3 deletions pkg/appconsts/versioned_consts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ func TestVersionedConsts(t *testing.T) {
got: appconsts.GasPerBlobByte(v3.Version),
},
{
name: "MaxTxBytes v3",
name: "MaxTxSize v3",
version: v3.Version,
expectedConstant: v3.MaxTxBytes,
got: appconsts.MaxTxBytes(v3.Version),
expectedConstant: v3.MaxTxSize,
got: appconsts.MaxTxSize(v3.Version),
},
}

Expand Down
2 changes: 1 addition & 1 deletion specs/src/ante_handler_v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The AnteHandler chains together several decorators to ensure the following criteria are met for app version 3:

- The tx does not contain any messages that are unsupported by the current app version. See `MsgVersioningGateKeeper`.
- The tx size is not larger than the application's configured versioned constant MaxTxBytes.
- The tx size is not larger than the application's configured versioned constant MaxTxSize.
- The tx does not contain any [extension options](https://github.com/cosmos/cosmos-sdk/blob/22c28366466e64ebf0df1ce5bec8b1130523552c/proto/cosmos/tx/v1beta1/tx.proto#L119-L122).
- The tx passes `ValidateBasic()`.
- The tx's [timeout_height](https://github.com/cosmos/cosmos-sdk/blob/22c28366466e64ebf0df1ce5bec8b1130523552c/proto/cosmos/tx/v1beta1/tx.proto#L115-L117) has not been reached if one is specified.
Expand Down
Loading