-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon.sh
More file actions
264 lines (233 loc) · 8.71 KB
/
common.sh
File metadata and controls
264 lines (233 loc) · 8.71 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
#!/bin/bash
function save_cwd() {
original_cwd=$(pwd)
}
function recover_cwd() {
cd $original_cwd
}
function prelude() {
save_cwd
# Get the directory of the script
local script_dir=$(dirname "$(realpath "$0")")
cd $script_dir
opup_script_path="$script_dir/opup.sh"
# working directory is the parent directory
cd ..
}
function postlude() {
recover_cwd
}
function start_da_server() {
pushd da-server
cat <<EOF | jq . > config.json
{
"SequencerIP": "127.0.0.1",
"ListenAddr": "0.0.0.0:8888",
"StorePath": "${PWD}/da/data"
}
EOF
popd
screen -d -m -S "da-server" bash -c "$opup_script_path da"
}
function start_op_services() {
if [ "$EL_CLIENT" = "geth" ]; then
screen -d -m -S "op-geth" bash -c "$opup_script_path geth"
else
screen -d -m -S "op-reth" bash -c "$opup_script_path reth"
fi
screen -d -m -S "op-node" bash -c "$opup_script_path node"
screen -d -m -S "op-batcher" bash -c "$opup_script_path batcher"
screen -d -m -S "op-proposer" bash -c "$opup_script_path proposer"
if [ -n "${CHALLENGER}" ]; then
screen -d -m -S "op-challenger" bash -c "$opup_script_path challenger"
fi
}
function start_explorer() {
screen -d -m -S "blockscout" bash -c "$opup_script_path blockscout"
}
function activate_direnv() {
eval "$(direnv export bash)"
}
function replace_string() {
local file=$1
local a=$2
local b=$3
local separator="${4:-/}"
sed_replace "s$separator$a$separator$b$separator" $file
}
function replace_env_value() {
file=$1
key=$2
value=$3
sed_replace "s#$key=.*#$key=$value#" $file
}
# for compatibility between macOS and linux
function sed_replace() {
cmd=$1
file=$2
if [[ "$(uname)" == "Linux" ]]; then
sed -i "$cmd" $file
else
sed -i '' "$cmd" $file
fi
}
function replace_env_value_or_insert() {
file=$1
key=$2
value=$3
sed_replace "s#$key=.*#$key=$value#" $file
if ! grep -q "$key=" $file; then
# if the 4th parameter is set, do not export
if [ -n "$4" ]; then
echo "$key=$value" >> $file
else
echo "export $key=$value" >> $file
fi
fi
}
function replace_all() {
file=$1
a=$2
b=$3
sed_replace "s#$a#$b#g" $file
}
function open_with_lineno() {
f=$1
vi -c "set number" $f
}
function config_explorer() {
echo "Ready to deploy explorer..."
hostIP=$(ip route get 8.8.8.8 | awk '{print $7; exit}')
prompt "Please review the environment variables in "common-frontend.env", finish by quiting the editor.
Press Enter to continue..."
pushd optimism
activate_direnv
l2ChainID=$L2_CHAIN_ID
popd
pushd blockscout
replace_string docker-compose/envs/common-blockscout.env "# CHAIN_ID=" "CHAIN_ID=$l2ChainID"
replace_env_value docker-compose/envs/common-blockscout.env "NFT_MEDIA_HANDLER_ENABLED" "false"
replace_string docker-compose/envs/common-blockscout.env "# CHAIN_TYPE=" "CHAIN_TYPE=optimism"
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_API_HOST" $hostIP
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_STATS_API_HOST" "http://$hostIP:8080"
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_APP_HOST" $hostIP
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_NETWORK_ID" $l2ChainID
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_VISUALIZE_API_HOST" "http://$hostIP:8081"
replace_env_value_or_insert docker-compose/envs/common-frontend.env "NEXT_PUBLIC_NETWORK_RPC_URL" "http://$hostIP:8545" 1
# FYI, these 3 envs are necessary to show L1 fee: https://github.com/blockscout/frontend/blob/main/docs/ENVS.md#rollup-chain
replace_env_value_or_insert docker-compose/envs/common-frontend.env "NEXT_PUBLIC_ROLLUP_TYPE" "'optimistic'" 1
# TODO set real value for NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL
replace_env_value_or_insert docker-compose/envs/common-frontend.env "NEXT_PUBLIC_ROLLUP_L2_WITHDRAWAL_URL" "https://example.com" 1
replace_env_value_or_insert docker-compose/envs/common-frontend.env "NEXT_PUBLIC_ROLLUP_L1_BASE_URL" "https://sepolia.etherscan.io/" 1
replace_all docker-compose/proxy/default.conf.template "add_header 'Access-Control-Allow-Origin' 'http://localhost' always;" "add_header 'Access-Control-Allow-Origin' '*' always;"
if [ -n "${ES}" ]; then
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_NETWORK_CURRENCY_NAME" QKC
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_NETWORK_CURRENCY_SYMBOL" QKC
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_NETWORK_NAME" "Super world computer"
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_NETWORK_SHORT_NAME" "Super world computer"
fi
if [ -n "${MAINNET}" ]; then
replace_env_value docker-compose/envs/common-frontend.env "NEXT_PUBLIC_IS_TESTNET" "false"
fi
open_with_lineno docker-compose/envs/common-frontend.env
# if 8081(kurtosis uses this port) is already in use, switch to 8088 instead
# TODO make it more clever maybe
if netstat -tuln | grep ":8081"; then
replace_all docker-compose/envs/common-frontend.env 8081 8088
replace_all docker-compose/proxy/default.conf.template 8081 8088
replace_all docker-compose/proxy/microservices.conf.template 8081 8088
replace_all docker-compose/services/nginx.yml 8081 8088
fi
popd
}
function save_to_session_history() {
local session=${STY##*.}
echo "$@" >> "$session.history"
}
function remote_signer_flags() {
endpoint=$1
address=$2
tlsCa=$3
tlsCert=$4
tlsKey=$5
shift 5
local headers=""
for arg in "$@"; do
headers+="--signer.header $arg "
done
echo "--signer.endpoint $endpoint --signer.address $address --signer.tls.ca $tlsCa --signer.tls.cert $tlsCert --signer.tls.key $tlsKey $headers --signer.tls.enabled"
}
function l1_admin_address() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "$GS_ADMIN_ADDRESS"
else
jq -r '.l1admin.address' $REMOTE_CONFIG_JSON
fi
}
function l2_admin_address() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "$GS_ADMIN_ADDRESS"
else
jq -r '.l2admin.address' $REMOTE_CONFIG_JSON
fi
}
function batcher_pk_flags() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "--private-key=$GS_BATCHER_PRIVATE_KEY"
else
endpoint=$(jq -r '.batcher.endpoint' $REMOTE_CONFIG_JSON)
address=$(jq -r '.batcher.address' $REMOTE_CONFIG_JSON)
tlsCa=$(jq -r '.batcher.tlsca' $REMOTE_CONFIG_JSON)
tlsCert=$(jq -r '.batcher.tlscert' $REMOTE_CONFIG_JSON)
tlsKey=$(jq -r '.batcher.tlskey' $REMOTE_CONFIG_JSON)
headers=$(jq -r '.batcher.headers // [] | @tsv' $REMOTE_CONFIG_JSON)
remote_signer_flags $endpoint $address $tlsCa $tlsCert $tlsKey ${headers[@]}
fi
}
function proposer_pk_flags() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "--private-key=$GS_PROPOSER_PRIVATE_KEY"
else
endpoint=$(jq -r '.proposer.endpoint' $REMOTE_CONFIG_JSON)
address=$(jq -r '.proposer.address' $REMOTE_CONFIG_JSON)
tlsCa=$(jq -r '.proposer.tlsca' $REMOTE_CONFIG_JSON)
tlsCert=$(jq -r '.proposer.tlscert' $REMOTE_CONFIG_JSON)
tlsKey=$(jq -r '.proposer.tlskey' $REMOTE_CONFIG_JSON)
headers=$(jq -r '.proposer.headers // [] | @tsv' $REMOTE_CONFIG_JSON)
remote_signer_flags $endpoint $address $tlsCa $tlsCert $tlsKey ${headers[@]}
fi
}
function challenger_pk_flags() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "--private-key=$GS_CHALLENGER_PRIVATE_KEY"
else
endpoint=$(jq -r '.challenger.endpoint' $REMOTE_CONFIG_JSON)
address=$(jq -r '.challenger.address' $REMOTE_CONFIG_JSON)
tlsCa=$(jq -r '.challenger.tlsca' $REMOTE_CONFIG_JSON)
tlsCert=$(jq -r '.challenger.tlscert' $REMOTE_CONFIG_JSON)
tlsKey=$(jq -r '.challenger.tlskey' $REMOTE_CONFIG_JSON)
headers=$(jq -r '.challenger.headers // [] | @tsv' $REMOTE_CONFIG_JSON)
remote_signer_flags $endpoint $address $tlsCa $tlsCert $tlsKey ${headers[@]}
fi
}
function batcher_address() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "$GS_BATCHER_ADDRESS"
else
jq -r '.batcher.address' $REMOTE_CONFIG_JSON
fi
}
function proposer_address() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "$GS_PROPOSER_ADDRESS"
else
jq -r '.proposer.address' $REMOTE_CONFIG_JSON
fi
}
function challenger_address() {
if [ -z "$REMOTE_CONFIG_JSON" ]; then
echo "$GS_CHALLENGER_ADDRESS"
else
jq -r '.challenger.address' $REMOTE_CONFIG_JSON
fi
}