-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathrecipe_opstack.go
More file actions
214 lines (177 loc) · 6.63 KB
/
recipe_opstack.go
File metadata and controls
214 lines (177 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package playground
import (
flag "github.com/spf13/pflag"
)
var _ Recipe = &OpRecipe{}
const defaultL2BuilderAddress = "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266"
// OpRecipe is a recipe that deploys an OP stack
type OpRecipe struct {
// externalBuilder is the URL of the external builder to use. If enabled, the recipe deploys
// rollup-boost on the sequencer and uses this URL as the external builder.
externalBuilder string
// whether to enable the latest fork jovian and when
enableLatestFork *uint64
// blockTime is the block time to use for the rollup
// (default is 2 seconds)
blockTime uint64
// batcherMaxChannelDuration is the maximum channel duration to use for the batcher
// (default is 2 seconds)
batcherMaxChannelDuration uint64
// whether to enable flashblocks in Rollup-boost. Note the internal builder **will not** be
// using flashblocks. This is meant to be used with an external builder for now.
flashblocks bool
// flashblocksBuilderURL is the URL of the builder that returns the flashblocks. This is meant to be used
// for external builders.
flashblocksBuilderURL string
// Indicates that flashblocks-rpc should use base image
baseOverlay bool
// whether to enable websocket proxy
enableWebsocketProxy bool
// whether to enable chain-monitor
enableChainMonitor bool
// predeploysFile is the path to a JSON file containing additional contracts
// to predeploy in the L2 genesis
predeploysFile string
}
func (o *OpRecipe) Name() string {
return "opstack"
}
func (o *OpRecipe) Description() string {
return "Deploy an OP stack"
}
func (o *OpRecipe) Flags() *flag.FlagSet {
flags := flag.NewFlagSet("opstack", flag.ContinueOnError)
flags.StringVar(&o.externalBuilder, "external-builder", "", "External builder URL")
flags.Var(&nullableUint64Value{&o.enableLatestFork}, "enable-latest-fork", "Enable Jovian fork: 0 = at genesis, N > 0 = at block N (default: Isthmus only)")
flags.Uint64Var(&o.blockTime, "block-time", defaultOpBlockTimeSeconds, "Block time to use for the rollup")
flags.Uint64Var(&o.batcherMaxChannelDuration, "batcher-max-channel-duration", 2, "Maximum channel duration to use for the batcher")
flags.BoolVar(&o.flashblocks, "flashblocks", false, "Whether to enable flashblocks")
flags.BoolVar(&o.baseOverlay, "base-overlay", false, "Whether to use base implementation for flashblocks-rpc")
flags.StringVar(&o.flashblocksBuilderURL, "flashblocks-builder", "", "External URL of builder flashblocks stream")
flags.BoolVar(&o.enableWebsocketProxy, "enable-websocket-proxy", false, "Whether to enable websocket proxy")
flags.BoolVar(&o.enableChainMonitor, "chain-monitor", false, "Whether to enable chain-monitor")
flags.StringVar(&o.predeploysFile, "use-predeploys", "", "Path to JSON file with additional contracts to predeploy in L2 genesis")
return flags
}
func (o *OpRecipe) Artifacts() *ArtifactsBuilder {
builder := NewArtifactsBuilder()
builder.WithL2()
builder.ApplyLatestL2Fork(o.enableLatestFork)
builder.OpBlockTime(o.blockTime)
builder.PredeployFile(o.predeploysFile)
return builder
}
func (o *OpRecipe) Apply(ctx *ExContext) *Component {
component := NewComponent("op-recipe")
component.AddComponent(ctx, &Bootnode{})
component.AddComponent(ctx, &RethEL{})
component.AddComponent(ctx, &LighthouseBeaconNode{
ExecutionNode: "el",
})
component.AddComponent(ctx, &LighthouseValidator{
BeaconNode: "beacon",
})
flashblocksBuilderURLRef := o.flashblocksBuilderURL
externalBuilderRef := o.externalBuilder
peers := []string{}
if o.externalBuilder == "op-reth" {
// Add a new op-reth service and connect it to Rollup-boost
component.AddComponent(ctx, &OpReth{})
externalBuilderRef = Connect("op-reth", "authrpc")
} else if o.externalBuilder == "op-rbuilder" {
component.AddComponent(ctx, &OpRbuilder{
Flashblocks: o.flashblocks,
})
externalBuilderRef = Connect("op-rbuilder", "authrpc")
}
if o.flashblocks && o.externalBuilder == "op-rbuilder" {
// If flashblocks is enabled and using op-rbuilder, use it to deliver flashblocks
flashblocksBuilderURLRef = ConnectWs("op-rbuilder", "flashblocks")
}
if o.flashblocks {
peers = append(peers, "flashblocks-rpc")
}
// Only enable bproxy if flashblocks is enabled (since flashblocks-rpc is the only service that needs it)
if o.flashblocks {
component.AddComponent(ctx, &BProxy{
TargetAuthrpc: externalBuilderRef,
Peers: peers,
Flashblocks: o.flashblocks,
FlashblocksBuilderURL: flashblocksBuilderURLRef,
})
}
// Only enable websocket-proxy if the flag is set
if o.enableWebsocketProxy {
component.AddComponent(ctx, &WebsocketProxy{
Upstream: "rollup-boost",
})
}
elNode := "op-geth"
if o.externalBuilder != "" {
elNode = "rollup-boost"
// Use bproxy if flashblocks is enabled, otherwise use external builder directly
builderRef := externalBuilderRef
flashblocksBuilderRef := flashblocksBuilderURLRef
if o.flashblocks {
builderRef = Connect("bproxy", "authrpc")
flashblocksBuilderRef = ConnectWs("bproxy", "flashblocks")
}
component.AddComponent(ctx, &RollupBoost{
ELNode: "op-geth",
Builder: builderRef,
Flashblocks: o.flashblocks,
FlashblocksBuilderURL: flashblocksBuilderRef,
})
}
if o.flashblocks {
// Determine which service to use for flashblocks websocket connection
flashblocksWSService := "rollup-boost"
useWebsocketProxy := false
if o.enableWebsocketProxy {
flashblocksWSService = "websocket-proxy"
useWebsocketProxy = true
}
component.AddComponent(ctx, &FlashblocksRPC{
FlashblocksWSService: flashblocksWSService,
BaseOverlay: o.baseOverlay,
UseWebsocketProxy: useWebsocketProxy,
})
}
component.AddService(ctx, &OpGeth{})
component.AddComponent(ctx, &OpNode{
L1Node: "el",
L1Beacon: "beacon",
L2Node: elNode,
})
component.AddComponent(ctx, &OpBatcher{
L1Node: "el",
L2Node: "op-geth",
RollupNode: "op-node",
MaxChannelDuration: o.batcherMaxChannelDuration,
})
if o.enableChainMonitor {
component.AddComponent(ctx, &ChainMonitor{
L1RPC: "el",
L2BlockTime: o.blockTime,
L2BuilderAddress: defaultL2BuilderAddress,
L2RPC: "op-geth",
})
}
if ctx.Contender.TargetChain == "" {
ctx.Contender.TargetChain = "op-geth"
}
component.RunContenderIfEnabled(ctx)
return component
}
func (o *OpRecipe) Output(manifest *Manifest) map[string]interface{} {
/*
opGeth := manifest.MustGetService("op-geth").component.(*OpGeth)
if opGeth.Enode != "" {
// Only output if enode was set
return map[string]interface{}{
"op-geth-enode": opGeth.Enode,
}
}
*/
return map[string]interface{}{}
}