Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use (
.
./hiveproxy
./simulators/devp2p
./simulators/eth2/common
./simulators/eth2/engine
./simulators/eth2/testnet
./simulators/ethereum/consensus
Expand Down
212 changes: 212 additions & 0 deletions go.work.sum

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions simulators/eth2/common/chain_generators/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package chaingenerators

import (
"github.com/ethereum/go-ethereum/core/types"
el "github.com/ethereum/hive/simulators/eth2/common/config/execution"
)

type ChainGenerator interface {
Generate(*el.ExecutionGenesis) ([]*types.Block, error)
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
package main
package pow

import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/ethash"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/rawdb"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"

"github.com/ethereum/hive/simulators/eth2/engine/setup"
execution_config "github.com/ethereum/hive/simulators/eth2/common/config/execution"
)

type ChainGenerator interface {
Generate(*setup.Eth1Genesis) ([]*types.Block, error)
}

var PoWChainGeneratorDefaults = ethash.Config{
var Defaults = ethash.Config{
PowMode: ethash.ModeNormal,
CachesInMem: 2,
DatasetsOnDisk: 2,
DatasetDir: "/ethash",
}

type PoWChainGenerator struct {
type ChainGenerator struct {
BlockCount int
ethash.Config
GenFunction func(int, *core.BlockGen)
Expand All @@ -35,8 +29,24 @@ type instaSeal struct{ consensus.Engine }

// FinalizeAndAssemble implements consensus.Engine, accumulating the block and uncle rewards,
// setting the final state and assembling the block.
func (e instaSeal) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
block, err := e.Engine.FinalizeAndAssemble(chain, header, state, txs, uncles, receipts)
func (e instaSeal) FinalizeAndAssemble(
chain consensus.ChainHeaderReader,
header *types.Header,
state *state.StateDB,
txs []*types.Transaction,
uncles []*types.Header,
receipts []*types.Receipt,
withdrawals []*types.Withdrawal,
) (*types.Block, error) {
block, err := e.Engine.FinalizeAndAssemble(
chain,
header,
state,
txs,
uncles,
receipts,
withdrawals,
)
if err != nil {
return nil, err
}
Expand All @@ -47,26 +57,31 @@ func (e instaSeal) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header
return <-sealedBlock, nil
}

func (p *PoWChainGenerator) Generate(genesis *setup.Eth1Genesis) ([]*types.Block, error) {
func (p *ChainGenerator) Generate(
genesis *execution_config.ExecutionGenesis,
) ([]*types.Block, error) {
// We generate a new chain only if the generator had not generated one already.
// This is done because the chain generators can be reused on different clients to ensure
// they start with the same chain.
if p.blocks != nil {
return p.blocks, nil
}
db := rawdb.NewMemoryDatabase()
engine := ethash.New(p.Config, nil, false)
insta := instaSeal{engine}
genesisBlock := genesis.Genesis.ToBlock()
p.blocks, _ = core.GenerateChain(genesis.Genesis.Config, genesisBlock, insta, db, p.BlockCount, p.GenFunction)
_, p.blocks, _ = core.GenerateChainWithGenesis(
genesis.Genesis,
insta,
p.BlockCount,
p.GenFunction,
)
return p.blocks, nil
}

func (p *PoWChainGenerator) Blocks() []*types.Block {
func (p *ChainGenerator) Blocks() []*types.Block {
return p.blocks
}

func (p *PoWChainGenerator) Head() *types.Block {
func (p *ChainGenerator) Head() *types.Block {
if p.blocks == nil || len(p.blocks) == 0 {
return nil
}
Expand Down
Loading