Skip to content

Commit

Permalink
fix: version gate in process proposal
Browse files Browse the repository at this point in the history
  • Loading branch information
ninabarbakadze committed Oct 10, 2024
1 parent 12dfb01 commit 54b2b4d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
6 changes: 4 additions & 2 deletions app/ante/max_tx_size.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@ func (d MaxTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool
return next(ctx, tx, simulate)
}

currentTxSize := len(ctx.TxBytes())
maxTxBytes := appconsts.MaxTxBytes(ctx.BlockHeader().Version.App)
if len(ctx.TxBytes()) > maxTxBytes {
return ctx, fmt.Errorf("tx size is larger than the application's configured threshold: %d bytes", maxTxBytes)
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)
}
return next(ctx, tx, simulate)
}
33 changes: 20 additions & 13 deletions app/ante/max_tx_size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,50 +21,57 @@ func TestMaxTxSizeDecorator(t *testing.T) {
txSize int
expectError bool
appVersion uint64
isCheckTx []bool
}{
{
name: "good tx; under max tx bytes threshold",
txSize: v3.MaxTxBytes - 1,
appVersion: v3.Version,
expectError: false,
isCheckTx: []bool{true, false},
},
{
name: "bad tx; over max tx bytes threshold",
txSize: v3.MaxTxBytes + 1,
appVersion: v3.Version,
expectError: true,
isCheckTx: []bool{true, false},
},
{
name: "good tx; equal to max tx bytes threshold",
txSize: v3.MaxTxBytes,
appVersion: v3.Version,
expectError: false,
isCheckTx: []bool{true, false},
},
{
name: "good tx; limit only applies to v3 and above",
txSize: v3.MaxTxBytes + 10,
appVersion: v2.Version,
expectError: false,
isCheckTx: []bool{true, false},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
ctx := sdk.NewContext(nil, tmproto.Header{
Version: version.Consensus{
App: tc.appVersion,
},
}, false, nil)
for _, isCheckTx := range tc.isCheckTx {

txBytes := make([]byte, tc.txSize)
ctx := sdk.NewContext(nil, tmproto.Header{
Version: version.Consensus{
App: tc.appVersion,
},
}, isCheckTx, nil)

ctx = ctx.WithTxBytes(txBytes)
_, err := anteHandler(ctx, nil, false)
if tc.expectError {
require.Error(t, err)
require.Contains(t, err.Error(), "tx size is larger than the application's configured threshold")
} else {
require.NoError(t, err)
txBytes := make([]byte, tc.txSize)

ctx = ctx.WithTxBytes(txBytes)
_, err := anteHandler(ctx, nil, false)
if tc.expectError {
require.Error(t, err)
} else {
require.NoError(t, err)
}
}
})
}
Expand Down
6 changes: 4 additions & 2 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,10 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
return reject()
}

// Set the tx size on the context before calling the AnteHandler
sdkCtx = sdkCtx.WithTxBytes(tx)
// set the tx bytes in the context for app version v3 and greater
if sdkCtx.BlockHeader().Version.App >= 3 {
sdkCtx = sdkCtx.WithTxBytes(tx)
}

// validated the PFB signature
sdkCtx, err = handler(sdkCtx, sdkTx, false)
Expand Down

0 comments on commit 54b2b4d

Please sign in to comment.