Skip to content

Commit 4d064ab

Browse files
committed
l1 geth subprocess
1 parent 80ddf69 commit 4d064ab

File tree

22 files changed

+512
-59
lines changed

22 files changed

+512
-59
lines changed

op-acceptance-tests/tests/osaka/activation_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import (
66

77
"github.com/ethereum-optimism/optimism/op-batcher/batcher"
88
"github.com/ethereum-optimism/optimism/op-batcher/flags"
9+
"github.com/ethereum-optimism/optimism/op-chain-ops/devkeys"
910
"github.com/ethereum-optimism/optimism/op-devstack/devtest"
1011
"github.com/ethereum-optimism/optimism/op-devstack/presets"
1112
"github.com/ethereum-optimism/optimism/op-devstack/stack"
1213
"github.com/ethereum-optimism/optimism/op-devstack/sysgo"
14+
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/intentbuilder"
1315
)
1416

1517
const osakaOffset = 30
@@ -18,7 +20,11 @@ func TestMain(m *testing.M) {
1820
ids := sysgo.NewDefaultMinimalSystemIDs(sysgo.DefaultL1ID, sysgo.DefaultL2AID)
1921
opt := stack.Combine[*sysgo.Orchestrator]()
2022
opt.Add(sysgo.DefaultMinimalSystem(&ids))
21-
opt.Add(sysgo.WithDeployerOptions(sysgo.WithOsakaOffset(ids.L1.ChainID(), osakaOffset)))
23+
opt.Add(sysgo.WithDeployerOptions(
24+
func(_ devtest.P, _ devkeys.Keys, builder intentbuilder.Builder) {
25+
_, l1Config := builder.WithL1(ids.L1.ChainID())
26+
l1Config.WithOsakaOffset(osakaOffset)
27+
}))
2228
opt.Add(sysgo.WithBatcherOption(func(_ stack.L2BatcherID, cfg *batcher.CLIConfig) {
2329
cfg.DataAvailabilityType = flags.BlobsType
2430
}))
@@ -31,6 +37,6 @@ func TestOsakaActivation(gt *testing.T) {
3137
osakaActivationTime := time.Unix(int64(*sys.L1Network.Escape().ChainConfig().OsakaTime), 0)
3238
t.Log("Waiting for osaka to activate...")
3339
time.Sleep(time.Until(osakaActivationTime))
34-
t.Log("Osaka activated")
35-
sys.L2EL.WaitForFinalization()
40+
t.Log("Osaka activation time reached")
41+
sys.L1EL.WaitForFinalization()
3642
}

op-devstack/stack/match/labels.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const (
2020
type Vendor string
2121

2222
const (
23+
Geth Vendor = "geth"
2324
OpReth Vendor = "op-reth"
2425
OpGeth Vendor = "op-geth"
2526
Proxyd Vendor = "proxyd"

op-devstack/sysgo/deployer.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"math/big"
55
"os"
66
"path/filepath"
7-
"strconv"
87
"time"
98

109
"github.com/ethereum/go-ethereum/common"
@@ -196,13 +195,6 @@ func WithLocalContractSources() DeployerOption {
196195
}
197196
}
198197

199-
func WithOsakaOffset(l1ChainID eth.ChainID, offset uint64) DeployerOption {
200-
return func(_ devtest.P, _ devkeys.Keys, builder intentbuilder.Builder) {
201-
_, l1Config := builder.WithL1(l1ChainID)
202-
l1Config.WithOsakaOffset(offset)
203-
}
204-
}
205-
206198
func WithCommons(l1ChainID eth.ChainID) DeployerOption {
207199
return func(p devtest.P, keys devkeys.Keys, builder intentbuilder.Builder) {
208200
_, l1Config := builder.WithL1(l1ChainID)
@@ -212,12 +204,6 @@ func WithCommons(l1ChainID eth.ChainID) DeployerOption {
212204

213205
l1Config.WithPragueOffset(0) // activate pectra on L1
214206

215-
if osakaOffsetStr, ok := os.LookupEnv("SYSGO_OSAKA_OFFSET"); ok {
216-
offset, err := strconv.ParseUint(osakaOffsetStr, 10, 64)
217-
p.Require().NoError(err)
218-
WithOsakaOffset(l1ChainID, offset)
219-
}
220-
221207
faucetFunderAddr, err := keys.Address(devkeys.UserKey(funderMnemonicIndex))
222208
p.Require().NoError(err, "need funder addr")
223209
l1Config.WithPrefundedAccount(faucetFunderAddr, *eth.BillionEther.ToU256())

op-devstack/sysgo/engine_client.go

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
package sysgo
2+
3+
import (
4+
"context"
5+
6+
"github.com/ethereum-optimism/optimism/op-e2e/e2eutils/geth"
7+
"github.com/ethereum/go-ethereum/beacon/engine"
8+
"github.com/ethereum/go-ethereum/common"
9+
"github.com/ethereum/go-ethereum/common/hexutil"
10+
gn "github.com/ethereum/go-ethereum/node"
11+
"github.com/ethereum/go-ethereum/rpc"
12+
gethrpc "github.com/ethereum/go-ethereum/rpc"
13+
)
14+
15+
type engineClient struct {
16+
inner *rpc.Client
17+
}
18+
19+
func dialEngine(ctx context.Context, endpoint string, jwtSecret [32]byte) (*engineClient, error) {
20+
engineCl, err := gethrpc.DialOptions(ctx, endpoint, rpc.WithHTTPAuth(gn.NewJWTAuth(jwtSecret)))
21+
if err != nil {
22+
return nil, err
23+
}
24+
return &engineClient{
25+
inner: engineCl,
26+
}, nil
27+
}
28+
29+
var _ geth.EngineAPI = (*engineClient)(nil)
30+
31+
func (e *engineClient) forkchoiceUpdated(fs engine.ForkchoiceStateV1, pa *engine.PayloadAttributes, method string) (engine.ForkChoiceResponse, error) {
32+
var x engine.ForkChoiceResponse
33+
if err := e.inner.CallContext(context.Background(), &x, method, fs, pa); err != nil {
34+
return engine.ForkChoiceResponse{}, err
35+
}
36+
return x, nil
37+
}
38+
39+
func (e *engineClient) ForkchoiceUpdatedV2(fs engine.ForkchoiceStateV1, pa *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
40+
return e.forkchoiceUpdated(fs, pa, "engine_forkchoiceUpdatedV2")
41+
}
42+
43+
func (e *engineClient) ForkchoiceUpdatedV3(fs engine.ForkchoiceStateV1, pa *engine.PayloadAttributes) (engine.ForkChoiceResponse, error) {
44+
return e.forkchoiceUpdated(fs, pa, "engine_forkchoiceUpdatedV3")
45+
}
46+
47+
func (e *engineClient) getPayload(id engine.PayloadID, method string) (*engine.ExecutionPayloadEnvelope, error) {
48+
var result engine.ExecutionPayloadEnvelope
49+
if err := e.inner.CallContext(context.Background(), &result, method, id); err != nil {
50+
return nil, err
51+
}
52+
return &result, nil
53+
}
54+
55+
func (e *engineClient) GetPayloadV2(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
56+
return e.getPayload(id, "engine_getPayloadV2")
57+
}
58+
59+
func (e *engineClient) GetPayloadV3(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
60+
return e.getPayload(id, "engine_getPayloadV3")
61+
}
62+
63+
func (e *engineClient) GetPayloadV4(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
64+
return e.getPayload(id, "engine_getPayloadV4")
65+
}
66+
67+
func (e *engineClient) GetPayloadV5(id engine.PayloadID) (*engine.ExecutionPayloadEnvelope, error) {
68+
return e.getPayload(id, "engine_getPayloadV5")
69+
}
70+
71+
func (e *engineClient) NewPayloadV2(data engine.ExecutableData) (engine.PayloadStatusV1, error) {
72+
var result engine.PayloadStatusV1
73+
if err := e.inner.CallContext(context.Background(), &result, "engine_newPayloadV2", data); err != nil {
74+
return engine.PayloadStatusV1{}, err
75+
}
76+
return result, nil
77+
}
78+
79+
func (e *engineClient) NewPayloadV3(data engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash) (engine.PayloadStatusV1, error) {
80+
var result engine.PayloadStatusV1
81+
if err := e.inner.CallContext(context.Background(), &result, "engine_newPayloadV3", data, versionedHashes, beaconRoot); err != nil {
82+
return engine.PayloadStatusV1{}, err
83+
}
84+
return result, nil
85+
}
86+
87+
func (e *engineClient) NewPayloadV4(data engine.ExecutableData, versionedHashes []common.Hash, beaconRoot *common.Hash, executionRequests []hexutil.Bytes) (engine.PayloadStatusV1, error) {
88+
var result engine.PayloadStatusV1
89+
if err := e.inner.CallContext(context.Background(), &result, "engine_newPayloadV4", data, versionedHashes, beaconRoot, executionRequests); err != nil {
90+
return engine.PayloadStatusV1{}, err
91+
}
92+
return result, nil
93+
}

op-devstack/sysgo/faucet.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func WithFaucets(l1ELs []stack.L1ELNodeID, l2ELs []stack.L2ELNodeID) stack.Optio
7575
require.True(ok, "need L1 EL for faucet", elID)
7676

7777
faucets[id] = &fconf.FaucetEntry{
78-
ELRPC: endpoint.MustRPC{Value: endpoint.URL(el.userRPC)},
78+
ELRPC: endpoint.MustRPC{Value: endpoint.URL(el.UserRPC())},
7979
ChainID: elID.ChainID(),
8080
TxCfg: fconf.TxManagerConfig{
8181
PrivateKey: funderKeyStr,

op-devstack/sysgo/l1_nodes.go

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package sysgo
22

33
import (
4+
"os"
45
"path/filepath"
56

67
"github.com/ethereum-optimism/optimism/op-devstack/shim"
@@ -12,14 +13,32 @@ import (
1213
"github.com/ethereum-optimism/optimism/op-service/clock"
1314
)
1415

15-
type L1ELNode struct {
16+
type L1ELNode interface {
17+
hydrator
18+
l1ELNode()
19+
UserRPC() string
20+
AuthRPC() string
21+
}
22+
23+
type L1Geth struct {
1624
id stack.L1ELNodeID
1725
userRPC string
26+
authRPC string
1827
l1Geth *geth.GethInstance
1928
blobPath string
2029
}
2130

22-
func (n *L1ELNode) hydrate(system stack.ExtensibleSystem) {
31+
func (*L1Geth) l1ELNode() {}
32+
33+
func (g *L1Geth) UserRPC() string {
34+
return g.userRPC
35+
}
36+
37+
func (g *L1Geth) AuthRPC() string {
38+
return g.authRPC
39+
}
40+
41+
func (n *L1Geth) hydrate(system stack.ExtensibleSystem) {
2342
require := system.T().Require()
2443
rpcCl, err := client.NewRPC(system.T().Ctx(), system.Logger(), n.userRPC, client.WithLazyDial())
2544
require.NoError(err)
@@ -55,6 +74,13 @@ func (n *L1CLNode) hydrate(system stack.ExtensibleSystem) {
5574
}
5675

5776
func WithL1Nodes(l1ELID stack.L1ELNodeID, l1CLID stack.L1CLNodeID) stack.Option[*Orchestrator] {
77+
if gethExecPath, ok := os.LookupEnv("SYSGO_GETH_EXEC_PATH"); ok {
78+
return WithL1NodesSubprocess(l1ELID, l1CLID, gethExecPath)
79+
}
80+
return WithL1NodesInProcess(l1ELID, l1CLID)
81+
}
82+
83+
func WithL1NodesInProcess(l1ELID stack.L1ELNodeID, l1CLID stack.L1CLNodeID) stack.Option[*Orchestrator] {
5884
return stack.AfterDeploy(func(orch *Orchestrator) {
5985
clP := orch.P().WithCtx(stack.ContextWithID(orch.P().Ctx(), l1CLID))
6086
elP := orch.P().WithCtx(stack.ContextWithID(orch.P().Ctx(), l1ELID))
@@ -96,9 +122,10 @@ func WithL1Nodes(l1ELID stack.L1ELNodeID, l1CLID stack.L1CLNodeID) stack.Option[
96122
_ = l1Geth.Close()
97123
})
98124

99-
l1ELNode := &L1ELNode{
125+
l1ELNode := &L1Geth{
100126
id: l1ELID,
101127
userRPC: l1Geth.Node.HTTPEndpoint(),
128+
authRPC: l1Geth.Node.HTTPAuthEndpoint(),
102129
l1Geth: l1Geth,
103130
blobPath: blobPath,
104131
}
@@ -120,7 +147,7 @@ func WithExtL1Nodes(l1ELID stack.L1ELNodeID, l1CLID stack.L1CLNodeID, elRPCEndpo
120147
require := orch.P().Require()
121148

122149
// Create L1 EL node with external RPC
123-
l1ELNode := &L1ELNode{
150+
l1ELNode := &L1Geth{
124151
id: l1ELID,
125152
userRPC: elRPCEndpoint,
126153
}

0 commit comments

Comments
 (0)