Skip to content

Commit

Permalink
Merge branch 'main' into rp/fix-version
Browse files Browse the repository at this point in the history
  • Loading branch information
rootulp authored Oct 15, 2024
2 parents 35be682 + b1f43f5 commit 0aad2de
Show file tree
Hide file tree
Showing 32 changed files with 746 additions and 178 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,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.
Expand Down
2 changes: 2 additions & 0 deletions app/ante/ante.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ func NewAnteHandler(
// Set up the context with a gas meter.
// Must be called before gas consumption occurs in any other decorator.
ante.NewSetUpContextDecorator(),
// Ensure the tx is not larger than the configured threshold.
NewMaxTxSizeDecorator(),
// Ensure the tx does not contain any extension options.
ante.NewExtensionOptionsDecorator(nil),
// Ensure the tx passes ValidateBasic.
Expand Down
33 changes: 33 additions & 0 deletions app/ante/max_tx_size.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package ante

import (
"fmt"

"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// MaxTxSizeDecorator ensures that a tx can not be larger than
// application's configured versioned constant.
type MaxTxSizeDecorator struct{}

func NewMaxTxSizeDecorator() MaxTxSizeDecorator {
return MaxTxSizeDecorator{}
}

// AnteHandle implements the AnteHandler interface. It ensures that tx size is under application's configured threshold.
func (d MaxTxSizeDecorator) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (sdk.Context, error) {
// Tx size rule applies to app versions v3 and onwards.
if ctx.BlockHeader().Version.App < v3.Version {
return next(ctx, tx, simulate)
}

currentTxSize := len(ctx.TxBytes())
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)
}
78 changes: 78 additions & 0 deletions app/ante/max_tx_size_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package ante_test

import (
"testing"

"github.com/celestiaorg/celestia-app/v3/app/ante"
v2 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v2"
v3 "github.com/celestiaorg/celestia-app/v3/pkg/appconsts/v3"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/stretchr/testify/require"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
version "github.com/tendermint/tendermint/proto/tendermint/version"
)

func TestMaxTxSizeDecorator(t *testing.T) {
decorator := ante.NewMaxTxSizeDecorator()
anteHandler := sdk.ChainAnteDecorators(decorator)

testCases := []struct {
name string
txSize int
expectError bool
appVersion uint64
isCheckTx []bool
}{
{
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 size threshold",
txSize: v3.MaxTxSize + 1,
appVersion: v3.Version,
expectError: true,
isCheckTx: []bool{true, false},
},
{
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.MaxTxSize + 10,
appVersion: v2.Version,
expectError: false,
isCheckTx: []bool{true, false},
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
for _, isCheckTx := range tc.isCheckTx {

ctx := sdk.NewContext(nil, tmproto.Header{
Version: version.Consensus{
App: tc.appVersion,
},
}, isCheckTx, nil)

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)
}
}
})
}
}
File renamed without changes.
File renamed without changes.
9 changes: 9 additions & 0 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package app_test

import (
"encoding/json"
"os"
"path/filepath"
"testing"

Expand Down Expand Up @@ -160,7 +161,15 @@ func createTestApp(t *testing.T) *app.App {
config := encoding.MakeConfig(app.ModuleEncodingRegisters...)
upgradeHeight := int64(3)
snapshotDir := filepath.Join(t.TempDir(), "data", "snapshots")
t.Cleanup(func() {
err := os.RemoveAll(snapshotDir)
require.NoError(t, err)
})
snapshotDB, err := tmdb.NewDB("metadata", tmdb.GoLevelDBBackend, snapshotDir)
t.Cleanup(func() {
err := snapshotDB.Close()
require.NoError(t, err)
})
require.NoError(t, err)
snapshotStore, err := snapshots.NewStore(snapshotDB, snapshotDir)
require.NoError(t, err)
Expand Down
15 changes: 4 additions & 11 deletions app/default_overrides.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/celestiaorg/celestia-app/v3/pkg/appconsts"
"github.com/celestiaorg/celestia-app/v3/x/mint"
minttypes "github.com/celestiaorg/celestia-app/v3/x/mint/types"
"github.com/celestiaorg/go-square/v2/share"
"github.com/cosmos/cosmos-sdk/codec"
serverconfig "github.com/cosmos/cosmos-sdk/server/config"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand Down Expand Up @@ -259,19 +258,13 @@ func DefaultEvidenceParams() tmproto.EvidenceParams {
func DefaultConsensusConfig() *tmcfg.Config {
cfg := tmcfg.DefaultConfig()
// Set broadcast timeout to be 50 seconds in order to avoid timeouts for long block times
// TODO: make TimeoutBroadcastTx configurable per https://github.com/celestiaorg/celestia-app/issues/1034
cfg.RPC.TimeoutBroadcastTxCommit = 50 * time.Second
cfg.RPC.MaxBodyBytes = int64(8388608) // 8 MiB

cfg.Mempool.TTLNumBlocks = 5
cfg.Mempool.TTLDuration = time.Duration(cfg.Mempool.TTLNumBlocks) * appconsts.GoalBlockTime
// Given that there is a stateful transaction size check in CheckTx,
// We set a loose upper bound on what we expect the transaction to
// be based on the upper bound size of the entire block for the given
// version. This acts as a first line of DoS protection
upperBoundBytes := appconsts.DefaultSquareSizeUpperBound * appconsts.DefaultSquareSizeUpperBound * share.ContinuationSparseShareContentSize
cfg.Mempool.MaxTxBytes = upperBoundBytes
cfg.Mempool.MaxTxsBytes = int64(upperBoundBytes) * cfg.Mempool.TTLNumBlocks
cfg.Mempool.TTLNumBlocks = 12
cfg.Mempool.TTLDuration = 75 * time.Second
cfg.Mempool.MaxTxBytes = 7_897_088
cfg.Mempool.MaxTxsBytes = 39_485_440
cfg.Mempool.Version = "v1" // prioritized mempool

cfg.Consensus.TimeoutPropose = appconsts.TimeoutPropose
Expand Down
4 changes: 2 additions & 2 deletions app/default_overrides_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ func TestDefaultConsensusConfig(t *testing.T) {
Size: tmcfg.DefaultMempoolConfig().Size,
WalPath: tmcfg.DefaultMempoolConfig().WalPath,

// overrides
// Overrides
MaxTxBytes: 7_897_088,
MaxTxsBytes: 39_485_440,
TTLDuration: 75 * time.Second,
TTLNumBlocks: 5,
TTLNumBlocks: 12,
Version: "v1",
}
assert.Equal(t, want, *got.Mempool)
Expand Down
8 changes: 8 additions & 0 deletions app/process_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ func (app *App) ProcessProposal(req abci.RequestProcessProposal) (resp abci.Resp
tx = blobTx.Tx
}

// todo: uncomment once we're sure this isn't consensus breaking
// sdkCtx = sdkCtx.WithTxBytes(tx)

sdkTx, err := app.txConfig.TxDecoder()(tx)
// Set the tx bytes in the context for app version v3 and greater
if sdkCtx.BlockHeader().Version.App >= 3 {
sdkCtx = sdkCtx.WithTxBytes(tx)
}

if err != nil {
if req.Header.Version.App == v1 {
// For appVersion 1, there was no block validity rule that all
Expand Down
Loading

0 comments on commit 0aad2de

Please sign in to comment.