Skip to content

Commit 86965f8

Browse files
authored
feat(tx-pool): fast reject transactions that cannot fit into a block (#1042)
* feat(tx pool): fast reject transactions that cannot fit into a block * add a TestValidateTxBlockSize unit test * chore: auto version bump [bot] --------- Co-authored-by: colinlyguo <colinlyguo@users.noreply.github.com>
1 parent 89639dd commit 86965f8

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

core/tx_pool.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
705705
if uint64(tx.Size()) > txMaxSize {
706706
return ErrOversizedData
707707
}
708+
// Reject transactions that cannot fit into a block even as a single transaction
709+
if !pool.chainconfig.Scroll.IsValidBlockSize(tx.Size()) {
710+
return ErrOversizedData
711+
}
708712
// Check whether the init code size has been exceeded.
709713
if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
710714
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)

core/tx_pool_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2677,3 +2677,32 @@ func TestStatsWithMinBaseFee(t *testing.T) {
26772677
}
26782678
}
26792679
}
2680+
2681+
func TestValidateTxBlockSize(t *testing.T) {
2682+
pool, key := setupTxPoolWithConfig(params.ScrollMainnetChainConfig)
2683+
defer pool.Stop()
2684+
2685+
account := crypto.PubkeyToAddress(key.PublicKey)
2686+
testAddBalance(pool, account, big.NewInt(1000000000000000000))
2687+
2688+
validTx := pricedDataTransaction(1, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock)-128)
2689+
oversizedTx := pricedDataTransaction(2, 2100000, big.NewInt(1), key, uint64(*pool.chainconfig.Scroll.MaxTxPayloadBytesPerBlock))
2690+
2691+
tests := []struct {
2692+
name string
2693+
tx *types.Transaction
2694+
want error
2695+
}{
2696+
{"Valid transaction", validTx, nil},
2697+
{"Oversized transaction", oversizedTx, ErrOversizedData},
2698+
}
2699+
2700+
for _, tt := range tests {
2701+
t.Run(tt.name, func(t *testing.T) {
2702+
err := pool.validateTx(tt.tx, false)
2703+
if err != tt.want {
2704+
t.Errorf("validateTx() error = %v, want %v", err, tt.want)
2705+
}
2706+
})
2707+
}
2708+
}

params/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
const (
2525
VersionMajor = 5 // Major version component of the current release
2626
VersionMinor = 7 // Minor version component of the current release
27-
VersionPatch = 16 // Patch version component of the current release
27+
VersionPatch = 17 // Patch version component of the current release
2828
VersionMeta = "mainnet" // Version metadata to append to the version string
2929
)
3030

0 commit comments

Comments
 (0)