-
Notifications
You must be signed in to change notification settings - Fork 76
/
cdk_bridge_infra.star
116 lines (103 loc) · 4.34 KB
/
cdk_bridge_infra.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
zkevm_bridge_package = import_module("./lib/zkevm_bridge.star")
databases = import_module("./databases.star")
def run(plan, args, contract_setup_addresses):
db_configs = databases.get_db_configs(
args["deployment_suffix"], args["sequencer_type"]
)
# Start the bridge service.
bridge_config_artifact = create_bridge_config_artifact(
plan, args, contract_setup_addresses, db_configs
)
claimtx_keystore_artifact = plan.store_service_files(
name="claimtxmanager-keystore",
service_name="contracts" + args["deployment_suffix"],
src="/opt/zkevm/claimtxmanager.keystore",
)
bridge_service_config = zkevm_bridge_package.create_bridge_service_config(
args, bridge_config_artifact, claimtx_keystore_artifact
)
plan.add_service(
name="zkevm-bridge-service" + args["deployment_suffix"],
config=bridge_service_config,
)
# Start the bridge UI.
bridge_ui_config_artifact = create_bridge_ui_config_artifact(
plan, args, contract_setup_addresses
)
zkevm_bridge_package.start_bridge_ui(plan, args, bridge_ui_config_artifact)
# Start the bridge UI reverse proxy. This is only relevant / needed if we have a fake l1
if args["use_local_l1"]:
proxy_config_artifact = create_reverse_proxy_config_artifact(plan, args)
zkevm_bridge_package.start_reverse_proxy(plan, args, proxy_config_artifact)
def create_bridge_config_artifact(plan, args, contract_setup_addresses, db_configs):
bridge_config_template = read_file(
src="./templates/bridge-infra/bridge-config.toml"
)
return plan.render_templates(
name="bridge-config-artifact",
config={
"bridge-config.toml": struct(
template=bridge_config_template,
data={
"deployment_suffix": args["deployment_suffix"],
"global_log_level": args["global_log_level"],
"l1_rpc_url": args["l1_rpc_url"],
"l2_rpc_name": args["l2_rpc_name"],
"zkevm_l2_keystore_password": args["zkevm_l2_keystore_password"],
# ports
"zkevm_bridge_grpc_port": args["zkevm_bridge_grpc_port"],
"zkevm_bridge_rpc_port": args["zkevm_bridge_rpc_port"],
"zkevm_rpc_http_port": args["zkevm_rpc_http_port"],
}
| contract_setup_addresses
| db_configs,
)
},
)
def create_bridge_ui_config_artifact(plan, args, contract_setup_addresses):
bridge_ui_config_template = read_file("./templates/bridge-infra/.env")
return plan.render_templates(
name="bridge-ui-config-artifact",
config={
".env": struct(
template=bridge_ui_config_template,
data={
"l1_explorer_url": args["l1_explorer_url"],
"zkevm_explorer_url": args["polygon_zkevm_explorer"],
}
| contract_setup_addresses,
)
},
)
def create_reverse_proxy_config_artifact(plan, args):
bridge_ui_proxy_config_template = read_file(
src="./templates/bridge-infra/haproxy.cfg"
)
l1rpc_service = plan.get_service("el-1-geth-lighthouse")
l2rpc_service = plan.get_service(
name=args["l2_rpc_name"] + args["deployment_suffix"]
)
bridge_service = plan.get_service(
name="zkevm-bridge-service" + args["deployment_suffix"]
)
bridgeui_service = plan.get_service(
name="zkevm-bridge-ui" + args["deployment_suffix"]
)
return plan.render_templates(
name="bridge-ui-proxy",
config={
"haproxy.cfg": struct(
template=bridge_ui_proxy_config_template,
data={
"l1rpc_ip": l1rpc_service.ip_address,
"l1rpc_port": l1rpc_service.ports["rpc"].number,
"l2rpc_ip": l2rpc_service.ip_address,
"l2rpc_port": l2rpc_service.ports["rpc"].number,
"bridgeservice_ip": bridge_service.ip_address,
"bridgeservice_port": bridge_service.ports["rpc"].number,
"bridgeui_ip": bridgeui_service.ip_address,
"bridgeui_port": bridgeui_service.ports["web-ui"].number,
},
)
},
)