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: 0 additions & 10 deletions devnet-sdk/descriptors/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package descriptors

import (
"encoding/json"
"fmt"
"net/http"

"github.com/ethereum-optimism/optimism/devnet-sdk/types"
Expand All @@ -11,22 +10,13 @@ import (

type PortInfo struct {
Host string `json:"host"`
Path string `json:"path,omitempty"`
Scheme string `json:"scheme,omitempty"`
Port int `json:"port,omitempty"`
PrivatePort int `json:"private_port,omitempty"`

ReverseProxyHeader http.Header `json:"reverse_proxy_header,omitempty"`
}

func AppendPath(baseURL, path string) string {
url := baseURL
if path != "" {
url += fmt.Sprintf("/%s", path)
}
return url
}

// EndpointMap is a map of service names to their endpoints.
type EndpointMap map[string]*PortInfo

Expand Down
20 changes: 13 additions & 7 deletions op-devstack/sysext/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sysext
import (
"fmt"
"net/http"
"net/url"

"github.com/ethereum/go-ethereum/rpc"

Expand All @@ -22,18 +23,21 @@ const (
FeatureInterop = "interop"
)

func (orch *Orchestrator) rpcClient(t devtest.T, service *descriptors.Service, protocol string) client.RPC {
func (orch *Orchestrator) rpcClient(t devtest.T, service *descriptors.Service, protocol string, path string) client.RPC {
t.Helper()

endpoint, header, err := orch.findProtocolService(service, protocol)
t.Require().NoError(err)

endpoint, err = url.JoinPath(endpoint, path)
t.Require().NoError(err)

opts := []client.RPCOption{}
if !orch.useEagerRPCClients {
opts = append(opts, client.WithLazyDial())
}

if orch.env.Env.ReverseProxyURL != "" && !orch.useDirectCnx {
if orch.env.Env.ReverseProxyURL != "" && len(header) > 0 && !orch.useDirectCnx {
opts = append(
opts,
client.WithGethRPCOptions(
Expand All @@ -52,12 +56,15 @@ func (orch *Orchestrator) rpcClient(t devtest.T, service *descriptors.Service, p
return cl
}

func (orch *Orchestrator) httpClient(t devtest.T, service *descriptors.Service, protocol string) *client.BasicHTTPClient {
func (orch *Orchestrator) httpClient(t devtest.T, service *descriptors.Service, protocol string, path string) *client.BasicHTTPClient {
t.Helper()

endpoint, header, err := orch.findProtocolService(service, protocol)
t.Require().NoError(err)

endpoint, err = url.JoinPath(endpoint, path)
t.Require().NoError(err)

opts := []client.BasicHTTPClientOption{}

if orch.env.Env.ReverseProxyURL != "" && !orch.useDirectCnx {
Expand All @@ -74,16 +81,15 @@ func (orch *Orchestrator) httpClient(t devtest.T, service *descriptors.Service,
func (orch *Orchestrator) findProtocolService(service *descriptors.Service, protocol string) (string, http.Header, error) {
for proto, endpoint := range service.Endpoints {
if proto == protocol {
if orch.env.Env.ReverseProxyURL != "" && !orch.useDirectCnx {
return descriptors.AppendPath(orch.env.Env.ReverseProxyURL, endpoint.Path), endpoint.ReverseProxyHeader, nil
if orch.env.Env.ReverseProxyURL != "" && len(endpoint.ReverseProxyHeader) > 0 && !orch.useDirectCnx {
return orch.env.Env.ReverseProxyURL, endpoint.ReverseProxyHeader, nil
}

port := endpoint.Port
if orch.usePrivatePorts {
port = endpoint.PrivatePort
}
url := descriptors.AppendPath(fmt.Sprintf("http://%s:%d", endpoint.Host, port), endpoint.Path)
return url, nil, nil
return fmt.Sprintf("http://%s:%d", endpoint.Host, port), nil, nil
}
}
return "", nil, fmt.Errorf("protocol %s not found", protocol)
Expand Down
9 changes: 3 additions & 6 deletions op-devstack/sysext/l1.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (o *Orchestrator) hydrateL1(system stack.ExtensibleSystem) {
l1.AddL1ELNode(shim.NewL1ELNode(shim.L1ELNodeConfig{
ELNodeConfig: shim.ELNodeConfig{
CommonConfig: commonConfig,
Client: o.rpcClient(t, elService, RPCProtocol),
Client: o.rpcClient(t, elService, RPCProtocol, "/"),
ChainID: l1ID,
},
ID: stack.L1ELNodeID{
Expand All @@ -49,18 +49,15 @@ func (o *Orchestrator) hydrateL1(system stack.ExtensibleSystem) {
ChainID: l1ID,
},
CommonConfig: commonConfig,
Client: o.httpClient(t, clService, HTTPProtocol),
Client: o.httpClient(t, clService, HTTPProtocol, "/"),
}))
}

if faucet, ok := env.Env.L1.Services["faucet"]; ok {
for _, instance := range faucet {
for _, endpoint := range instance.Endpoints {
endpoint.Path = fmt.Sprintf("chain/%s", l1.ChainID().String())
}
l1.AddFaucet(shim.NewFaucet(shim.FaucetConfig{
CommonConfig: commonConfig,
Client: o.rpcClient(t, instance, RPCProtocol),
Client: o.rpcClient(t, instance, RPCProtocol, fmt.Sprintf("/chain/%s", env.Env.L1.Config.ChainID.String())),
ID: stack.FaucetID{Key: instance.Name, ChainID: l1ID},
}))
}
Expand Down
15 changes: 6 additions & 9 deletions op-devstack/sysext/l2.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,9 @@ func (o *Orchestrator) hydrateL2(net *descriptors.L2Chain, system stack.Extensib

if faucet, ok := net.Services["faucet"]; ok {
for _, instance := range faucet {
for _, endpoint := range instance.Endpoints {
endpoint.Path = fmt.Sprintf("chain/%s", l2.ChainID().String())
}
l2.AddFaucet(shim.NewFaucet(shim.FaucetConfig{
CommonConfig: commonConfig,
Client: o.rpcClient(t, instance, RPCProtocol),
Client: o.rpcClient(t, instance, RPCProtocol, fmt.Sprintf("/chain/%s", l2.ChainID().String())),
ID: stack.FaucetID{Key: instance.Name, ChainID: l2.ChainID()},
}))
}
Expand All @@ -79,7 +76,7 @@ func (o *Orchestrator) hydrateL2ELCL(node *descriptors.Node, l2Net stack.Extensi

elService, ok := node.Services[ELServiceName]
require.True(ok, "need L2 EL service for chain", l2ID)
elClient := o.rpcClient(l2Net.T(), elService, RPCProtocol)
elClient := o.rpcClient(l2Net.T(), elService, RPCProtocol, "/")
l2EL := shim.NewL2ELNode(shim.L2ELNodeConfig{
ELNodeConfig: shim.ELNodeConfig{
CommonConfig: shim.NewCommonConfig(l2Net.T()),
Expand All @@ -103,7 +100,7 @@ func (o *Orchestrator) hydrateL2ELCL(node *descriptors.Node, l2Net stack.Extensi
require.True(ok, "need L2 CL service for chain", l2ID)

// it's an RPC, but 'http' in kurtosis descriptor
clClient := o.rpcClient(l2Net.T(), clService, HTTPProtocol)
clClient := o.rpcClient(l2Net.T(), clService, HTTPProtocol, "/")
l2CL := shim.NewL2CLNode(shim.L2CLNodeConfig{
ID: stack.L2CLNodeID{
Key: clService.Name,
Expand Down Expand Up @@ -131,7 +128,7 @@ func (o *Orchestrator) hydrateL2ProxydMaybe(net *descriptors.L2Chain, l2Net stac
l2Proxyd := shim.NewL2ELNode(shim.L2ELNodeConfig{
ELNodeConfig: shim.ELNodeConfig{
CommonConfig: shim.NewCommonConfig(l2Net.T()),
Client: o.rpcClient(l2Net.T(), instance, HTTPProtocol),
Client: o.rpcClient(l2Net.T(), instance, HTTPProtocol, "/"),
ChainID: l2ID.ChainID(),
},
ID: stack.L2ELNodeID{
Expand Down Expand Up @@ -162,7 +159,7 @@ func (o *Orchestrator) hydrateBatcherMaybe(net *descriptors.L2Chain, l2Net stack
Key: instance.Name,
ChainID: l2ID.ChainID(),
},
Client: o.rpcClient(l2Net.T(), instance, HTTPProtocol),
Client: o.rpcClient(l2Net.T(), instance, HTTPProtocol, "/"),
}))
}
}
Expand All @@ -185,7 +182,7 @@ func (o *Orchestrator) hydrateProposerMaybe(net *descriptors.L2Chain, l2Net stac
Key: instance.Name,
ChainID: l2ID.ChainID(),
},
Client: o.rpcClient(l2Net.T(), instance, HTTPProtocol),
Client: o.rpcClient(l2Net.T(), instance, HTTPProtocol, "/"),
}))
}
}
Expand Down
2 changes: 1 addition & 1 deletion op-devstack/sysext/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func (o *Orchestrator) hydrateSupervisorsMaybe(sys stack.ExtensibleSystem) {
sys.AddSupervisor(shim.NewSupervisor(shim.SupervisorConfig{
CommonConfig: shim.NewCommonConfig(sys.T()),
ID: id,
Client: o.rpcClient(sys.T(), instance, RPCProtocol),
Client: o.rpcClient(sys.T(), instance, RPCProtocol, "/"),
}))
}
}
Expand Down