-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.star
365 lines (297 loc) · 11.6 KB
/
main.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
SEI_IMAGE = "sei-chain/localnode"
SEI_PUBLISHED_IMAGE = "h4ck3rk3y/localnode:3.0.1"
SEI_NODE_PREFIX = "sei-node-"
SEI_DEFAULT_GIT_URL = "https://github.com/sei-protocol/sei-chain"
SEI_DEFAULT_GIT_REF = "3.0.4"
DEFAULT_CLUSTER_SIZE = 4
DEFAULT_NUM_ACCOUNTS = 10
DEFAULT_INVARIANT_CHECK_INTERVAL = 10
MAIN_BASE = "/sei-protocol/"
MAIN_DIR = MAIN_BASE + "sei-chain/"
PERSISTENT_PEERS_PATH = "build/generated/persistent_peers.txt"
GENESIS_ACCOUNTS_PATH = "build/generated/genesis_accounts.txt"
EXPORTED_KEYS_PATH = "build/generated/exported_keys/"
GENESIS_JSON_PATH = "build/generated/genesis.json"
GENTX_PATH = "build/generated/gentx/"
ZEROTH_NODE = 0
def run(plan , args):
image = args.get("image", SEI_PUBLISHED_IMAGE)
git_url = args.get("git_url", SEI_DEFAULT_GIT_URL)
git_ref = args.get("git_ref", SEI_DEFAULT_GIT_REF)
builds_image_live = args.get("builds_image_live", False)
if builds_image_live:
image = SEI_IMAGE
cluster_size = args.get("cluster_size", DEFAULT_CLUSTER_SIZE)
num_accounts = args.get("num_accounts", DEFAULT_NUM_ACCOUNTS)
invariant_check_interval = args.get("invariant_check_interval", DEFAULT_INVARIANT_CHECK_INTERVAL)
node_names = []
genesis_accounts = []
peers = []
configurer = plan.upload_files("github.com/kurtosis-tech/sei-package/static_files/configurer.sh")
genesis = plan.upload_files("github.com/kurtosis-tech/sei-package/static_files/genesis.sh")
step45 = plan.upload_files("github.com/kurtosis-tech/sei-package/static_files/step_4_and_5.sh")
step6 = plan.upload_files("github.com/kurtosis-tech/sei-package/static_files/step_6.sh")
built = build(plan, image, builds_image_live, git_url, git_ref)
for index in range(0, cluster_size):
env_vars_for_node = {}
env_vars_for_node["ID"] = str(index)
env_vars_for_node["CLUSTER_SIZE"] = str(cluster_size)
env_vars_for_node["NUM_ACCOUNTS"] = str(num_accounts)
env_vars_for_node["INVARIANT_CHECK_INTERVAL"] = str(invariant_check_interval)
config = ServiceConfig(
image = image,
env_vars = env_vars_for_node,
ports = {
"prometheus": PortSpec(number = 9090, wait = None),
"grpc-web": PortSpec(number = 9091, wait = None),
"tendermint-p2p": PortSpec(number = 26656, wait = None),
"tendermint-rpc": PortSpec(number = 26657, wait = None),
"abci-app": PortSpec(number = 26658, wait = None)
},
files = {
MAIN_BASE: built,
"/tmp/configurer": configurer,
"/tmp/genesis": genesis,
"/tmp/step45": step45,
"/tmp/step6": step6,
},
entrypoint = ["sleep", "9999999"]
)
name = SEI_NODE_PREFIX + str(index)
plan.add_service(
name = name,
config = config,
)
plan.exec(
service_name = name,
recipe = ExecRecipe(
command = ["mkdir", "/root/go/bin"],
)
)
plan.exec(
service_name = name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "go install github.com/CosmWasm/wasmvm"]
)
)
node_names.append(name)
for name in node_names:
plan.exec(
service_name = name,
recipe = ExecRecipe(
command = ["/tmp/configurer/configurer.sh"]
)
)
account = read_file_from_service(plan, name, GENESIS_ACCOUNTS_PATH)
peer = read_file_from_service(plan, name, PERSISTENT_PEERS_PATH)
genesis_accounts.append(account)
peers.append(peer)
# copy over genesis accounts to node0
plan.print("Copying over genesis accounts to {0}".format(node_names[ZEROTH_NODE]))
write_together_node0(plan, genesis_accounts, GENESIS_ACCOUNTS_PATH)
read_file_from_service_with_nl(plan, node_names[ZEROTH_NODE], GENESIS_ACCOUNTS_PATH)
# copy over persistent peers to node 0
plan.print("Concatenating {0} on all nodes".format(PERSISTENT_PEERS_PATH))
combine_file_over_nodes(plan, node_names, peers, PERSISTENT_PEERS_PATH)
# copy over exported keys to node 0
plan.print("Copying over all exported_keys to {0}".format(node_names[ZEROTH_NODE]))
for source_node in node_names[1:]:
copy_only_file_in_dir(plan, source_node, EXPORTED_KEYS_PATH, node_names[ZEROTH_NODE], EXPORTED_KEYS_PATH)
# copy over gentx to node 0
plan.print("Copying over all gentx to {0}".format(node_names[ZEROTH_NODE]))
for source_node in node_names[1:]:
copy_only_file_in_dir(plan, source_node, GENTX_PATH, node_names[ZEROTH_NODE], GENTX_PATH)
# verify exported keys
plan.print("Verifying exported keys on {0}".format(node_names[ZEROTH_NODE]))
plan.exec(
service_name = node_names[ZEROTH_NODE],
recipe = ExecRecipe(
command = ["ls", EXPORTED_KEYS_PATH],
)
)
# run step 2 & 3 on zero'th node
plan.print("Running Genesis on {0}".format(node_names[ZEROTH_NODE]))
plan.exec(
service_name = node_names[ZEROTH_NODE],
recipe = ExecRecipe(
command = ["/tmp/genesis/genesis.sh"],
)
)
copy_genesis_json_to_other_nodes(plan, node_names)
# run step 4 and 5 everywhere
for name in node_names:
plan.print("Running SIED node on {0}".format(name))
plan.exec(
service_name = name,
recipe = ExecRecipe(
command = ["/tmp/step45/step_4_and_5.sh"]
)
)
plan.print("Waiting for tendermint rpc port to be alive on every node before running price feeder")
wait_on_tendermint_rpc(plan, node_names)
# run step 6 after 4 & 5 are done at both places
for name in node_names:
plan.print("Running price feeder on node {0}".format(name))
plan.exec(
service_name = name,
recipe = ExecRecipe(
command = ["/tmp/step6/step_6.sh"]
)
)
plan.print("We wait for 20 seconds to make sure that the price feeder is healthy")
plan.exec(
service_name = node_names[ZEROTH_NODE],
recipe = ExecRecipe(
command = ["sleep", "20"]
)
)
print_some_logs(plan, node_names)
# print some logs on each node
def wait_on_tendermint_rpc(plan, node_names):
request_recipe = GetHttpRequestRecipe(
port_id = "tendermint-rpc",
endpoint = "/",
)
for name in node_names:
plan.wait(
service_name=name,
recipe=request_recipe,
field="code",
assertion="==",
target_value=200,
)
# print some logs on each node
def print_some_logs(plan, node_names):
for index, node in enumerate(node_names):
plan.exec(
service_name = node,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "tail -n 20 build/generated/logs/seid-{0}.log".format(index)]
)
)
plan.exec(
service_name = node,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "tail -n 20 build/generated/logs/price-feeder-{0}.log".format(index)]
)
)
# copies genesis.json from node0 to all other nodes
def copy_genesis_json_to_other_nodes(plan, node_names):
plan.exec(
service_name = node_names[ZEROTH_NODE],
recipe = ExecRecipe(
command = ["mkdir", "-p", "/tmp/genesis_json/"]
)
)
plan.exec(
service_name = node_names[ZEROTH_NODE],
recipe = ExecRecipe(
command = ["cp", GENESIS_JSON_PATH, "/tmp/genesis_json/"]
)
)
for target_node in node_names[1:]:
copy_only_file_in_dir(plan, node_names[ZEROTH_NODE], "/tmp/genesis_json/", target_node, "build/generated/")
# copies the only file in source dir to the target dir preserving its name
def copy_only_file_in_dir(plan, source_service_name, dir_name, target_service_name, target_dir_name):
filename_response = plan.exec(
service_name = source_service_name,
recipe = ExecRecipe(
command = ["ls", dir_name]
)
)
filename = filename_response["output"]
filedata = read_file_from_service_with_nl(plan, source_service_name, dir_name + filename)
plan.exec(
service_name = target_service_name,
recipe = ExecRecipe(command = ["/bin/sh", "-c", "echo -n '{0}' > {1}{2}".format(filedata, target_dir_name, filename)])
)
read_file_from_service_with_nl(plan, target_service_name, "{}{}".format(target_dir_name, filename))
# reads the given file in service without the new line
def read_file_from_service(plan, service_name, filename):
output = plan.exec(
service_name = service_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "cat {} | tr -d '\n'".format(filename)]
)
)
return output["output"]
# reads the given file from service with new lines
def read_file_from_service_with_nl(plan, service_name, filename):
output = plan.exec(
service_name = service_name,
recipe = ExecRecipe(
command = ["/bin/sh", "-c", "cat {}".format(filename)]
)
)
return output["output"]
# writes a given file on multiple nodes into one file on node0
def write_together_node0(plan, lines, filename):
for line in lines[1:]:
plan.exec(
service_name = "{}0".format(SEI_NODE_PREFIX),
recipe = ExecRecipe(command = ["/bin/sh", "-c", 'echo "{0}" >> {1}'.format(line, filename)])
)
# combines a file distributed accross nodes to a new file on node0
def combine_file_over_nodes(plan, node_names, lines, filename):
for index, target_node_name in enumerate(node_names):
for line in lines[0:index] + lines[index+1:]:
plan.exec(
service_name = target_node_name,
recipe = ExecRecipe(command = ["/bin/sh", "-c", 'echo "{0}" >> {1}'.format(line, filename)])
)
# we verify things were properly written
read_file_from_service_with_nl(plan, target_node_name, filename)
# This builds the binary and we throw this away
def build(plan, image, builds_image_live, git_url, git_ref):
cloner = plan.upload_files("github.com/kurtosis-tech/sei-package/static_files/cloner.sh")
builder = plan.upload_files("github.com/kurtosis-tech/sei-package/static_files/builder.sh")
plan.add_service(
name = "builder",
config = ServiceConfig(
image = image,
entrypoint = ["sleep", "999999"],
files = {
"/tmp/cloner": cloner,
"/tmp/builder": builder,
},
),
)
plan.exec(
service_name = "builder",
recipe = ExecRecipe(
command = ["/tmp/cloner/cloner.sh", git_url],
)
)
if not builds_image_live:
plan.exec(
service_name = "builder",
recipe = ExecRecipe(
command = ["git", "checkout", git_ref]
)
)
# remove the .git folder to trim down the directory
plan.exec(
service_name = "builder",
recipe = ExecRecipe(
command = ["rm", "-rf", ".git"]
)
)
# but git repo is required for scripts
plan.exec(
service_name = "builder",
recipe = ExecRecipe(
command = ["git", "init"]
)
)
plan.exec(
service_name = "builder",
recipe = ExecRecipe(
command = ["/tmp/builder/builder.sh"],
)
)
built = plan.store_service_files(
service_name = "builder",
src = MAIN_DIR
)
plan.remove_service("builder")
return built