-
Notifications
You must be signed in to change notification settings - Fork 97
Expand file tree
/
Copy pathinput_parser.star
More file actions
79 lines (63 loc) · 2.54 KB
/
input_parser.star
File metadata and controls
79 lines (63 loc) · 2.54 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
_filter = import_module("/src/util/filter.star")
_net = import_module("/src/util/net.star")
_registry = import_module("/src/package_io/registry.star")
_DEFAULT_ARGS = {
"enabled": False,
"image": None,
# At the moment we only support rollup-boost
"type": "rollup-boost",
"builder_host": None,
"builder_port": None,
"builder_timeout": "1000",
"l2_timeout": "1000",
}
_IMAGE_IDS = {
"rollup-boost": _registry.ROLLUP_BOOST,
}
def parse(mev_args, network_params, participant_name, participant_index, registry):
network_id = network_params.network_id
network_name = network_params.name
# This string keep repeating in the error messages
mev_log_string = "{} on network {}".format(participant_name, network_name)
# Any extra attributes will cause an error
_filter.assert_keys(
mev_args or {},
_DEFAULT_ARGS.keys(),
"Invalid attributes in MEV configuration for " + mev_log_string + ": {}",
)
# We filter the None values so that we can merge dicts easily
mev_params = _DEFAULT_ARGS | _filter.remove_none(mev_args or {})
if not mev_params["enabled"]:
return None
# Now we check that we either have none or both of builder_host & builder_port
if mev_params["builder_host"] and not mev_params["builder_port"]:
fail("Missing builder_port in MEV configuration for {}".format(mev_log_string))
elif not mev_params["builder_host"] and mev_params["builder_port"]:
fail("Missing builder_host in MEV configuration for {}".format(mev_log_string))
# And default the image to the one in the registry
mev_params["image"] = mev_params["image"] or _default_image(
mev_params["type"], registry
)
# Add the service name
mev_params["service_name"] = "op-mev-{}-{}-{}-{}".format(
mev_params["type"], network_id, network_name, participant_name
)
# Add a bunch of labels
mev_params["labels"] = {
"op.kind": "mev",
"op.network.id": str(network_id),
"op.mev.type": mev_params["type"],
"op.network.participant.index": str(participant_index),
"op.network.participant.name": participant_name,
}
# Add ports
mev_params["ports"] = {
_net.RPC_PORT_NAME: _net.port(number=8551),
_net.WS_PORT_NAME: _net.port(number=1112, application_protocol="ws"),
}
return struct(**mev_params)
def _default_image(mev_type, registry):
if mev_type in _IMAGE_IDS:
return registry.get(_IMAGE_IDS[mev_type])
else:
fail("Invalid MEV type: {}".format(mev_type))