diff --git a/core/txpool/legacypool/legacypool_test.go b/core/txpool/legacypool/legacypool_test.go index 04d58ddd1c3b..edad39fc4657 100644 --- a/core/txpool/legacypool/legacypool_test.go +++ b/core/txpool/legacypool/legacypool_test.go @@ -2730,3 +2730,34 @@ func TestStatsWithMinBaseFee(t *testing.T) { } } } + +func TestValidateTxBlockSize(t *testing.T) { + // Create the pool to test the pricing enforcement with + pool, _ := setupPoolWithConfig(params.ScrollMainnetChainConfig) + defer pool.Close() + + key, _ := crypto.GenerateKey() + account := crypto.PubkeyToAddress(key.PublicKey) + testAddBalance(pool, account, big.NewInt(1000000000000000000)) + + validTx := pricedDataTransaction(1, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)-128) + oversizedTx := pricedDataTransaction(2, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)) + + tests := []struct { + name string + tx *types.Transaction + want error + }{ + {"Valid transaction", validTx, nil}, + {"Oversized transaction", oversizedTx, txpool.ErrOversizedData}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + err := pool.validateTxBasics(tt.tx, false) + if err != tt.want { + t.Errorf("validateTx() error = %v, want %v", err, tt.want) + } + }) + } +} diff --git a/core/txpool/validation.go b/core/txpool/validation.go index 3b09ee3ec154..17a6f39bbcaf 100644 --- a/core/txpool/validation.go +++ b/core/txpool/validation.go @@ -57,6 +57,10 @@ func ValidateTransaction(tx *types.Transaction, head *types.Header, signer types if tx.Size() > opts.MaxSize { return fmt.Errorf("%w: transaction size %v, limit %v", ErrOversizedData, tx.Size(), opts.MaxSize) } + // Reject transactions that cannot fit into a block even as a single transaction + if !opts.Config.Scroll.IsValidBlockSize(tx.Size()) { + return ErrOversizedData + } // Ensure only transactions that have been enabled are accepted if !opts.Config.IsCurie(head.Number) && tx.Type() != types.LegacyTxType { return fmt.Errorf("%w: type %d rejected, pool not yet in Curie", core.ErrTxTypeNotSupported, tx.Type())