Skip to content
Merged
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
10 changes: 10 additions & 0 deletions simulators/eth2/engine/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Generate the ethash verification caches.
# Use a static version because this will never need to be updated.
FROM ethereum/client-go:v1.10.20 AS geth
RUN \
/usr/local/bin/geth makecache 1 /ethash && \
/usr/local/bin/geth makedag 1 /ethash

# Build the simulator binary
FROM golang:1-alpine AS builder
RUN apk --no-cache add gcc musl-dev linux-headers cmake make clang build-base clang-static clang-dev
ADD . /source
Expand All @@ -8,4 +16,6 @@ RUN go build -o ./sim .
FROM alpine:latest
ADD . /
COPY --from=builder /source/sim /
COPY --from=geth /ethash /ethash

ENTRYPOINT ["./sim"]
62 changes: 62 additions & 0 deletions simulators/eth2/engine/chain_generators.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

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"
)

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

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

type PoWChainGenerator struct {
BlockCount int
ethash.Config
GenFunction func(int, *core.BlockGen)
blocks []*types.Block
}

// instaSeal wraps a consensus engine with instant block sealing. When a block is produced
// using FinalizeAndAssemble, it also applies Seal.
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)
if err != nil {
return nil, err
}
sealedBlock := make(chan *types.Block, 1)
if err = e.Engine.Seal(nil, block, sealedBlock, nil); err != nil {
return nil, err
}
return <-sealedBlock, nil
}

func (p *PoWChainGenerator) Generate(genesis *setup.Eth1Genesis) ([]*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(db)
p.blocks, _ = core.GenerateChain(genesis.Genesis.Config, genesisBlock, insta, db, p.BlockCount, p.GenFunction)
return p.blocks, nil
}
16 changes: 16 additions & 0 deletions simulators/eth2/engine/engineapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ const (
EngineForkchoiceUpdatedV1 string = "engine_forkchoiceUpdatedV1"
EngineGetPayloadV1 = "engine_getPayloadV1"
EngineNewPayloadV1 = "engine_newPayloadV1"
EthGetBlockByHash = "eth_getBlockByHash"
EthGetBlockByNumber = "eth_getBlockByNumber"
)

// EngineClient wrapper for Ethereum Engine RPC for testing purposes.
Expand Down Expand Up @@ -124,6 +126,20 @@ func (ec *EngineClient) checkTTD() (*types.Header, bool) {
return nil, false
}

func (ec *EngineClient) waitForTTDWithTimeout(cliqueSeconds uint64, timeout <-chan time.Time) bool {
for {
select {
case <-time.After(time.Duration(cliqueSeconds) * time.Second):
_, ok := ec.checkTTD()
if ok {
return true
}
case <-timeout:
return false
}
}
}

// Engine API Types
type PayloadStatusV1 struct {
Status PayloadStatus `json:"status"`
Expand Down
23 changes: 12 additions & 11 deletions simulators/eth2/engine/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ethereum/hive/simulators/eth2/engine
go 1.17

require (
github.com/ethereum/go-ethereum v1.10.17
github.com/ethereum/go-ethereum v1.10.20
github.com/ethereum/hive v0.0.0-20220707162108-7ef78bf4723f
github.com/google/uuid v1.3.0
github.com/herumi/bls-eth-go-binary v0.0.0-20210902234237-7763804ee078
Expand Down Expand Up @@ -31,30 +31,31 @@ require (
github.com/minio/sha256-simd v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.4.2 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onsi/gomega v1.15.0 // indirect
github.com/onsi/gomega v1.19.0 // indirect
github.com/prometheus/tsdb v0.10.0 // indirect
github.com/protolambda/bls12-381-util v0.0.0-20210812140640-b03868185758
github.com/shirou/gopsutil v3.21.8+incompatible // indirect
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.9 // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/text v0.3.7 // indirect
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

require (
github.com/Azure/go-ansiterm v0.0.0-20210617225240-d185dfc1b5a1 // indirect
github.com/Microsoft/go-winio v0.5.2 // indirect
github.com/Microsoft/hcsshim v0.9.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.1.2 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/containerd/cgroups v1.0.3 // indirect
github.com/containerd/containerd v1.6.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/docker/docker v20.10.12+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
github.com/docker/go-units v0.4.0 // indirect
github.com/edsrzf/mmap-go v1.0.0 // indirect
github.com/fjl/gencodec v0.0.0-20220412091415-8bb9e558978c // indirect
github.com/fsouza/go-dockerclient v1.7.11 // indirect
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
Expand Down Expand Up @@ -82,14 +83,14 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
github.com/tklauser/numcpus v0.3.0 // indirect
github.com/urfave/cli/v2 v2.5.1 // indirect
github.com/urfave/cli/v2 v2.10.2 // indirect
github.com/wealdtech/go-bytesutil v1.1.1 // indirect
github.com/wealdtech/go-eth2-types/v2 v2.5.6 // indirect
go.opencensus.io v0.23.0 // indirect
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e // indirect
golang.org/x/mod v0.4.2 // indirect
golang.org/x/tools v0.1.5 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
golang.org/x/mod v0.6.0-dev.0.20211013180041-c96bc1413d57 // indirect
golang.org/x/tools v0.1.8-0.20211029000441-d6a9af8af023 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
gopkg.in/inconshreveable/log15.v2 v2.0.0-20200109203555-b30bc20e4fd1 // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
Expand Down
Loading