Skip to content

Commit

Permalink
feat(tx-pool): fast reject transactions that cannot fit into a block
Browse files Browse the repository at this point in the history
  • Loading branch information
0xmountaintop committed Oct 9, 2024
1 parent 00ba80c commit a89d09a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
31 changes: 31 additions & 0 deletions core/txpool/legacypool/legacypool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
})
}
}
4 changes: 4 additions & 0 deletions core/txpool/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit a89d09a

Please sign in to comment.