Skip to content

Commit

Permalink
simulators/optimism: testnet sim, update p2p sim
Browse files Browse the repository at this point in the history
  • Loading branch information
protolambda authored and mslipper committed Sep 8, 2022
1 parent da8bd89 commit e8a4ecc
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 74 deletions.
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ use (
./optimism
./simulators/optimism/p2p
./simulators/optimism/rpc
./simulators/optimism/testnet
)
16 changes: 10 additions & 6 deletions simulators/optimism/p2p/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
FROM golang:1.18-alpine3.15 as builder
RUN apk add --update gcc musl-dev linux-headers

# Build the simulator executable.
ADD . /source
WORKDIR /source
# Build the simulator executable, from hive repo root.
# See context.txt for docker build context change.
# We use a go.work file to pull in other go modules of the hive repo.
ADD ./simulators/optimism/p2p/hive.go.work /source/go.work
ADD ./optimism /source/optimism
ADD ./simulators/optimism/p2p /source/p2p

WORKDIR /source/p2p
RUN go build -v .

# Build the simulator run container.
FROM alpine:latest
ADD . /source
WORKDIR /source
COPY --from=builder /source/p2p .

COPY --from=builder /source/p2p/p2p .
ENTRYPOINT ["./p2p"]
7 changes: 3 additions & 4 deletions simulators/optimism/p2p/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# Optimism P2P test suite
# Hive Optimism P2P test suite

This test suite tests the P2P protocol between the sequencer and verifier on
the optimism network.
This test suite tests the P2P functionality in an Optimism Bedrock testnet.

hive --sim optimism/p2p --client=op-l1,op-l2,op-proposer,op-batcher,op-sequencer,op-verifier --docker.output
hive --sim optimism/p2p --client=op-l1,op-geth,op-proposer,op-batcher,op-node,op-contracts --docker.output
34 changes: 0 additions & 34 deletions simulators/optimism/p2p/helper.go

This file was deleted.

