diff --git a/beacon/engine/gen_ed.go b/beacon/engine/gen_ed.go index 36a1791352..0ae5a3b8f1 100644 --- a/beacon/engine/gen_ed.go +++ b/beacon/engine/gen_ed.go @@ -10,7 +10,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/types/bal" ) var _ = (*executableDataMarshaling)(nil) @@ -35,7 +34,6 @@ func (e ExecutableData) MarshalJSON() ([]byte, error) { Withdrawals []*types.Withdrawal `json:"withdrawals"` BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"` - BlockAccessList *bal.BlockAccessList `json:"blockAccessList"` ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"` } var enc ExecutableData @@ -61,7 +59,6 @@ func (e ExecutableData) MarshalJSON() ([]byte, error) { enc.Withdrawals = e.Withdrawals enc.BlobGasUsed = (*hexutil.Uint64)(e.BlobGasUsed) enc.ExcessBlobGas = (*hexutil.Uint64)(e.ExcessBlobGas) - enc.BlockAccessList = e.BlockAccessList enc.ExecutionWitness = e.ExecutionWitness return json.Marshal(&enc) } @@ -86,7 +83,6 @@ func (e *ExecutableData) UnmarshalJSON(input []byte) error { Withdrawals []*types.Withdrawal `json:"withdrawals"` BlobGasUsed *hexutil.Uint64 `json:"blobGasUsed"` ExcessBlobGas *hexutil.Uint64 `json:"excessBlobGas"` - BlockAccessList *bal.BlockAccessList `json:"blockAccessList"` ExecutionWitness *types.ExecutionWitness `json:"executionWitness,omitempty"` } var dec ExecutableData @@ -161,9 +157,6 @@ func (e *ExecutableData) UnmarshalJSON(input []byte) error { if dec.ExcessBlobGas != nil { e.ExcessBlobGas = (*uint64)(dec.ExcessBlobGas) } - if dec.BlockAccessList != nil { - e.BlockAccessList = dec.BlockAccessList - } if dec.ExecutionWitness != nil { e.ExecutionWitness = dec.ExecutionWitness } diff --git a/core/genesis.go b/core/genesis.go index 2fd044c70a..932410cdfd 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -67,12 +67,13 @@ type Genesis struct { // These fields are used for consensus tests. Please don't use them // in actual genesis blocks. - Number uint64 `json:"number"` - GasUsed uint64 `json:"gasUsed"` - ParentHash common.Hash `json:"parentHash"` - BaseFee *big.Int `json:"baseFeePerGas"` // EIP-1559 - ExcessBlobGas *uint64 `json:"excessBlobGas"` // EIP-4844 - BlobGasUsed *uint64 `json:"blobGasUsed"` // EIP-4844 + Number uint64 `json:"number"` + GasUsed uint64 `json:"gasUsed"` + ParentHash common.Hash `json:"parentHash"` + BaseFee *big.Int `json:"baseFeePerGas"` // EIP-1559 + ExcessBlobGas *uint64 `json:"excessBlobGas"` // EIP-4844 + BlobGasUsed *uint64 `json:"blobGasUsed"` // EIP-4844 + BlockAccessListHash *common.Hash `json:"blockAccessListHash,omitempty"` // EIP-7928 } // copy copies the genesis. @@ -122,6 +123,7 @@ func ReadGenesis(db ethdb.Database) (*Genesis, error) { genesis.BaseFee = genesisHeader.BaseFee genesis.ExcessBlobGas = genesisHeader.ExcessBlobGas genesis.BlobGasUsed = genesisHeader.BlobGasUsed + genesis.BlockAccessListHash = genesisHeader.BlockAccessListHash return &genesis, nil } @@ -469,18 +471,19 @@ func (g *Genesis) ToBlock() *types.Block { // toBlockWithRoot constructs the genesis block with the given genesis state root. func (g *Genesis) toBlockWithRoot(root common.Hash) *types.Block { head := &types.Header{ - Number: new(big.Int).SetUint64(g.Number), - Nonce: types.EncodeNonce(g.Nonce), - Time: g.Timestamp, - ParentHash: g.ParentHash, - Extra: g.ExtraData, - GasLimit: g.GasLimit, - GasUsed: g.GasUsed, - BaseFee: g.BaseFee, - Difficulty: g.Difficulty, - MixDigest: g.Mixhash, - Coinbase: g.Coinbase, - Root: root, + Number: new(big.Int).SetUint64(g.Number), + Nonce: types.EncodeNonce(g.Nonce), + Time: g.Timestamp, + ParentHash: g.ParentHash, + Extra: g.ExtraData, + GasLimit: g.GasLimit, + GasUsed: g.GasUsed, + BaseFee: g.BaseFee, + Difficulty: g.Difficulty, + MixDigest: g.Mixhash, + Coinbase: g.Coinbase, + BlockAccessListHash: g.BlockAccessListHash, + Root: root, } if g.GasLimit == 0 { head.GasLimit = params.GenesisGasLimit diff --git a/miner/worker.go b/miner/worker.go index c0574eac23..26f2b55bf2 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -162,7 +162,7 @@ func (miner *Miner) generateWork(genParam *generateParams, witness bool) *newPay work.header.RequestsHash = &reqHash } - block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts) + block, err := miner.engine.FinalizeAndAssemble(miner.chain, work.header, work.state, &body, work.receipts, nil) if err != nil { return &newPayloadResult{err: err} } diff --git a/tests/block_test.go b/tests/block_test.go index 9bc77b4c90..c718b304b6 100644 --- a/tests/block_test.go +++ b/tests/block_test.go @@ -18,7 +18,6 @@ package tests import ( "math/rand" - "path/filepath" "testing" "github.com/ethereum/go-ethereum/common" @@ -68,119 +67,13 @@ func TestBlockchain(t *testing.T) { bt.skipLoad(`.*\.meta/.*`) bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) { - execBlockTest(t, bt, test, false) + execBlockTest(t, bt, test) }) // There is also a LegacyTests folder, containing blockchain tests generated // prior to Istanbul. However, they are all derived from GeneralStateTests, // which run natively, so there's no reason to run them here. } -func TestBlockchainBAL(t *testing.T) { - bt := new(testMatcher) - - // We are running most of GeneralStatetests to tests witness support, even - // though they are ran as state tests too. Still, the performance tests are - // less about state andmore about EVM number crunching, so skip those. - bt.skipLoad(`^GeneralStateTests/VMTests/vmPerformance`) - - // Skip random failures due to selfish mining test - bt.skipLoad(`.*bcForgedTest/bcForkUncle\.json`) - - // Slow tests - bt.slow(`.*bcExploitTest/DelegateCallSpam.json`) - bt.slow(`.*bcExploitTest/ShanghaiLove.json`) - bt.slow(`.*bcExploitTest/SuicideIssue.json`) - bt.slow(`.*/bcForkStressTest/`) - bt.slow(`.*/bcGasPricerTest/RPC_API_Test.json`) - bt.slow(`.*/bcWalletTest/`) - - // Very slow test - bt.skipLoad(`.*/stTimeConsuming/.*`) - // test takes a lot for time and goes easily OOM because of sha3 calculation on a huge range, - // using 4.6 TGas - bt.skipLoad(`.*randomStatetest94.json.*`) - - // After the merge we would accept side chains as canonical even if they have lower td - bt.skipLoad(`.*bcMultiChainTest/ChainAtoChainB_difficultyB.json`) - bt.skipLoad(`.*bcMultiChainTest/CallContractFromNotBestBlock.json`) - bt.skipLoad(`.*bcTotalDifficultyTest/uncleBlockAtBlock3afterBlock4.json`) - bt.skipLoad(`.*bcTotalDifficultyTest/lotsOfBranchesOverrideAtTheMiddle.json`) - bt.skipLoad(`.*bcTotalDifficultyTest/sideChainWithMoreTransactions.json`) - bt.skipLoad(`.*bcForkStressTest/ForkStressTest.json`) - bt.skipLoad(`.*bcMultiChainTest/lotsOfLeafs.json`) - bt.skipLoad(`.*bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain.json`) - bt.skipLoad(`.*bcFrontierToHomestead/blockChainFrontierWithLargerTDvsHomesteadBlockchain2.json`) - - // With chain history removal, TDs become unavailable, this transition tests based on TTD are unrunnable - bt.skipLoad(`.*bcArrowGlacierToParis/powToPosBlockRejection.json`) - - // This directory contains no test. - bt.skipLoad(`.*\.meta/.*`) - - bt.walk(t, blockTestDir, func(t *testing.T, name string, test *BlockTest) { - config, ok := Forks[test.json.Network] - if !ok { - t.Fatalf("unsupported fork: %s\n", test.json.Network) - } - gspec := test.genesis(config) - // skip any tests which are not past the cancun fork (selfdestruct removal) - if gspec.Config.CancunTime == nil || *gspec.Config.CancunTime != 0 { - return - } - execBlockTest(t, bt, test, true) - }) - // There is also a LegacyTests folder, containing blockchain tests generated - // prior to Istanbul. However, they are all derived from GeneralStateTests, - // which run natively, so there's no reason to run them here. -} - -// TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests. -// TODO: rename this to reflect that it tests creating/verifying BALs on pre-amsterdam tests -func TestExecutionSpecBlocktestsBAL(t *testing.T) { - if !common.FileExist(executionSpecBlockchainTestDir) { - t.Skipf("directory %s does not exist", executionSpecBlockchainTestDir) - } - bt := new(testMatcher) - - bt.skipLoad(".*prague/eip7251_consolidations/contract_deployment/system_contract_deployment.json") - bt.skipLoad(".*prague/eip7002_el_triggerable_withdrawals/contract_deployment/system_contract_deployment.json") - - bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) { - config, ok := Forks[test.json.Network] - if !ok { - t.Fatalf("unsupported fork: %s\n", test.json.Network) - } - gspec := test.genesis(config) - // skip any tests which are not past the cancun fork (selfdestruct removal) - if gspec.Config.CancunTime == nil || *gspec.Config.CancunTime != 0 { - return - } - execBlockTest(t, bt, test, true) - }) -} - -func TestExecutionSpecBlocktestsAmsterdam(t *testing.T) { - var executionSpecAmsterdamBlockchainTestDir = filepath.Join(".", "fixtures-amsterdam-bal", "blockchain_tests") - if !common.FileExist(executionSpecAmsterdamBlockchainTestDir) { - t.Skipf("directory %s does not exist", executionSpecAmsterdamBlockchainTestDir) - } - bt := new(testMatcher) - - bt.walk(t, executionSpecAmsterdamBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) { - config, ok := Forks[test.json.Network] - if !ok { - t.Fatalf("unsupported fork: %s\n", test.json.Network) - } - gspec := test.genesis(config) - // skip any tests which are not past the cancun fork (selfdestruct removal) - if gspec.Config.CancunTime == nil || *gspec.Config.CancunTime != 0 { - return - } - // TODO: skip any tests that aren't amsterdam - execBlockTest(t, bt, test, false) - }) -} - // TestExecutionSpecBlocktests runs the test fixtures from execution-spec-tests. func TestExecutionSpecBlocktests(t *testing.T) { if !common.FileExist(executionSpecBlockchainTestDir) { @@ -193,11 +86,11 @@ func TestExecutionSpecBlocktests(t *testing.T) { bt.skipLoad(".*prague/eip7002_el_triggerable_withdrawals/test_system_contract_deployment.json") bt.walk(t, executionSpecBlockchainTestDir, func(t *testing.T, name string, test *BlockTest) { - execBlockTest(t, bt, test, false) + execBlockTest(t, bt, test) }) } -func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest, buildAndVerifyBAL bool) { +func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest) { // Define all the different flag combinations we should run the tests with, // picking only one for short tests. // @@ -211,11 +104,9 @@ func execBlockTest(t *testing.T, bt *testMatcher, test *BlockTest, buildAndVerif snapshotConf = []bool{snapshotConf[rand.Int()%2]} dbschemeConf = []string{dbschemeConf[rand.Int()%2]} } - for _, snapshot := range snapshotConf { for _, dbscheme := range dbschemeConf { - //tracer := logger.NewJSONLogger(&logger.Config{}, os.Stdout) - if err := bt.checkFailure(t, test.Run(snapshot, dbscheme, false, buildAndVerifyBAL, nil, nil)); err != nil { + if err := bt.checkFailure(t, test.Run(snapshot, dbscheme, true, nil, nil)); err != nil { t.Errorf("test with config {snapshotter:%v, scheme:%v} failed: %v", snapshot, dbscheme, err) return } diff --git a/tests/block_test_util.go b/tests/block_test_util.go index eb912a5f21..3b88753b1c 100644 --- a/tests/block_test_util.go +++ b/tests/block_test_util.go @@ -22,7 +22,6 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/ethereum/go-ethereum/core/types/bal" stdmath "math" "math/big" "os" @@ -72,7 +71,6 @@ type btBlock struct { ExpectException string Rlp string UncleHeaders []*btHeader - AccessList *bal.BlockAccessList `json:"blockAccessList,omitempty"` } //go:generate go run github.com/fjl/gencodec -type btHeader -field-override btHeaderMarshaling -out gen_btheader.go @@ -99,7 +97,6 @@ type btHeader struct { BlobGasUsed *uint64 ExcessBlobGas *uint64 ParentBeaconBlockRoot *common.Hash - BlockAccessListHash *common.Hash } type btHeaderMarshaling struct { @@ -114,7 +111,11 @@ type btHeaderMarshaling struct { ExcessBlobGas *math.HexOrDecimal64 } -func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter bool, scheme string, witness, createAndVerifyBAL bool, tracer *tracing.Hooks) (*core.BlockChain, error) { +func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, tracer *tracing.Hooks, postCheck func(error, *core.BlockChain)) (result error) { + config, ok := Forks[t.json.Network] + if !ok { + return UnsupportedForkError{t.json.Network} + } // import pre accounts & construct test genesis block & state root var ( db = rawdb.NewMemoryDatabase() @@ -127,6 +128,7 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter } else { tconf.HashDB = hashdb.Defaults } + // Commit genesis state gspec := t.genesis(config) // if ttd is not specified, set an arbitrary huge value @@ -136,15 +138,15 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter triedb := triedb.NewDatabase(db, tconf) gblock, err := gspec.Commit(db, triedb) if err != nil { - return nil, err + return err } triedb.Close() // close the db to prevent memory leak if gblock.Hash() != t.json.Genesis.Hash { - return nil, fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6]) + return fmt.Errorf("genesis block hash doesn't match test: computed=%x, test=%x", gblock.Hash().Bytes()[:6], t.json.Genesis.Hash[:6]) } if gblock.Root() != t.json.Genesis.StateRoot { - return nil, fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.Root().Bytes()[:6], t.json.Genesis.StateRoot[:6]) + return fmt.Errorf("genesis block state root does not match test: computed=%x, test=%x", gblock.Root().Bytes()[:6], t.json.Genesis.StateRoot[:6]) } // Wrap the original engine within the beacon-engine engine := beacon.New(ethash.NewFaker()) @@ -158,28 +160,12 @@ func (t *BlockTest) createTestBlockChain(config *params.ChainConfig, snapshotter Tracer: tracer, StatelessSelfValidation: witness, }, - NoPrefetch: true, - EnableBALForTesting: createAndVerifyBAL, } if snapshotter { options.SnapshotLimit = 1 options.SnapshotWait = true } chain, err := core.NewBlockChain(db, gspec, engine, options) - if err != nil { - return nil, err - } - return chain, nil -} - -func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, createAndVerifyBAL bool, tracer *tracing.Hooks, postCheck func(error, *core.BlockChain)) (result error) { - config, ok := Forks[t.json.Network] - if !ok { - return UnsupportedForkError{t.json.Network} - } - // import pre accounts & construct test genesis block & state root - - chain, err := t.createTestBlockChain(config, snapshotter, scheme, witness, createAndVerifyBAL, tracer) if err != nil { return err } @@ -213,69 +199,25 @@ func (t *BlockTest) Run(snapshotter bool, scheme string, witness bool, createAnd } } } - err = t.validateImportedHeaders(chain, validBlocks) - if err != nil { - return err - } - - if createAndVerifyBAL { - newChain, _ := t.createTestBlockChain(config, snapshotter, scheme, witness, createAndVerifyBAL, tracer) - defer newChain.Stop() - - var blocksWithBAL types.Blocks - for i := uint64(1); i <= chain.CurrentBlock().Number.Uint64(); i++ { - block := chain.GetBlockByNumber(i) - if block.Body().AccessList == nil { - return fmt.Errorf("block %d missing BAL", block.NumberU64()) - } - blocksWithBAL = append(blocksWithBAL, block) - } - - amt, err := newChain.InsertChain(blocksWithBAL) - if err != nil { - return err - } - _ = amt - newDB, err := newChain.State() - if err != nil { - return err - } - if err = t.validatePostState(newDB); err != nil { - return fmt.Errorf("post state validation failed: %v", err) - } - // Cross-check the snapshot-to-hash against the trie hash - if snapshotter { - if newChain.Snapshots() != nil { - if err := chain.Snapshots().Verify(chain.CurrentBlock().Root); err != nil { - return err - } - } - } - err = t.validateImportedHeaders(newChain, validBlocks) - if err != nil { - return err - } - } - return nil + return t.validateImportedHeaders(chain, validBlocks) } func (t *BlockTest) genesis(config *params.ChainConfig) *core.Genesis { return &core.Genesis{ - Config: config, - Nonce: t.json.Genesis.Nonce.Uint64(), - Timestamp: t.json.Genesis.Timestamp, - ParentHash: t.json.Genesis.ParentHash, - ExtraData: t.json.Genesis.ExtraData, - GasLimit: t.json.Genesis.GasLimit, - GasUsed: t.json.Genesis.GasUsed, - Difficulty: t.json.Genesis.Difficulty, - Mixhash: t.json.Genesis.MixHash, - Coinbase: t.json.Genesis.Coinbase, - Alloc: t.json.Pre, - BaseFee: t.json.Genesis.BaseFeePerGas, - BlobGasUsed: t.json.Genesis.BlobGasUsed, - ExcessBlobGas: t.json.Genesis.ExcessBlobGas, - BlockAccessListHash: t.json.Genesis.BlockAccessListHash, + Config: config, + Nonce: t.json.Genesis.Nonce.Uint64(), + Timestamp: t.json.Genesis.Timestamp, + ParentHash: t.json.Genesis.ParentHash, + ExtraData: t.json.Genesis.ExtraData, + GasLimit: t.json.Genesis.GasLimit, + GasUsed: t.json.Genesis.GasUsed, + Difficulty: t.json.Genesis.Difficulty, + Mixhash: t.json.Genesis.MixHash, + Coinbase: t.json.Genesis.Coinbase, + Alloc: t.json.Pre, + BaseFee: t.json.Genesis.BaseFeePerGas, + BlobGasUsed: t.json.Genesis.BlobGasUsed, + ExcessBlobGas: t.json.Genesis.ExcessBlobGas, } }