-
Notifications
You must be signed in to change notification settings - Fork 343
Expand file tree
/
Copy pathbesu_launcher.star
More file actions
354 lines (316 loc) · 11.2 KB
/
Copy pathbesu_launcher.star
File metadata and controls
354 lines (316 loc) · 11.2 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
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
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")
el_shared = import_module("../el_shared.star")
node_metrics = import_module("../../node_metrics_info.star")
constants = import_module("../../package_io/constants.star")
# The dirpath of the execution data directory on the client container
EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER = "/data/besu/execution-data"
METRICS_PATH = "/metrics"
RPC_PORT_NUM = 8545
WS_PORT_NUM = 8546
DISCOVERY_PORT_NUM = 30303
ENGINE_HTTP_RPC_PORT_NUM = 8551
METRICS_PORT_NUM = 9001
JAVA_OPTS = {"JAVA_OPTS": "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n"}
ENTRYPOINT_ARGS = ["sh", "-c"]
VERBOSITY_LEVELS = {
constants.GLOBAL_LOG_LEVEL.error: "ERROR",
constants.GLOBAL_LOG_LEVEL.warn: "WARN",
constants.GLOBAL_LOG_LEVEL.info: "INFO",
constants.GLOBAL_LOG_LEVEL.debug: "DEBUG",
constants.GLOBAL_LOG_LEVEL.trace: "TRACE",
constants.GLOBAL_LOG_LEVEL.custom: "CUSTOM",
}
def launch(
plan,
launcher,
service_name,
participant,
global_log_level,
existing_el_clients,
persistent,
tolerations,
node_selectors,
port_publisher,
participant_index,
network_params,
extra_files_artifacts,
bootnodoor_el_enr=None,
el_binary_artifact=None,
otel_otlp_grpc_url=None,
):
cl_client_name = service_name.split("-")[3]
config = get_config(
plan,
launcher,
participant,
service_name,
existing_el_clients,
cl_client_name,
global_log_level,
persistent,
tolerations,
node_selectors,
port_publisher,
participant_index,
network_params,
extra_files_artifacts,
bootnodoor_el_enr,
el_binary_artifact,
otel_otlp_grpc_url,
)
service = plan.add_service(
service_name, config, force_update=participant.el_force_restart
)
return get_el_context(
plan,
service_name,
service,
launcher,
)
def get_config(
plan,
launcher,
participant,
service_name,
existing_el_clients,
cl_client_name,
global_log_level,
persistent,
tolerations,
node_selectors,
port_publisher,
participant_index,
network_params,
extra_files_artifacts,
bootnodoor_el_enr=None,
el_binary_artifact=None,
otel_otlp_grpc_url=None,
):
log_level = input_parser.get_client_log_level_or_default(
participant.el_log_level, global_log_level, VERBOSITY_LEVELS
)
public_ports = {}
public_ports_for_component = None
if port_publisher.el_enabled:
public_ports_for_component = shared_utils.get_public_ports_for_component(
"el", port_publisher, participant_index
)
public_ports = el_shared.get_general_el_public_port_specs(
public_ports_for_component
)
additional_public_port_assignments = {
constants.RPC_PORT_ID: public_ports_for_component[3],
constants.WS_PORT_ID: public_ports_for_component[4],
}
public_ports.update(
shared_utils.get_port_specs(additional_public_port_assignments)
)
discovery_port_tcp = (
public_ports_for_component[0]
if public_ports_for_component
else DISCOVERY_PORT_NUM
)
discovery_port_udp = (
public_ports_for_component[0]
if public_ports_for_component
else DISCOVERY_PORT_NUM
)
used_port_assignments = {
constants.TCP_DISCOVERY_PORT_ID: discovery_port_tcp,
constants.UDP_DISCOVERY_PORT_ID: discovery_port_udp,
constants.ENGINE_RPC_PORT_ID: ENGINE_HTTP_RPC_PORT_NUM,
constants.METRICS_PORT_ID: METRICS_PORT_NUM,
constants.RPC_PORT_ID: RPC_PORT_NUM,
constants.WS_PORT_ID: WS_PORT_NUM,
}
used_ports = shared_utils.get_port_specs(used_port_assignments)
cmd = [
"besu",
]
if log_level != "CUSTOM":
cmd.append("--logging=" + log_level)
cmd += [
"--data-path=" + EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER,
"--host-allowlist=*",
"--rpc-http-enabled=true",
"--rpc-http-host=0.0.0.0",
"--rpc-http-port={0}".format(RPC_PORT_NUM),
"--rpc-http-api=ADMIN,ETH,NET,DEBUG,TXPOOL,ENGINE,TRACE,WEB3",
"--rpc-http-cors-origins=*",
"--rpc-http-max-active-connections=300",
"--rpc-ws-enabled=true",
"--rpc-ws-host=0.0.0.0",
"--rpc-ws-port={0}".format(WS_PORT_NUM),
"--rpc-ws-api=ADMIN,ETH,NET,DEBUG,TXPOOL,ENGINE,TRACE,WEB3",
"--p2p-enabled=true",
"--p2p-host=" + port_publisher.el_nat_exit_ip,
"--p2p-port={0}".format(discovery_port_tcp),
"--discovery-mode=V5",
"--engine-rpc-enabled=true",
"--engine-jwt-secret=" + constants.JWT_MOUNT_PATH_ON_CONTAINER,
"--engine-host-allowlist=*",
"--engine-rpc-port={0}".format(ENGINE_HTTP_RPC_PORT_NUM),
"{0}".format(
"--sync-mode=FULL"
if network_params.network in constants.NETWORK_NAME.kurtosis
or participant.el_storage_type == "archive"
else "--sync-mode=SNAP"
),
"--metrics-enabled=true",
"--metrics-host=0.0.0.0",
"--metrics-port={0}".format(METRICS_PORT_NUM),
"--min-gas-price=1000000000",
]
# Configure storage type - besu defaults to full (BONSAI), use FOREST for archive
if participant.el_storage_type == "archive":
cmd.append("--data-storage-format=FOREST")
if network_params.gas_limit > 0:
cmd.append("--target-gas-limit={0}".format(network_params.gas_limit))
if network_params.network not in constants.PUBLIC_NETWORKS:
cmd.append(
"--genesis-file="
+ constants.GENESIS_CONFIG_MOUNT_PATH_ON_CONTAINER
+ "/besu.json"
)
else:
cmd.append("--network=" + network_params.network)
# Handle bootnode configuration with bootnodoor_el_enr override
if bootnodoor_el_enr != None:
cmd.append("--bootnodes=" + bootnodoor_el_enr)
elif (
network_params.network == constants.NETWORK_NAME.kurtosis
or constants.NETWORK_NAME.shadowfork in network_params.network
):
el_bootnode_enrs = [
ctx.enr
for ctx in existing_el_clients[: constants.MAX_ENODE_ENTRIES]
if ctx.enr
]
if len(el_bootnode_enrs) > 0:
cmd.append("--bootnodes=" + ",".join(el_bootnode_enrs))
elif (
network_params.network not in constants.PUBLIC_NETWORKS
and constants.NETWORK_NAME.shadowfork not in network_params.network
):
cmd.append(
"--bootnodes="
+ shared_utils.get_devnet_el_enrs(
plan, launcher.el_cl_genesis_data.files_artifact_uuid
)
)
if len(participant.el_extra_params) > 0:
# we do this as extra_params isn't a normal [] but a proto repeated array
cmd.extend([param for param in participant.el_extra_params])
cmd_str = " ".join(cmd)
env_vars = (
shared_utils.with_otel_env_vars(
participant.el_extra_env_vars,
otel_otlp_grpc_url,
service_name,
)
| JAVA_OPTS
)
files = {
constants.GENESIS_DATA_MOUNTPOINT_ON_CLIENTS: launcher.el_cl_genesis_data.files_artifact_uuid,
constants.JWT_MOUNTPOINT_ON_CLIENTS: launcher.jwt_file,
}
if persistent:
volume_size_key = (
"devnets" if "devnet" in network_params.network else network_params.network
)
files[EXECUTION_DATA_DIRPATH_ON_CLIENT_CONTAINER] = Directory(
persistent_key="data-{0}".format(service_name),
size=int(participant.el_volume_size)
if int(participant.el_volume_size) > 0
else constants.VOLUME_SIZE[volume_size_key][
constants.EL_TYPE.besu + "_volume_size"
],
)
# Add extra mounts - automatically handle file uploads
processed_mounts = shared_utils.process_extra_mounts(
plan, participant.el_extra_mounts, extra_files_artifacts
)
for mount_path, artifact in processed_mounts.items():
files[mount_path] = artifact
# Binary injection - mount custom binary directory if provided
if el_binary_artifact != None:
files["/opt/bin"] = el_binary_artifact.artifact
# Copy injected binary to override default, then run original command
final_cmd_str = (
"cp /opt/bin/{0} /opt/besu/bin/besu && ".format(el_binary_artifact.filename)
+ cmd_str
)
else:
final_cmd_str = cmd_str
config_args = {
"image": participant.el_image,
"ports": used_ports,
"public_ports": public_ports,
"publish_udp": port_publisher.el_enabled,
"cmd": [final_cmd_str],
"files": files,
"entrypoint": ENTRYPOINT_ARGS,
"private_ip_address_placeholder": constants.PRIVATE_IP_ADDRESS_PLACEHOLDER,
"env_vars": env_vars,
"labels": shared_utils.label_maker(
client=constants.EL_TYPE.besu,
client_type=constants.CLIENT_TYPES.el,
image=participant.el_image[-constants.MAX_LABEL_LENGTH :],
connected_client=cl_client_name,
extra_labels=participant.el_extra_labels
| {constants.NODE_INDEX_LABEL_KEY: str(participant_index + 1)},
supernode=participant.supernode,
),
"user": User(uid=0, gid=0),
"tolerations": tolerations,
"node_selectors": node_selectors,
}
if participant.el_min_cpu > 0:
config_args["min_cpu"] = participant.el_min_cpu
if participant.el_max_cpu > 0:
config_args["max_cpu"] = participant.el_max_cpu
if participant.el_min_mem > 0:
config_args["min_memory"] = participant.el_min_mem
if participant.el_max_mem > 0:
config_args["max_memory"] = participant.el_max_mem
if len(participant.el_devices) > 0:
config_args["devices"] = participant.el_devices
return ServiceConfig(**config_args)
# makes request to [service_name] for enode and returns a full el_context
def get_el_context(
plan,
service_name,
service,
launcher,
):
enode, enr = el_admin_node_info.get_enode_enr_for_node(
plan, service_name, constants.RPC_PORT_ID
)
metrics_url = "{0}:{1}".format(service.name, METRICS_PORT_NUM)
besu_metrics_info = node_metrics.new_node_metrics_info(
service_name, METRICS_PATH, metrics_url
)
http_url = "http://{0}:{1}".format(service.name, RPC_PORT_NUM)
ws_url = "ws://{0}:{1}".format(service.name, WS_PORT_NUM)
return el_context.new_el_context(
client_name="besu",
enode=enode,
dns_name=service.name,
rpc_port_num=RPC_PORT_NUM,
ws_port_num=WS_PORT_NUM,
engine_rpc_port_num=ENGINE_HTTP_RPC_PORT_NUM,
rpc_http_url=http_url,
ws_url=ws_url,
service_name=service_name,
el_metrics_info=[besu_metrics_info],
ip_addr=service.ip_address,
enr=enr,
)
def new_besu_launcher(el_cl_genesis_data, jwt_file):
return struct(
el_cl_genesis_data=el_cl_genesis_data,
jwt_file=jwt_file,
)