mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
feat(block-validation): remove block size and tx count checks (#1215)
* feat(block-validation): remove block size and tx count checks * remove tests
This commit is contained in:
parent
c0d89415da
commit
cc9a1dd82d
3 changed files with 1 additions and 137 deletions
|
|
@ -70,13 +70,6 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
|
||||||
if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
|
if v.bc.HasBlockAndState(block.Hash(), block.NumberU64()) {
|
||||||
return ErrKnownBlock
|
return ErrKnownBlock
|
||||||
}
|
}
|
||||||
if !v.config.Scroll.IsValidTxCount(len(block.Transactions())) {
|
|
||||||
return consensus.ErrInvalidTxCount
|
|
||||||
}
|
|
||||||
// Check if block payload size is smaller than the max size
|
|
||||||
if !v.config.Scroll.IsValidBlockSize(block.PayloadSize()) {
|
|
||||||
return ErrInvalidBlockPayloadSize
|
|
||||||
}
|
|
||||||
// Header validity is known at this point, check the uncles and transactions
|
// Header validity is known at this point, check the uncles and transactions
|
||||||
header := block.Header()
|
header := block.Header()
|
||||||
if err := v.engine.VerifyUncles(v.bc, block); err != nil {
|
if err := v.engine.VerifyUncles(v.bc, block); err != nil {
|
||||||
|
|
@ -127,7 +120,6 @@ func (v *BlockValidator) ValidateL1Messages(block *types.Block) error {
|
||||||
blockHash := block.Hash()
|
blockHash := block.Hash()
|
||||||
|
|
||||||
if v.config.Scroll.L1Config == nil {
|
if v.config.Scroll.L1Config == nil {
|
||||||
// TODO: should we allow follower nodes to skip L1 message verification?
|
|
||||||
panic("Running on L1Message-enabled network but no l1Config was provided")
|
panic("Running on L1Message-enabled network but no l1Config was provided")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -204,7 +196,6 @@ func (v *BlockValidator) ValidateL1Messages(block *types.Block) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// skipped messages
|
// skipped messages
|
||||||
// TODO: consider verifying that skipped messages overflow
|
|
||||||
for index := queueIndex; index < txQueueIndex; index++ {
|
for index := queueIndex; index < txQueueIndex; index++ {
|
||||||
if exists := it.Next(); !exists {
|
if exists := it.Next(); !exists {
|
||||||
if err := it.Error(); err != nil {
|
if err := it.Error(); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -3186,70 +3186,6 @@ func TestFeeVault(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestTransactionCountLimit tests that the chain reject blocks with too many transactions.
|
|
||||||
func TestTransactionCountLimit(t *testing.T) {
|
|
||||||
// Create config that allows at most 1 transaction per block
|
|
||||||
config := params.TestChainConfig
|
|
||||||
config.Scroll.MaxTxPerBlock = new(int)
|
|
||||||
*config.Scroll.MaxTxPerBlock = 1
|
|
||||||
defer func() {
|
|
||||||
config.Scroll.MaxTxPerBlock = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
engine = ethash.NewFaker()
|
|
||||||
db = rawdb.NewMemoryDatabase()
|
|
||||||
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
||||||
address = crypto.PubkeyToAddress(key.PublicKey)
|
|
||||||
funds = big.NewInt(1000000000000000)
|
|
||||||
gspec = &Genesis{Config: config, Alloc: GenesisAlloc{address: {Balance: funds}}}
|
|
||||||
genesis = gspec.MustCommit(db)
|
|
||||||
)
|
|
||||||
|
|
||||||
addTx := func(b *BlockGen) {
|
|
||||||
tx := types.NewTransaction(b.TxNonce(address), address, big.NewInt(0), 50000, b.header.BaseFee, nil)
|
|
||||||
signed, _ := types.SignTx(tx, types.HomesteadSigner{}, key)
|
|
||||||
b.AddTx(signed)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize blockchain
|
|
||||||
blockchain, err := NewBlockChain(db, nil, config, engine, vm.Config{}, nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create new chain manager: %v", err)
|
|
||||||
}
|
|
||||||
defer blockchain.Stop()
|
|
||||||
|
|
||||||
// Insert empty block
|
|
||||||
block1, _ := GenerateChain(config, genesis, ethash.NewFaker(), db, 1, func(i int, b *BlockGen) {
|
|
||||||
// empty
|
|
||||||
})
|
|
||||||
|
|
||||||
if _, err := blockchain.InsertChain(block1); err != nil {
|
|
||||||
t.Fatalf("failed to insert chain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert block with 1 transaction
|
|
||||||
block2, _ := GenerateChain(config, genesis, ethash.NewFaker(), db, 1, func(i int, b *BlockGen) {
|
|
||||||
addTx(b)
|
|
||||||
})
|
|
||||||
|
|
||||||
if _, err := blockchain.InsertChain(block2); err != nil {
|
|
||||||
t.Fatalf("failed to insert chain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert block with 2 transactions
|
|
||||||
block3, _ := GenerateChain(config, genesis, ethash.NewFaker(), db, 1, func(i int, b *BlockGen) {
|
|
||||||
addTx(b)
|
|
||||||
addTx(b)
|
|
||||||
})
|
|
||||||
|
|
||||||
_, err = blockchain.InsertChain(block3)
|
|
||||||
|
|
||||||
if !errors.Is(err, consensus.ErrInvalidTxCount) {
|
|
||||||
t.Fatalf("error mismatch: have: %v, want: %v", err, consensus.ErrInvalidTxCount)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestInsertBlocksWithL1Messages tests that the chain accepts blocks with L1MessageTx transactions.
|
// TestInsertBlocksWithL1Messages tests that the chain accepts blocks with L1MessageTx transactions.
|
||||||
func TestInsertBlocksWithL1Messages(t *testing.T) {
|
func TestInsertBlocksWithL1Messages(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
|
|
@ -3443,69 +3379,6 @@ func TestL1MessageValidationFailure(t *testing.T) {
|
||||||
assert.Equal(t, uint64(4), *queueIndex)
|
assert.Equal(t, uint64(4), *queueIndex)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBlockPayloadSizeLimit(t *testing.T) {
|
|
||||||
// Create config that allows at most 150 bytes per block payload
|
|
||||||
config := params.TestChainConfig
|
|
||||||
config.Scroll.MaxTxPayloadBytesPerBlock = new(int)
|
|
||||||
*config.Scroll.MaxTxPayloadBytesPerBlock = 150
|
|
||||||
defer func() {
|
|
||||||
config.Scroll.MaxTxPayloadBytesPerBlock = nil
|
|
||||||
}()
|
|
||||||
|
|
||||||
var (
|
|
||||||
engine = ethash.NewFaker()
|
|
||||||
db = rawdb.NewMemoryDatabase()
|
|
||||||
key, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
|
||||||
address = crypto.PubkeyToAddress(key.PublicKey)
|
|
||||||
funds = big.NewInt(1000000000000000)
|
|
||||||
gspec = &Genesis{Config: config, Alloc: GenesisAlloc{address: {Balance: funds}}}
|
|
||||||
genesis = gspec.MustCommit(db)
|
|
||||||
)
|
|
||||||
|
|
||||||
addTx := func(b *BlockGen) {
|
|
||||||
tx := types.NewTransaction(b.TxNonce(address), address, big.NewInt(0), 50000, b.header.BaseFee, nil)
|
|
||||||
signed, _ := types.SignTx(tx, types.HomesteadSigner{}, key)
|
|
||||||
b.AddTx(signed)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initialize blockchain
|
|
||||||
blockchain, err := NewBlockChain(db, nil, config, engine, vm.Config{}, nil, nil)
|
|
||||||
if err != nil {
|
|
||||||
t.Fatalf("failed to create new chain manager: %v", err)
|
|
||||||
}
|
|
||||||
defer blockchain.Stop()
|
|
||||||
|
|
||||||
// Insert empty block
|
|
||||||
block1, _ := GenerateChain(config, genesis, ethash.NewFaker(), db, 1, func(i int, b *BlockGen) {
|
|
||||||
// empty
|
|
||||||
})
|
|
||||||
|
|
||||||
if _, err := blockchain.InsertChain(block1); err != nil {
|
|
||||||
t.Fatalf("failed to insert chain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert block with 1 transaction
|
|
||||||
block2, _ := GenerateChain(config, genesis, ethash.NewFaker(), db, 1, func(i int, b *BlockGen) {
|
|
||||||
addTx(b)
|
|
||||||
})
|
|
||||||
|
|
||||||
if _, err := blockchain.InsertChain(block2); err != nil {
|
|
||||||
t.Fatalf("failed to insert chain: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert block with 2 transactions
|
|
||||||
block3, _ := GenerateChain(config, genesis, ethash.NewFaker(), db, 1, func(i int, b *BlockGen) {
|
|
||||||
addTx(b)
|
|
||||||
addTx(b)
|
|
||||||
})
|
|
||||||
|
|
||||||
_, err = blockchain.InsertChain(block3)
|
|
||||||
|
|
||||||
if !errors.Is(err, ErrInvalidBlockPayloadSize) {
|
|
||||||
t.Fatalf("error mismatch: have: %v, want: %v", err, ErrInvalidBlockPayloadSize)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEIP3651(t *testing.T) {
|
func TestEIP3651(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
addraa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
|
addraa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
|
||||||
|
|
|
||||||
|
|
@ -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 = 8 // Minor version component of the current release
|
VersionMinor = 8 // Minor version component of the current release
|
||||||
VersionPatch = 58 // Patch version component of the current release
|
VersionPatch = 59 // 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