-
Notifications
You must be signed in to change notification settings - Fork 202
/
Copy pathgeth_launcher.star
390 lines (355 loc) · 12.1 KB
/
geth_launcher.star
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
shared_utils = import_module("../../shared_utils/shared_utils.star")
input_parser = import_module("../../package_io/input_parser.star")
el_context = import_module("../../el/el_context.star")
el_admin_node_info = import_module("../../el/el_admin_node_info.star")
genesis_constants = import_module(
"../../prelaunch_data_generator/genesis_constants/genesis_constants.star"
)
node_metrics = import_module("../../node_metrics_info.star")
constants = import_module("../../package_io/constants.star")
RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
DISCOVERY_PORT_NUM = 30303
ENGINE_RPC_PORT_NUM = 8551
METRICS_PORT_NUM = 9001
# The min/max CPU/memory that the execution node can use
EXECUTION_MIN_CPU = 300
EXECUTION_MIN_MEMORY = 512
# Port IDs
RPC_PORT_ID = "rpc"
WS_PORT_ID = "ws"
TCP_DISCOVERY_PORT_ID = "tcp-discovery"
UDP_DISCOVERY_PORT_ID = "udp-discovery"
ENGINE_RPC_PORT_ID = "engine-rpc"
ENGINE_WS_PORT_ID = "engineWs"
METRICS_PORT_ID = "metrics"
# TODO(old) Scale this dynamically based on CPUs available and Geth nodes mining
NUM_MINING_THREADS = 1
METRICS_PATH = "/debug/metrics/prometheus"
# The dirpath of the execution data directory on the client container
EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER = "/data/geth/execution-data"
PRIVATE_IP_ADDRESS_PLACEHOLDER = "KURTOSIS_IP_ADDR_PLACEHOLDER"
USED_PORTS = {
RPC_PORT_ID: shared_utils.new_port_spec(
RPC_PORT_NUM,
shared_utils.TCP_PROTOCOL,
shared_utils.HTTP_APPLICATION_PROTOCOL,
),
WS_PORT_ID: shared_utils.new_port_spec(WS_PORT_NUM, shared_utils.TCP_PROTOCOL),
TCP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
DISCOVERY_PORT_NUM, shared_utils.TCP_PROTOCOL
),
UDP_DISCOVERY_PORT_ID: shared_utils.new_port_spec(
DISCOVERY_PORT_NUM, shared_utils.UDP_PROTOCOL
),
ENGINE_RPC_PORT_ID: shared_utils.new_port_spec(
ENGINE_RPC_PORT_NUM,
shared_utils.TCP_PROTOCOL,
),
METRICS_PORT_ID: shared_utils.new_port_spec(
METRICS_PORT_NUM, shared_utils.TCP_PROTOCOL
),
}
ENTRYPOINT_ARGS = ["sh", "-c"]
VERBOSITY_LEVELS = {
constants.GLOBAL_LOG_LEVEL.error: "1",
constants.GLOBAL_LOG_LEVEL.warn: "2",
constants.GLOBAL_LOG_LEVEL.info: "3",
constants.GLOBAL_LOG_LEVEL.debug: "4",
constants.GLOBAL_LOG_LEVEL.trace: "5",
}
BUILDER_IMAGE_STR = "builder"
SUAVE_ENABLED_GETH_IMAGE_STR = "suave"
def launch(
plan,
launcher,
service_name,
image,
participant_log_level,
global_log_level,
# If empty then the node will be launched as a bootnode
existing_el_clients,
el_min_cpu,
el_max_cpu,
el_min_mem,
el_max_mem,
extra_params,
extra_env_vars,
extra_labels,
persistent,
el_volume_size,
tolerations,
node_selectors,
):
log_level = input_parser.get_client_log_level_or_default(
participant_log_level, global_log_level, VERBOSITY_LEVELS
)
network_name = shared_utils.get_network_name(launcher.network)
el_min_cpu = int(el_min_cpu) if int(el_min_cpu) > 0 else EXECUTION_MIN_CPU
el_max_cpu = (
int(el_max_cpu)
if int(el_max_cpu) > 0
else constants.RAM_CPU_OVERRIDES[network_name]["geth_max_cpu"]
)
el_min_mem = int(el_min_mem) if int(el_min_mem) > 0 else EXECUTION_MIN_MEMORY
el_max_mem = (
int(el_max_mem)
if int(el_max_mem) > 0
else constants.RAM_CPU_OVERRIDES[network_name]["geth_max_mem"]
)
el_volume_size = (
el_volume_size
if int(el_volume_size) > 0
else constants.VOLUME_SIZE[network_name]["geth_volume_size"]
)
cl_client_name = service_name.split("-")[3]
config = get_config(
plan,
launcher.el_cl_genesis_data,
launcher.jwt_file,
launcher.network,
launcher.networkid,
image,
service_name,
existing_el_clients,
cl_client_name,
log_level,
el_min_cpu,
el_max_cpu,
el_min_mem,
el_max_mem,
extra_params,
extra_env_vars,
extra_labels,
launcher.cancun_time,
launcher.prague_time,
persistent,
el_volume_size,
tolerations,
node_selectors,
)
service = plan.add_service(service_name, config)
enode, enr = el_admin_node_info.get_enode_enr_for_node(
plan, service_name, RPC_PORT_ID
)
metrics_url = "{0}:{1}".format(service.ip_address, METRICS_PORT_NUM)
geth_metrics_info = node_metrics.new_node_metrics_info(
service_name, METRICS_PATH, metrics_url
)
return el_context.new_el_context(
"geth",
enr,
enode,
service.ip_address,
RPC_PORT_NUM,
WS_PORT_NUM,
ENGINE_RPC_PORT_NUM,
service_name,
[geth_metrics_info],
)
def get_config(
plan,
el_cl_genesis_data,
jwt_file,
network,
networkid,
image,
service_name,
existing_el_clients,
cl_client_name,
verbosity_level,
el_min_cpu,
el_max_cpu,
el_min_mem,
el_max_mem,
extra_params,
extra_env_vars,
extra_labels,
cancun_time,
prague_time,
persistent,
el_volume_size,
tolerations,
node_selectors,
):
# TODO: Remove this once electra fork has path based storage scheme implemented
if (
constants.NETWORK_NAME.verkle in network
) and constants.NETWORK_NAME.shadowfork not in network:
if constants.NETWORK_NAME.verkle + "-gen" in network: # verkle-gen
init_datadir_cmd_str = "geth --datadir={0} --cache.preimages --override.prague={1} init {2}".format(
EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER,
prague_time,
constants.GENESIS_CONFIG_MOUNT_PATH_ON_CONTAINER + "/genesis.json",
)
else: # verkle
init_datadir_cmd_str = (
"geth --datadir={0} --cache.preimages init {1}".format(
EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER,
constants.GENESIS_CONFIG_MOUNT_PATH_ON_CONTAINER + "/genesis.json",
)
)
elif constants.NETWORK_NAME.shadowfork in network:
init_datadir_cmd_str = "echo shadowfork"
elif (
"--gcmode archive" in extra_params
): # Disable path based storage scheme archive mode
init_datadir_cmd_str = "geth init --datadir={0} {1}".format(
EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER,
constants.GENESIS_CONFIG_MOUNT_PATH_ON_CONTAINER + "/genesis.json",
)
else:
init_datadir_cmd_str = "geth init --state.scheme=path --datadir={0} {1}".format(
EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER,
constants.GENESIS_CONFIG_MOUNT_PATH_ON_CONTAINER + "/genesis.json",
)
cmd = [
"geth",
# Disable path based storage scheme for electra fork and verkle
# TODO: REMOVE Once geth default db is path based, and builder rebased
"{0}".format(
"--state.scheme=path"
if "verkle" not in network and "--gcmode archive" not in extra_params
else ""
),
# Override prague fork timestamp for electra fork
"{0}".format("--cache.preimages" if "verkle" in network else ""),
# Override prague fork timestamp
"{0}".format(
"--override.prague=" + str(prague_time) if "verkle-gen" in network else ""
),
"{0}".format(
"--{}".format(network) if network in constants.PUBLIC_NETWORKS else ""
),
"{0}".format(
"--override.cancun=" + str(cancun_time)
if constants.NETWORK_NAME.shadowfork in network
else ""
),
"--networkid={0}".format(networkid),
"--verbosity=" + verbosity_level,
"--datadir=" + EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER,
"--http",
"--http.addr=0.0.0.0",
"--http.vhosts=*",
"--http.corsdomain=*",
# WARNING: The admin info endpoint is enabled so that we can easily get ENR/enode, which means
# that users should NOT store private information in these Kurtosis nodes!
"--http.api=admin,engine,net,eth,web3,debug",
"--ws",
"--ws.addr=0.0.0.0",
"--ws.port={0}".format(WS_PORT_NUM),
"--ws.api=admin,engine,net,eth,web3,debug",
"--ws.origins=*",
"--allow-insecure-unlock",
"--nat=extip:" + PRIVATE_IP_ADDRESS_PLACEHOLDER,
"--verbosity=" + verbosity_level,
"--authrpc.port={0}".format(ENGINE_RPC_PORT_NUM),
"--authrpc.addr=0.0.0.0",
"--authrpc.vhosts=*",
"--authrpc.jwtsecret=" + constants.JWT_MOUNT_PATH_ON_CONTAINER,
"--syncmode=full",
"--rpc.allow-unprotected-txs",
"--metrics",
"--metrics.addr=0.0.0.0",
"--metrics.port={0}".format(METRICS_PORT_NUM),
]
if BUILDER_IMAGE_STR in image:
for index, arg in enumerate(cmd):
if "--http.api" in arg:
cmd[index] = "--http.api=admin,engine,net,eth,web3,debug,mev,flashbots"
if "--ws.api" in arg:
cmd[index] = "--ws.api=admin,engine,net,eth,web3,debug,mev,flashbots"
if SUAVE_ENABLED_GETH_IMAGE_STR in image:
for index, arg in enumerate(cmd):
if "--http.api" in arg:
cmd[index] = "--http.api=admin,engine,net,eth,web3,debug,suavex"
if "--ws.api" in arg:
cmd[index] = "--ws.api=admin,engine,net,eth,web3,debug,suavex"
if (
network == constants.NETWORK_NAME.kurtosis
or constants.NETWORK_NAME.shadowfork in network
):
if len(existing_el_clients) > 0:
cmd.append(
"--bootnodes="
+ ",".join(
[
ctx.enode
for ctx in existing_el_clients[: constants.MAX_ENODE_ENTRIES]
]
)
)
if (
constants.NETWORK_NAME.shadowfork in network and "verkle" in network
): # verkle shadowfork
cmd.append("--override.prague=" + str(prague_time))
cmd.append("--override.overlay-stride=10000")
cmd.append("--override.blockproof=true")
cmd.append("--clear.verkle.costs=true")
elif network not in constants.PUBLIC_NETWORKS:
cmd.append(
"--bootnodes="
+ shared_utils.get_devnet_enodes(
plan, el_cl_genesis_data.files_artifact_uuid
)
)
if len(extra_params) > 0:
# this is a repeated<proto type>, we convert it into Starlark
cmd.extend([param for param in extra_params])
cmd_str = " ".join(cmd)
if network not in constants.PUBLIC_NETWORKS:
subcommand_strs = [
init_datadir_cmd_str,
cmd_str,
]
command_str = " && ".join(subcommand_strs)
else:
command_str = cmd_str
files = {
constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: el_cl_genesis_data.files_artifact_uuid,
constants.JWT_MOUNTPOINT_ON_CLIENTS: jwt_file,
}
if persistent:
files[EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER] = Directory(
persistent_key="data-{0}".format(service_name),
size=el_volume_size,
)
return ServiceConfig(
image=image,
ports=USED_PORTS,
cmd=[command_str],
files=files,
entrypoint=ENTRYPOINT_ARGS,
private_ip_address_placeholder=PRIVATE_IP_ADDRESS_PLACEHOLDER,
min_cpu=el_min_cpu,
max_cpu=el_max_cpu,
min_memory=el_min_mem,
max_memory=el_max_mem,
env_vars=extra_env_vars,
labels=shared_utils.label_maker(
constants.EL_TYPE.geth,
constants.CLIENT_TYPES.el,
image,
cl_client_name,
extra_labels,
),
tolerations=tolerations,
node_selectors=node_selectors,
)
def new_geth_launcher(
el_cl_genesis_data,
jwt_file,
network,
networkid,
cancun_time,
prague_time,
):
return struct(
el_cl_genesis_data=el_cl_genesis_data,
jwt_file=jwt_file,
network=network,
networkid=networkid,
cancun_time=cancun_time,
prague_time=prague_time,
)