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
shared_utils = import_module("../shared_utils/shared_utils.star")
postgres = import_module("github.com/kurtosis-tech/postgres-package/main.star")
redis = import_module("github.com/kurtosis-tech/redis-package/main.star")
constants = import_module("../package_io/constants.star")
WEB_SERVICE_NAME = "blobscan-web"
API_SERVICE_NAME = "blobscan-api"
INDEXER_SERVICE_NAME = "blobscan-indexer"
SECRET_KEY = "supersecure"
WEB_HTTP_PORT_NUMBER = 3000
API_HTTP_PORT_NUMBER = 3001
WEB_PORTS = {
constants.HTTP_PORT_ID: shared_utils.new_port_spec(
WEB_HTTP_PORT_NUMBER,
shared_utils.TCP_PROTOCOL,
shared_utils.HTTP_APPLICATION_PROTOCOL,
)
}
API_PORTS = {
constants.HTTP_PORT_ID: shared_utils.new_port_spec(
API_HTTP_PORT_NUMBER,
shared_utils.TCP_PROTOCOL,
shared_utils.HTTP_APPLICATION_PROTOCOL,
)
}
ENTRYPOINT_ARGS = ["/bin/sh", "-c"]
# The min/max CPU/memory that blobscan-indexer can use
INDEX_MIN_CPU = 10
INDEX_MAX_CPU = 1000
INDEX_MIN_MEMORY = 32
INDEX_MAX_MEMORY = 1024
# The min/max CPU/memory that blobscan-api can use
API_MIN_CPU = 100
API_MAX_CPU = 1000
API_MIN_MEMORY = 1024
API_MAX_MEMORY = 2048
# The min/max CPU/memory that blobscan-web can use
WEB_MIN_CPU = 100
WEB_MAX_CPU = 1000
WEB_MIN_MEMORY = 512
WEB_MAX_MEMORY = 2048
# The min/max CPU/memory that postgres can use
POSTGRES_MIN_CPU = 10
POSTGRES_MAX_CPU = 1000
POSTGRES_MIN_MEMORY = 32
POSTGRES_MAX_MEMORY = 1024
# The min/max CPU/memory that redis can use
REDIS_MIN_CPU = 10
REDIS_MAX_CPU = 1000
REDIS_MIN_MEMORY = 32
REDIS_MAX_MEMORY = 1024
def launch_blobscan(
plan,
cl_contexts,
el_contexts,
network_id,
network_params,
persistent,
global_node_selectors,
port_publisher,
additional_service_index,
docker_cache_params,
):
node_selectors = global_node_selectors
beacon_node_rpc_uri = "{0}".format(cl_contexts[0].beacon_http_url)
execution_node_rpc_uri = "{0}".format(el_contexts[0].rpc_http_url)
postgres_output = postgres.run(
plan,
service_name="blobscan-postgres",
min_cpu=POSTGRES_MIN_CPU,
max_cpu=POSTGRES_MAX_CPU,
min_memory=POSTGRES_MIN_MEMORY,
max_memory=POSTGRES_MAX_MEMORY,
persistent=persistent,
node_selectors=node_selectors,
image=shared_utils.docker_cache_image_calc(
docker_cache_params, "library/postgres:alpine"
),
)
redis_output = redis.run(
plan,
service_name="blobscan-redis",
min_cpu=REDIS_MIN_CPU,
max_cpu=REDIS_MAX_CPU,
min_memory=REDIS_MIN_MEMORY,
max_memory=REDIS_MAX_MEMORY,
persistent=persistent,
node_selectors=node_selectors,
image=shared_utils.docker_cache_image_calc(
docker_cache_params, "library/redis:alpine"
),
)
api_config = get_api_config(
network_id,
postgres_output.url,
network_params.network,
redis_output.url,
node_selectors,
port_publisher,
additional_service_index,
docker_cache_params,
)
blobscan_config = plan.add_service(API_SERVICE_NAME, api_config)
blobscan_api_url = "http://{0}:{1}".format(
blobscan_config.ip_address, blobscan_config.ports[constants.HTTP_PORT_ID].number
)
web_config = get_web_config(
postgres_output.url,
network_params.network,
beacon_node_rpc_uri,
execution_node_rpc_uri,
node_selectors,
port_publisher,
additional_service_index,
docker_cache_params,
)
plan.add_service(WEB_SERVICE_NAME, web_config)
indexer_config = get_indexer_config(
beacon_node_rpc_uri,
blobscan_api_url,
execution_node_rpc_uri,
network_params.network,
node_selectors,
docker_cache_params,
)
plan.add_service(INDEXER_SERVICE_NAME, indexer_config)
def get_api_config(
network_id,
postgres_url,
network_name,
redis_url,
node_selectors,
port_publisher,
additional_service_index,
docker_cache_params,
):
IMAGE_NAME = "blossomlabs/blobscan-api:latest"
public_ports = shared_utils.get_additional_service_standard_public_port(
port_publisher,
constants.HTTP_PORT_ID,
additional_service_index,
0,
)
return ServiceConfig(
image=shared_utils.docker_cache_image_calc(
docker_cache_params,
IMAGE_NAME,
),
ports=API_PORTS,
public_ports=public_ports,
env_vars={
"CHAIN_ID": network_id,
"DATABASE_URL": postgres_url,
"REDIS_URI": redis_url,
"SECRET_KEY": SECRET_KEY,
"BLOBSCAN_API_PORT": str(API_HTTP_PORT_NUMBER),
"POSTGRES_STORAGE_ENABLED": "true",
"NETWORK_NAME": network_name
if network_name in constants.PUBLIC_NETWORKS
else "devnet",
},
ready_conditions=ReadyCondition(
recipe=GetHttpRequestRecipe(
port_id="http",
endpoint="/healthcheck",
),
field="code",
assertion="==",
target_value=200,
interval="5s",
timeout="120s",
),
min_cpu=API_MIN_CPU,
max_cpu=API_MAX_CPU,
min_memory=API_MIN_MEMORY,
max_memory=API_MAX_MEMORY,
node_selectors=node_selectors,
)
def get_web_config(
postgres_url,
network_name,
beacon_node_rpc,
execution_node_rpc,
node_selectors,
port_publisher,
additional_service_index,
docker_cache_params,
):
# TODO: https://github.com/kurtosis-tech/kurtosis/issues/1861
# Configure NEXT_PUBLIC_BEACON_BASE_URL and NEXT_PUBLIC_EXPLORER_BASE env vars
# once retrieving external URLs from services are supported in Kurtosis.
IMAGE_NAME = "blossomlabs/blobscan-web:latest"
public_ports = shared_utils.get_additional_service_standard_public_port(
port_publisher,
constants.HTTP_PORT_ID,
additional_service_index,
1,
)
return ServiceConfig(
image=shared_utils.docker_cache_image_calc(
docker_cache_params,
IMAGE_NAME,
),
ports=WEB_PORTS,
public_ports=public_ports,
env_vars={
"DATABASE_URL": postgres_url,
"NEXT_PUBLIC_NETWORK_NAME": network_name
if network_name in constants.PUBLIC_NETWORKS
else "devnet",
"SECRET_KEY": SECRET_KEY,
"POSTGRES_STORAGE_ENABLED": "true",
},
min_cpu=WEB_MIN_CPU,
max_cpu=WEB_MAX_CPU,
min_memory=WEB_MIN_MEMORY,
max_memory=WEB_MAX_MEMORY,
node_selectors=node_selectors,
)
def get_indexer_config(
beacon_node_rpc,
blobscan_api_url,
execution_node_rpc,
network_name,
node_selectors,
docker_cache_params,
):
IMAGE_NAME = "blossomlabs/blobscan-indexer:master"
return ServiceConfig(
image=shared_utils.docker_cache_image_calc(
docker_cache_params,
IMAGE_NAME,
),
env_vars={
"BEACON_NODE_ENDPOINT": beacon_node_rpc,
"BLOBSCAN_API_ENDPOINT": blobscan_api_url,
"EXECUTION_NODE_ENDPOINT": execution_node_rpc,
"NETWORK_NAME": network_name
if network_name in constants.PUBLIC_NETWORKS
else "devnet",
"SECRET_KEY": SECRET_KEY,
},
entrypoint=ENTRYPOINT_ARGS,
cmd=[" && ".join(["sleep 90", "/app/blob-indexer"])],
min_cpu=INDEX_MIN_CPU,
max_cpu=INDEX_MAX_CPU,
min_memory=INDEX_MIN_MEMORY,
max_memory=INDEX_MAX_MEMORY,
node_selectors=node_selectors,
)