mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
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>
This commit is contained in:
parent
89639dd74a
commit
86965f8a48
3 changed files with 34 additions and 1 deletions
|
|
@ -705,6 +705,10 @@ func (pool *TxPool) validateTx(tx *types.Transaction, local bool) error {
|
||||||
if uint64(tx.Size()) > txMaxSize {
|
if uint64(tx.Size()) > txMaxSize {
|
||||||
return ErrOversizedData
|
return ErrOversizedData
|
||||||
}
|
}
|
||||||
|
// Reject transactions that cannot fit into a block even as a single transaction
|
||||||
|
if !pool.chainconfig.Scroll.IsValidBlockSize(tx.Size()) {
|
||||||
|
return ErrOversizedData
|
||||||
|
}
|
||||||
// Check whether the init code size has been exceeded.
|
// Check whether the init code size has been exceeded.
|
||||||
if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
|
if pool.shanghai && tx.To() == nil && len(tx.Data()) > params.MaxInitCodeSize {
|
||||||
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
|
return fmt.Errorf("%w: code size %v limit %v", ErrMaxInitCodeSizeExceeded, len(tx.Data()), params.MaxInitCodeSize)
|
||||||
|
|
|
||||||
|
|
@ -2677,3 +2677,32 @@ func TestStatsWithMinBaseFee(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestValidateTxBlockSize(t *testing.T) {
|
||||||
|
pool, key := setupTxPoolWithConfig(params.ScrollMainnetChainConfig)
|
||||||
|
defer pool.Stop()
|
||||||
|
|
||||||
|
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, ErrOversizedData},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := pool.validateTx(tt.tx, false)
|
||||||
|
if err != tt.want {
|
||||||
|
t.Errorf("validateTx() error = %v, want %v", err, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ import (
|
||||||
const (
|
const (
|
||||||
VersionMajor = 5 // Major version component of the current release
|
VersionMajor = 5 // Major version component of the current release
|
||||||
VersionMinor = 7 // Minor version component of the current release
|
VersionMinor = 7 // Minor version component of the current release
|
||||||
VersionPatch = 16 // Patch version component of the current release
|
VersionPatch = 17 // Patch version component of the current release
|
||||||
VersionMeta = "mainnet" // Version metadata to append to the version string
|
VersionMeta = "mainnet" // Version metadata to append to the version string
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue