mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 17:33:47 +00:00
all: get rid of beacon.faker test consensus type
This commit is contained in:
parent
125b68a797
commit
27766d0a99
7 changed files with 17 additions and 61 deletions
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
@ -3987,7 +3987,7 @@ func TestEIP3651(t *testing.T) {
|
||||||
var (
|
var (
|
||||||
aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
|
aa = common.HexToAddress("0x000000000000000000000000000000000000aaaa")
|
||||||
bb = common.HexToAddress("0x000000000000000000000000000000000000bbbb")
|
bb = common.HexToAddress("0x000000000000000000000000000000000000bbbb")
|
||||||
engine = beacon.NewFaker()
|
engine = beacon.New(ethash.NewFaker())
|
||||||
|
|
||||||
// A sender who makes transactions, has some funds
|
// A sender who makes transactions, has some funds
|
||||||
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
key1, _ = crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291")
|
||||||
|
|
@ -4103,7 +4103,7 @@ func TestPragueRequests(t *testing.T) {
|
||||||
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
|
addr1 = crypto.PubkeyToAddress(key1.PublicKey)
|
||||||
config = *params.MergedTestChainConfig
|
config = *params.MergedTestChainConfig
|
||||||
signer = types.LatestSigner(&config)
|
signer = types.LatestSigner(&config)
|
||||||
engine = beacon.NewFaker()
|
engine = beacon.New(ethash.NewFaker())
|
||||||
)
|
)
|
||||||
gspec := &Genesis{
|
gspec := &Genesis{
|
||||||
Config: &config,
|
Config: &config,
|
||||||
|
|
|
||||||
|
|
@ -80,8 +80,9 @@ func TestGeneratePOSChain(t *testing.T) {
|
||||||
Code: common.Hex2Bytes("600154600354"),
|
Code: common.Hex2Bytes("600154600354"),
|
||||||
}
|
}
|
||||||
genesis := gspec.MustCommit(gendb, triedb.NewDatabase(gendb, triedb.HashDefaults))
|
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)})
|
gen.SetParentBeaconRoot(common.Hash{byte(i + 1)})
|
||||||
|
|
||||||
// Add value transfer tx.
|
// Add value transfer tx.
|
||||||
|
|
@ -122,7 +123,7 @@ func TestGeneratePOSChain(t *testing.T) {
|
||||||
})
|
})
|
||||||
|
|
||||||
// Import the chain. This runs all block validation rules.
|
// 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()
|
defer blockchain.Stop()
|
||||||
|
|
||||||
if i, err := blockchain.InsertChain(genchain); err != nil {
|
if i, err := blockchain.InsertChain(genchain); err != nil {
|
||||||
|
|
|
||||||
|
|
@ -32,8 +32,7 @@ import (
|
||||||
"github.com/ethereum/go-ethereum/beacon/engine"
|
"github.com/ethereum/go-ethereum/beacon/engine"
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/ethereum/go-ethereum/consensus"
|
"github.com/ethereum/go-ethereum/consensus/beacon"
|
||||||
beaconConsensus "github.com/ethereum/go-ethereum/consensus/beacon"
|
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
"github.com/ethereum/go-ethereum/core/types"
|
"github.com/ethereum/go-ethereum/core/types"
|
||||||
|
|
@ -62,12 +61,11 @@ var (
|
||||||
|
|
||||||
func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
|
func generateMergeChain(n int, merged bool) (*core.Genesis, []*types.Block) {
|
||||||
config := *params.AllEthashProtocolChanges
|
config := *params.AllEthashProtocolChanges
|
||||||
engine := consensus.Engine(beaconConsensus.New(ethash.NewFaker()))
|
engine := beacon.New(ethash.NewFaker())
|
||||||
if merged {
|
if merged {
|
||||||
config.TerminalTotalDifficulty = common.Big0
|
config.TerminalTotalDifficulty = common.Big0
|
||||||
engine = beaconConsensus.NewFaker()
|
|
||||||
} else {
|
} else {
|
||||||
engine.(*beaconConsensus.Beacon).TestingTTDBlock(uint64(n))
|
engine.TestingTTDBlock(uint64(n))
|
||||||
}
|
}
|
||||||
genesis := &core.Genesis{
|
genesis := &core.Genesis{
|
||||||
Config: &config,
|
Config: &config,
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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/beacon"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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 {
|
func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int, *core.BlockGen)) *testBackend {
|
||||||
var (
|
var (
|
||||||
// Create a database pre-initialize with a genesis block
|
// Create a database pre-initialize with a genesis block
|
||||||
db = rawdb.NewMemoryDatabase()
|
db = rawdb.NewMemoryDatabase()
|
||||||
config = params.TestChainConfig
|
config = params.TestChainConfig
|
||||||
engine consensus.Engine = ethash.NewFaker()
|
engine = beacon.New(ethash.NewFaker())
|
||||||
)
|
)
|
||||||
|
if !shanghai {
|
||||||
if shanghai {
|
engine.TestingTTDBlock(math.MaxUint64)
|
||||||
|
} else {
|
||||||
config = ¶ms.ChainConfig{
|
config = ¶ms.ChainConfig{
|
||||||
ChainID: big.NewInt(1),
|
ChainID: big.NewInt(1),
|
||||||
HomesteadBlock: big.NewInt(0),
|
HomesteadBlock: big.NewInt(0),
|
||||||
|
|
@ -99,7 +99,6 @@ func newTestBackendWithGenerator(blocks int, shanghai bool, generator func(int,
|
||||||
TerminalTotalDifficulty: big.NewInt(0),
|
TerminalTotalDifficulty: big.NewInt(0),
|
||||||
Ethash: new(params.EthashConfig),
|
Ethash: new(params.EthashConfig),
|
||||||
}
|
}
|
||||||
engine = beacon.NewFaker()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gspec := &core.Genesis{
|
gspec := &core.Genesis{
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
func newTestMergedBackend(t *testing.T, n int, gspec *core.Genesis, generator func(i int, b *core.BlockGen)) *testBackend {
|
||||||
backend := &testBackend{
|
backend := &testBackend{
|
||||||
chainConfig: gspec.Config,
|
chainConfig: gspec.Config,
|
||||||
engine: beacon.NewFaker(),
|
engine: beacon.New(ethash.NewFaker()),
|
||||||
chaindb: rawdb.NewMemoryDatabase(),
|
chaindb: rawdb.NewMemoryDatabase(),
|
||||||
}
|
}
|
||||||
// Generate blocks for testing
|
// Generate blocks for testing
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"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/beacon"
|
||||||
"github.com/ethereum/go-ethereum/consensus/ethash"
|
"github.com/ethereum/go-ethereum/consensus/ethash"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"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,
|
RPCGasCap: 1000000,
|
||||||
StateScheme: rawdb.HashScheme,
|
StateScheme: rawdb.HashScheme,
|
||||||
}
|
}
|
||||||
var engine consensus.Engine = ethash.NewFaker()
|
var engine = beacon.New(ethash.NewFaker())
|
||||||
if shanghai {
|
if shanghai {
|
||||||
engine = beacon.NewFaker()
|
|
||||||
gspec.Config.TerminalTotalDifficulty = common.Big0
|
gspec.Config.TerminalTotalDifficulty = common.Big0
|
||||||
// GenerateChain will increment timestamps by 10.
|
// GenerateChain will increment timestamps by 10.
|
||||||
// Shanghai upgrade at block 1.
|
// Shanghai upgrade at block 1.
|
||||||
|
|
@ -468,6 +466,7 @@ func newGQLService(t *testing.T, stack *node.Node, shanghai bool, gspec *core.Ge
|
||||||
} else {
|
} else {
|
||||||
// set an arbitrary large ttd as chains are required to be known to be merged
|
// set an arbitrary large ttd as chains are required to be known to be merged
|
||||||
gspec.Config.TerminalTotalDifficulty = big.NewInt(math.MaxInt64)
|
gspec.Config.TerminalTotalDifficulty = big.NewInt(math.MaxInt64)
|
||||||
|
engine.TestingTTDBlock(math.MaxUint64)
|
||||||
}
|
}
|
||||||
ethBackend, err := eth.New(stack, ethConf)
|
ethBackend, err := eth.New(stack, ethConf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue