Skip to content

Commit dcc3d7f

Browse files
authored
feat(kurtosis-devnet): provide standalone descriptors (#13758)
1 parent 965163a commit dcc3d7f

File tree

6 files changed

+126
-103
lines changed

6 files changed

+126
-103
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package descriptors
2+
3+
type PortInfo struct {
4+
Host string `json:"host"`
5+
Port int `json:"port"`
6+
}
7+
8+
// EndpointMap is a map of service names to their endpoints.
9+
type EndpointMap map[string]PortInfo
10+
11+
// Service represents a chain service.
12+
type Service struct {
13+
Name string `json:"name"`
14+
Endpoints EndpointMap `json:"endpoints"`
15+
}
16+
17+
// ServiceMap is a map of service names to services.
18+
type ServiceMap map[string]Service
19+
20+
// Node represents a node for a chain.
21+
type Node struct {
22+
Services ServiceMap `json:"services"`
23+
}
24+
25+
// AddressMap is a map of addresses to their corresponding chain IDs.
26+
type AddressMap map[string]string
27+
28+
// Chain represents a chain (L1 or L2) in a devnet.
29+
type Chain struct {
30+
Name string `json:"name"`
31+
ID string `json:"id,omitempty"`
32+
Services ServiceMap `json:"services,omitempty"`
33+
Nodes []Node `json:"nodes"`
34+
Addresses AddressMap `json:"addresses,omitempty"`
35+
Wallets WalletMap `json:"wallets,omitempty"`
36+
JWT string `json:"jwt,omitempty"`
37+
}
38+
39+
// Wallet represents a wallet with an address and optional private key.
40+
type Wallet struct {
41+
Address string `json:"address"`
42+
PrivateKey string `json:"private_key,omitempty"`
43+
}
44+
45+
// WalletMap is a map of wallet names to wallets.
46+
type WalletMap map[string]Wallet
47+
48+
// DevnetEnvironment exposes the relevant information to interact with a devnet.
49+
type DevnetEnvironment struct {
50+
L1 *Chain `json:"l1"`
51+
L2 []*Chain `json:"l2"`
52+
}

kurtosis-devnet/pkg/kurtosis/endpoints.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"strconv"
55
"strings"
66

7+
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/descriptors"
78
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/inspect"
89
)
910

@@ -45,7 +46,7 @@ func NewServiceFinder(services inspect.ServiceMap, opts ...ServiceFinderOption)
4546
}
4647

4748
// FindL1Services finds L1 nodes.
48-
func (f *ServiceFinder) FindL1Services() ([]Node, ServiceMap) {
49+
func (f *ServiceFinder) FindL1Services() ([]descriptors.Node, descriptors.ServiceMap) {
4950
return f.findRPCEndpoints(func(serviceName string) (string, int, bool) {
5051
// Only match services that start with one of the node service identifiers.
5152
// We might have to change this if we need to support L1 services beyond nodes.
@@ -60,7 +61,7 @@ func (f *ServiceFinder) FindL1Services() ([]Node, ServiceMap) {
6061
}
6162

6263
// FindL2Services finds L2 nodes and services for a specific network
63-
func (f *ServiceFinder) FindL2Services(network string) ([]Node, ServiceMap) {
64+
func (f *ServiceFinder) FindL2Services(network string) ([]descriptors.Node, descriptors.ServiceMap) {
6465
networkSuffix := "-" + network
6566
return f.findRPCEndpoints(func(serviceName string) (string, int, bool) {
6667
if strings.HasSuffix(serviceName, networkSuffix) {
@@ -73,9 +74,9 @@ func (f *ServiceFinder) FindL2Services(network string) ([]Node, ServiceMap) {
7374
}
7475

7576
// findRPCEndpoints looks for services matching the given predicate that have an RPC port
76-
func (f *ServiceFinder) findRPCEndpoints(matchService func(string) (string, int, bool)) ([]Node, ServiceMap) {
77-
serviceMap := make(ServiceMap)
78-
var nodes []Node
77+
func (f *ServiceFinder) findRPCEndpoints(matchService func(string) (string, int, bool)) ([]descriptors.Node, descriptors.ServiceMap) {
78+
serviceMap := make(descriptors.ServiceMap)
79+
var nodes []descriptors.Node
7980

8081
for serviceName, ports := range f.services {
8182
if serviceIdentifier, num, ok := matchService(serviceName); ok {
@@ -85,28 +86,28 @@ func (f *ServiceFinder) findRPCEndpoints(matchService func(string) (string, int,
8586
if num > len(nodes) {
8687
// Extend the slice to accommodate the required index
8788
for i := len(nodes); i < num; i++ {
88-
nodes = append(nodes, Node{
89-
Services: make(ServiceMap),
89+
nodes = append(nodes, descriptors.Node{
90+
Services: make(descriptors.ServiceMap),
9091
})
9192
}
9293
}
93-
endpoints := make(EndpointMap)
94+
endpoints := make(descriptors.EndpointMap)
9495
for portName, portInfo := range ports {
9596
endpoints[portName] = portInfo
9697
}
97-
nodes[num-1].Services[serviceIdentifier] = Service{
98+
nodes[num-1].Services[serviceIdentifier] = descriptors.Service{
9899
Name: serviceName,
99100
Endpoints: endpoints,
100101
}
101102
allocated = true
102103
}
103104
}
104105
if !allocated {
105-
endpoints := make(EndpointMap)
106+
endpoints := make(descriptors.EndpointMap)
106107
for portName, portInfo := range ports {
107108
endpoints[portName] = portInfo
108109
}
109-
serviceMap[serviceIdentifier] = Service{
110+
serviceMap[serviceIdentifier] = descriptors.Service{
110111
Name: serviceName,
111112
Endpoints: endpoints,
112113
}

kurtosis-devnet/pkg/kurtosis/endpoints_test.go

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package kurtosis
33
import (
44
"testing"
55

6+
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/descriptors"
67
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/inspect"
78
"github.com/stretchr/testify/assert"
89
)
@@ -52,31 +53,31 @@ func TestFindRPCEndpoints(t *testing.T) {
5253
tests := []struct {
5354
name string
5455
services inspect.ServiceMap
55-
findFn func(*ServiceFinder) ([]Node, ServiceMap)
56-
wantNodes []Node
57-
wantServices ServiceMap
56+
findFn func(*ServiceFinder) ([]descriptors.Node, descriptors.ServiceMap)
57+
wantNodes []descriptors.Node
58+
wantServices descriptors.ServiceMap
5859
}{
5960
{
6061
name: "find L1 endpoints",
6162
services: testServices,
62-
findFn: func(f *ServiceFinder) ([]Node, ServiceMap) {
63+
findFn: func(f *ServiceFinder) ([]descriptors.Node, descriptors.ServiceMap) {
6364
return f.FindL1Services()
6465
},
65-
wantNodes: []Node{
66+
wantNodes: []descriptors.Node{
6667
{
67-
Services: ServiceMap{
68-
"cl": Service{
68+
Services: descriptors.ServiceMap{
69+
"cl": descriptors.Service{
6970
Name: "cl-1-lighthouse-geth",
70-
Endpoints: EndpointMap{
71+
Endpoints: descriptors.EndpointMap{
7172
"metrics": {Port: 52691},
7273
"tcp-discovery": {Port: 52692},
7374
"udp-discovery": {Port: 58275},
7475
"http": {Port: 52693},
7576
},
7677
},
77-
"el": Service{
78+
"el": descriptors.Service{
7879
Name: "el-1-geth-lighthouse",
79-
Endpoints: EndpointMap{
80+
Endpoints: descriptors.EndpointMap{
8081
"metrics": {Port: 52643},
8182
"tcp-discovery": {Port: 52644},
8283
"udp-discovery": {Port: 51936},
@@ -88,28 +89,28 @@ func TestFindRPCEndpoints(t *testing.T) {
8889
},
8990
},
9091
},
91-
wantServices: ServiceMap{},
92+
wantServices: descriptors.ServiceMap{},
9293
},
9394
{
9495
name: "find op-kurtosis L2 endpoints",
9596
services: testServices,
96-
findFn: func(f *ServiceFinder) ([]Node, ServiceMap) {
97+
findFn: func(f *ServiceFinder) ([]descriptors.Node, descriptors.ServiceMap) {
9798
return f.FindL2Services("op-kurtosis")
9899
},
99-
wantNodes: []Node{
100+
wantNodes: []descriptors.Node{
100101
{
101-
Services: ServiceMap{
102-
"cl": Service{
102+
Services: descriptors.ServiceMap{
103+
"cl": descriptors.Service{
103104
Name: "op-cl-1-op-node-op-geth-op-kurtosis",
104-
Endpoints: EndpointMap{
105+
Endpoints: descriptors.EndpointMap{
105106
"udp-discovery": {Port: 50990},
106107
"http": {Port: 53503},
107108
"tcp-discovery": {Port: 53504},
108109
},
109110
},
110-
"el": Service{
111+
"el": descriptors.Service{
111112
Name: "op-el-1-op-geth-op-node-op-kurtosis",
112-
Endpoints: EndpointMap{
113+
Endpoints: descriptors.EndpointMap{
113114
"udp-discovery": {Port: 53233},
114115
"engine-rpc": {Port: 53399},
115116
"metrics": {Port: 53400},
@@ -121,10 +122,10 @@ func TestFindRPCEndpoints(t *testing.T) {
121122
},
122123
},
123124
},
124-
wantServices: ServiceMap{
125-
"batcher": Service{
125+
wantServices: descriptors.ServiceMap{
126+
"batcher": descriptors.Service{
126127
Name: "op-batcher-op-kurtosis",
127-
Endpoints: EndpointMap{
128+
Endpoints: descriptors.EndpointMap{
128129
"http": {Port: 53572},
129130
},
130131
},
@@ -137,14 +138,14 @@ func TestFindRPCEndpoints(t *testing.T) {
137138
"http": {Host: "custom.host", Port: 8080},
138139
},
139140
},
140-
findFn: func(f *ServiceFinder) ([]Node, ServiceMap) {
141+
findFn: func(f *ServiceFinder) ([]descriptors.Node, descriptors.ServiceMap) {
141142
return f.FindL2Services("custom-host")
142143
},
143144
wantNodes: nil,
144-
wantServices: ServiceMap{
145-
"batcher": Service{
145+
wantServices: descriptors.ServiceMap{
146+
"batcher": descriptors.Service{
146147
Name: "op-batcher-custom-host",
147-
Endpoints: EndpointMap{
148+
Endpoints: descriptors.EndpointMap{
148149
"http": {Host: "custom.host", Port: 8080},
149150
},
150151
},

kurtosis-devnet/pkg/kurtosis/kurtosis.go

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
"fmt"
77
"io"
88

9+
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/descriptors"
910
apiInterfaces "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/interfaces"
1011
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/run"
1112
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/api/wrappers"
1213
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/deployer"
13-
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/inspect"
1414
srcInterfaces "github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/interfaces"
1515
"github.com/ethereum-optimism/optimism/kurtosis-devnet/pkg/kurtosis/sources/spec"
1616
)
@@ -20,40 +20,9 @@ const (
2020
DefaultEnclave = "devnet"
2121
)
2222

23-
type EndpointMap map[string]inspect.PortInfo
24-
25-
type ServiceMap map[string]Service
26-
27-
type Service struct {
28-
Name string `json:"name"`
29-
Endpoints EndpointMap `json:"endpoints"`
30-
}
31-
32-
type Node struct {
33-
Services ServiceMap `json:"services"`
34-
}
35-
36-
type Chain struct {
37-
Name string `json:"name"`
38-
ID string `json:"id,omitempty"`
39-
Services ServiceMap `json:"services,omitempty"`
40-
Nodes []Node `json:"nodes"`
41-
Addresses deployer.DeploymentAddresses `json:"addresses,omitempty"`
42-
Wallets WalletMap `json:"wallets,omitempty"`
43-
JWT string `json:"jwt,omitempty"`
44-
}
45-
46-
type Wallet struct {
47-
Address string `json:"address"`
48-
PrivateKey string `json:"private_key,omitempty"`
49-
}
50-
51-
type WalletMap map[string]Wallet
52-
5323
// KurtosisEnvironment represents the output of a Kurtosis deployment
5424
type KurtosisEnvironment struct {
55-
L1 *Chain `json:"l1"`
56-
L2 []*Chain `json:"l2"`
25+
descriptors.DevnetEnvironment
5726
}
5827

5928
// KurtosisDeployer handles deploying packages using Kurtosis
@@ -162,10 +131,10 @@ func NewKurtosisDeployer(opts ...KurtosisDeployerOptions) (*KurtosisDeployer, er
162131
return d, nil
163132
}
164133

165-
func (d *KurtosisDeployer) getWallets(wallets deployer.WalletList) WalletMap {
166-
walletMap := make(WalletMap)
134+
func (d *KurtosisDeployer) getWallets(wallets deployer.WalletList) descriptors.WalletMap {
135+
walletMap := make(descriptors.WalletMap)
167136
for _, wallet := range wallets {
168-
walletMap[wallet.Name] = Wallet{
137+
walletMap[wallet.Name] = descriptors.Wallet{
169138
Address: wallet.Address,
170139
PrivateKey: wallet.PrivateKey,
171140
}
@@ -193,20 +162,22 @@ func (d *KurtosisDeployer) GetEnvironmentInfo(ctx context.Context, spec *spec.En
193162
}
194163

195164
env := &KurtosisEnvironment{
196-
L2: make([]*Chain, 0, len(spec.Chains)),
165+
DevnetEnvironment: descriptors.DevnetEnvironment{
166+
L2: make([]*descriptors.Chain, 0, len(spec.Chains)),
167+
},
197168
}
198169

199170
// Find L1 endpoint
200171
finder := NewServiceFinder(inspectResult.UserServices)
201172
if nodes, services := finder.FindL1Services(); len(nodes) > 0 {
202-
chain := &Chain{
173+
chain := &descriptors.Chain{
203174
Name: "Ethereum",
204175
Services: services,
205176
Nodes: nodes,
206177
JWT: jwtData.L1JWT,
207178
}
208179
if deployerState.State != nil {
209-
chain.Addresses = deployerState.State.Addresses
180+
chain.Addresses = descriptors.AddressMap(deployerState.State.Addresses)
210181
chain.Wallets = d.getWallets(deployerState.Wallets)
211182
}
212183
env.L1 = chain
@@ -216,7 +187,7 @@ func (d *KurtosisDeployer) GetEnvironmentInfo(ctx context.Context, spec *spec.En
216187
for _, chainSpec := range spec.Chains {
217188
nodes, services := finder.FindL2Services(chainSpec.Name)
218189

219-
chain := &Chain{
190+
chain := &descriptors.Chain{
220191
Name: chainSpec.Name,
221192
ID: chainSpec.NetworkID,
222193
Services: services,
@@ -227,7 +198,7 @@ func (d *KurtosisDeployer) GetEnvironmentInfo(ctx context.Context, spec *spec.En
227198
// Add contract addresses if available
228199
if deployerState.State != nil && deployerState.State.Deployments != nil {
229200
if addresses, ok := deployerState.State.Deployments[chainSpec.NetworkID]; ok {
230-
chain.Addresses = addresses.Addresses
201+
chain.Addresses = descriptors.AddressMap(addresses.Addresses)
231202
}
232203
if wallets, ok := deployerState.State.Deployments[chainSpec.NetworkID]; ok {
233204
chain.Wallets = d.getWallets(wallets.Wallets)

0 commit comments

Comments
 (0)