diff --git a/consensus/beacon/faker.go b/consensus/beacon/faker.go deleted file mode 100644 index 981e345e3e..0000000000 --- a/consensus/beacon/faker.go +++ /dev/null @@ -1,41 +0,0 @@ -// Copyright 2023 The go-ethereum Authors -// This file is part of the go-ethereum library. -// -// The go-ethereum library is free software: you can redistribute it and/or modify -// it under the terms of the GNU Lesser General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// The go-ethereum library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public License -// along with the go-ethereum library. If not, see . - -package beacon - -import ( - "math/big" - - "github.com/ethereum/go-ethereum/consensus" - "github.com/ethereum/go-ethereum/core/types" -) - -// NewFaker creates a fake consensus engine for testing. -// The fake engine simulates a merged network. -// It can not be used to test the merge transition. -// This type is needed since the fakeChainReader can not be used with -// a normal beacon consensus engine. -func NewFaker() consensus.Engine { - return new(faker) -} - -type faker struct { - Beacon -} - -func (f *faker) CalcDifficulty(chain consensus.ChainHeaderReader, time uint64, parent *types.Header) *big.Int { - return beaconDifficulty -} diff --git a/core/blockchain_test.go b/core/blockchain_test.go index d9ff7140c0..3063d6cf05 100644 --- a/core/blockchain_test.go +++ b/core/blockchain_test.go @@ -3987,7 +3987,7 @@ func TestEIP3651(t *testing.T) { var ( aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa") bb = common.HexToAddress("0x000000000000000000000000000000000000bbbb") - engine = beacon.NewFaker() + engine = beacon.New(ethash.NewFaker()) // A sender who makes transactions, has some funds key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") @@ -4103,7 +4103,7 @@ func TestPragueRequests(t *testing.T) { addr1 = crypto.PubkeyToAddress(key1.PublicKey) config = *params.MergedTestChainConfig signer = types.LatestSigner(&config) - engine = beacon.NewFaker() + engine = beacon.New(ethash.NewFaker()) ) gspec := &Genesis{ Config: &config, diff --git a/core/chain_makers_test.go b/core/chain_makers_test.go index f72e6285df..cb1087b4b3 100644 --- a/core/chain_makers_test.go +++ b/core/chain_makers_test.go @@ -80,8 +80,9 @@ func TestGeneratePOSChain(t *testing.T) { Code: common.Hex2Bytes("600154600354"), } genesis := gspec.MustCommit(gendb, triedb.NewDatabase(gendb, triedb.HashDefaults)) + engine := beacon.New(ethash.NewFaker()) - genchain, genreceipts := GenerateChain(gspec.Config, genesis, beacon.NewFaker(), gendb, 4, func(i int, gen *BlockGen) { + genchain, genreceipts := GenerateChain(gspec.Config, genesis, engine, gendb, 4, func(i int, gen *BlockGen) { gen.SetParentBeaconRoot(common.Hash{byte(i + 1)}) // Add value transfer tx. @@ -122,7 +123,7 @@ func TestGeneratePOSChain(t *testing.T) { }) // Import the chain. This runs all block validation rules. - blockchain, _ := NewBlockChain(db, nil, gspec, nil, beacon.NewFaker(), vm.Config{}, nil) + blockchain, _ := NewBlockChain(db, nil, gspec, nil, engine, vm.Config{}, nil) defer blockchain.Stop() if i, err := blockchain.InsertChain(genchain); err != nil { diff --git a/eth/catalyst/api_test.go b/eth/catalyst/api_test.go index 0bff95a065..4698827731 100644 --- a/eth/catalyst/api_test.go +++ b/eth/catalyst/api_test.go @@ -32,8 +32,7 @@ import ( "github.com/ethereum/go-ethereum/beacon/engine" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" - "github.com/ethereum/go-ethereum/consensus" - beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon" + "github.com/ethereum/go-ethereum/consensus/beacon" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -62,12 +61,11 @@ var ( func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) { config := *params.AllEthashProtocolChanges - engine := consensus.Engine(beaconConsensus.New(ethash.NewFaker())) + engine := beacon.New(ethash.NewFaker()) if merged { config.TerminalTotalDifficulty = common.Big0 - engine = beaconConsensus.NewFaker() } else { - engine.(*beaconConsensus.Beacon).TestingTTDBlock(uint64(n)) + engine.TestingTTDBlock(uint64(n)) } genesis := &core.Genesis{ Config: &config, diff --git a/eth/protocols/eth/handler_test.go b/eth/protocols/eth/handler_test.go index d0509f2f3d..5b35a2f935 100644 --- a/eth/protocols/eth/handler_test.go +++ b/eth/protocols/eth/handler_test.go @@ -25,7 +25,6 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/beacon" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" @@ -71,12 +70,13 @@ func newTestBackend(blocks int) *testBackend { func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int, *core.BlockGen)) *testBackend { var ( // Create a database pre-initialize with a genesis block - db = rawdb.NewMemoryDatabase() - config = params.TestChainConfig - engine consensus.Engine = ethash.NewFaker() + db = rawdb.NewMemoryDatabase() + config = params.TestChainConfig + engine = beacon.New(ethash.NewFaker()) ) - - if shanghai { + if !shanghai { + engine.TestingTTDBlock(math.MaxUint64) + } else { config = ¶ms.ChainConfig{ ChainID: big.NewInt(1), HomesteadBlock: big.NewInt(0), @@ -99,7 +99,6 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int, TerminalTotalDifficulty: big.NewInt(0), Ethash: new(params.EthashConfig), } - engine = beacon.NewFaker() } gspec := &core.Genesis{ diff --git a/eth/tracers/api_test.go b/eth/tracers/api_test.go index 13a7b0aaae..95e7739be0 100644 --- a/eth/tracers/api_test.go +++ b/eth/tracers/api_test.go @@ -1089,7 +1089,7 @@ func TestTraceChain(t *testing.T) { func newTestMergedBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i int, b *core.BlockGen)) *testBackend { backend := &testBackend{ chainConfig: gspec.Config, - engine: beacon.NewFaker(), + engine: beacon.New(ethash.NewFaker()), chaindb: rawdb.NewMemoryDatabase(), } // Generate blocks for testing diff --git a/graphql/graphql_test.go b/graphql/graphql_test.go index 231170c273..3e6a042dbb 100644 --- a/graphql/graphql_test.go +++ b/graphql/graphql_test.go @@ -29,7 +29,6 @@ import ( "time" "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/consensus/beacon" "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/core" @@ -457,9 +456,8 @@ func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Ge RPCGasCap: 1000000, StateScheme: rawdb.HashScheme, } - var engine consensus.Engine = ethash.NewFaker() + var engine = beacon.New(ethash.NewFaker()) if shanghai { - engine = beacon.NewFaker() gspec.Config.TerminalTotalDifficulty = common.Big0 // GenerateChain will increment timestamps by 10. // Shanghai upgrade at block 1. @@ -468,6 +466,7 @@ func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Ge } else { // set an arbitrary large ttd as chains are required to be known to be merged gspec.Config.TerminalTotalDifficulty = big.NewInt(math.MaxInt64) + engine.TestingTTDBlock(math.MaxUint64) } ethBackend, err := eth.New(stack, ethConf) if err != nil {