6 changes: 6 additions & 0 deletions simulators/optimism/p2p/hive.go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
./optimism
./p2p
)
4 changes: 2 additions & 2 deletions simulators/optimism/p2p/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import (
func main() {
suite := hivesim.Suite{
Name: "optimism p2p",
Description: "This suite runs the P2P protocol tests",
Description: "This suite runs the P2P tests",
}

// Add tests for full nodes.
suite.Add(&hivesim.TestSpec{
Name: "simple p2p testnet",
Description: `This test run.`,
Description: `This suite runs the a testnet with P2P set up`,
Run: func(t *hivesim.T) { runP2PTests(t) },
})

Expand Down
27 changes: 0 additions & 27 deletions simulators/optimism/p2p/nodes.go

This file was deleted.

2 changes: 1 addition & 1 deletion simulators/optimism/rpc/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Optimism RPC test suite
# Hive Optimism RPC test suite

This test suite is a copy of the ETH L1 RPC test suite adapted for Optimism L2.
It tests several real-world scenarios such as sending value transactions,
Expand Down
20 changes: 20 additions & 0 deletions simulators/optimism/testnet/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# This simulation runs JSON-RPC API tests.
FROM golang:1.18-alpine3.15 as builder
RUN apk add --update gcc musl-dev linux-headers

# Build the simulator executable, from hive repo root.
# See context.txt for docker build context change.
# We use a go.work file to pull in other go modules of the hive repo.
ADD ./simulators/optimism/testnet/hive.go.work /source/go.work
ADD ./optimism /source/optimism
ADD ./simulators/optimism/testnet /source/testnet

WORKDIR /source/p2p
RUN go build -v .


# Build the simulator run container.
FROM alpine:latest

COPY --from=builder /source/testnet/testnet .
ENTRYPOINT ["./testnet"]
5 changes: 5 additions & 0 deletions simulators/optimism/testnet/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Hive Optimism Testnet

This test runs an Optimism Bedrock testnet.

hive --sim optimism/testnet --client=op-l1,op-geth,op-proposer,op-batcher,op-node,op-contracts --docker.output
1 change: 1 addition & 0 deletions simulators/optimism/testnet/context.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
../../../
31 changes: 31 additions & 0 deletions simulators/optimism/testnet/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module github.com/ethereum/hive/simulators/optimism/testnet

go 1.18

replace github.com/ethereum/go-ethereum v1.10.20 => github.com/ethereum-optimism/reference-optimistic-geth v0.0.0-20220715235548-70b02481016d

replace github.com/ethereum/hive v0.0.0-20220726101544-19cb1f8cc162 => github.com/ethereum-optimism/hive v0.0.0-20220727114344-022fad9696a4

require (
github.com/ethereum/go-ethereum v1.10.20
github.com/ethereum/hive v0.0.0-20220726101544-19cb1f8cc162
)

require (
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang-jwt/jwt/v4 v4.3.0 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220614013038-64ee5596c38a // indirect
github.com/tklauser/go-sysconf v0.3.5 // indirect
github.com/tklauser/numcpus v0.2.2 // indirect
golang.org/x/crypto v0.0.0-20211202192323-5770296d904e // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
)
6 changes: 6 additions & 0 deletions simulators/optimism/testnet/hive.go.work
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
go 1.18

use (
./optimism
./testnet
)
117 changes: 117 additions & 0 deletions simulators/optimism/testnet/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
package main

import (
"context"
"github.com/ethereum-optimism/optimism/op-node/rollup/driver"
"github.com/ethereum-optimism/optimism/op-proposer/rollupclient"
"github.com/stretchr/testify/assert"
"time"

"github.com/ethereum/hive/hivesim"
"github.com/ethereum/hive/optimism"
)

func main() {
suite := hivesim.Suite{
Name: "optimism p2p",
Description: "This suite runs the P2P tests",
}

// Add tests for full nodes.
suite.Add(&hivesim.TestSpec{
Name: "simple p2p testnet",
Description: `This suite runs the a testnet with P2P set up`,
Run: func(t *hivesim.T) { runP2PTests(t) },
})

sim := hivesim.New()
hivesim.MustRunSuite(sim, suite)
}

// runP2PTests runs the P2P tests between the sequencer and verifier.
func runP2PTests(t *hivesim.T) {
handleErr := func(err error) {
if err != nil {
t.Fatal(err)
}
}

d := optimism.NewDevnet(t)

d.InitContracts()
d.InitRollupHardhat()
d.AddEth1()
// wait for L1 to come online before deploying
{
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
_, err := d.GetEth1(0).EthClient().ChainID(ctx)
handleErr(err)
}
d.DeployL1Hardhat()

// sequencer stack, on top of first eth1 node
d.AddOpL2()
d.AddOpNode(0, 0)
d.AddOpBatcher(0, 0, 0)
d.AddOpProposer(0, 0, 0)

// TODO: pass optimism.UnprefixedParams{flag env vars here}.Params()
// hivesim start option to the op nodes to configure p2p networking

// verifier A
d.AddOpL2()
d.AddOpNode(0, 1) // we attach to the same L1 node, so we don't need to configure L1 networking.

// verifier B
d.AddOpL2()
d.AddOpNode(0, 2)

t.Log("waiting for nodes to get onto the network")
time.Sleep(time.Second * 10)

seq := d.GetOpNode(0)
verifA := d.GetOpNode(1)
verifB := d.GetOpNode(2)

seqCl := seq.RollupClient()
verifACl := verifA.RollupClient()
verifBCl := verifB.RollupClient()

ctx, cancel := context.WithCancel(context.Background())
go func() {
ticker := time.NewTicker(time.Second * 4)
defer ticker.Stop()

syncStat := func(name string, cl *rollupclient.RollupClient) *driver.SyncStatus {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*4)
seqStat, err := cl.SyncStatus(ctx)
cancel()
if err != nil {
t.Error("failed to get sync status from %s op-node: %v", name, err)
}
return seqStat // may be nil
}

for {
select {
case <-ticker.C:
// Check that all clients are synced
seqStat := syncStat("sequencer", seqCl)
verAStat := syncStat("verifier-A", verifACl)
verBStat := syncStat("verifier-B", verifBCl)
assert.Equal(t, seqStat, verAStat, "sequencer and verifier A should be synced")
assert.Equal(t, verAStat, verBStat, "verifier A and verifier B should be synced")
case <-ctx.Done():
t.Log("exiting sync checking loop")
return
}
}
}()

// Run testnet for duration of 3 sequence windows
time.Sleep(time.Second * time.Duration(d.L1Cfg.Clique.Period*d.RollupCfg.SeqWindowSize*3))
cancel()

// TODO: Add P2P tests
}

0 comments on commit e8a4ecc

Please sign in to comment.