-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal_node.sh
More file actions
executable file
·348 lines (295 loc) · 14.6 KB
/
local_node.sh
File metadata and controls
executable file
·348 lines (295 loc) · 14.6 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
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
#!/bin/bash
CHAINID="${CHAIN_ID:-10740}"
MONIKER="ogevmdevnettest"
# Remember to change to other types of keyring like 'file' in-case exposing to outside world,
# otherwise your balance will be wiped quickly
# The keyring test does not require private key to steal tokens from you
KEYRING="test"
KEYALGO="eth_secp256k1"
LOGLEVEL="info"
# Set dedicated home directory for the evmd instance
CHAINDIR="$HOME/.og-evm-devnet"
BASEFEE=10000000
# Path variables
CONFIG_TOML=$CHAINDIR/config/config.toml
APP_TOML=$CHAINDIR/config/app.toml
GENESIS=$CHAINDIR/config/genesis.json
TMP_GENESIS=$CHAINDIR/config/tmp_genesis.json
# validate dependencies are installed
command -v jq >/dev/null 2>&1 || {
echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"
exit 1
}
# used to exit on first error (any non-zero exit code)
set -e
# ------------- Flags -------------
install=true
overwrite=""
BUILD_FOR_DEBUG=false
ADDITIONAL_USERS=0
MNEMONIC_FILE="" # output file (defaults later to $CHAINDIR/mnemonics.yaml)
MNEMONICS_INPUT="" # input yaml to prefill dev keys
usage() {
cat <<EOF
Usage: $0 [options]
Options:
-y Overwrite existing chain data without prompt
-n Do not overwrite existing chain data
--no-install Skip 'make install'
--remote-debugging Build with nooptimization,nostrip
--additional-users N Create N extra users: dev4, dev5, ...
--mnemonic-file PATH Where to write mnemonics YAML (default: \$HOME/.evmd/mnemonics.yaml)
--mnemonics-input PATH Read dev mnemonics from a yaml file (key: mnemonics:)
EOF
}
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-y)
echo "Flag -y passed -> Overwriting the previous chain data."
overwrite="y"; shift
;;
-n)
echo "Flag -n passed -> Not overwriting the previous chain data."
overwrite="n"; shift
;;
--no-install)
echo "Flag --no-install passed -> Skipping installation of the evmd binary."
install=false; shift
;;
--remote-debugging)
echo "Flag --remote-debugging passed -> Building with remote debugging options."
BUILD_FOR_DEBUG=true; shift
;;
--additional-users)
if [[ -z "${2:-}" || "$2" =~ ^- ]]; then
echo "Error: --additional-users requires a number."; usage; exit 1
fi
ADDITIONAL_USERS="$2"; shift 2
;;
--mnemonic-file)
if [[ -z "${2:-}" || "$2" =~ ^- ]]; then
echo "Error: --mnemonic-file requires a path."; usage; exit 1
fi
MNEMONIC_FILE="$2"; shift 2
;;
--mnemonics-input)
if [[ -z "${2:-}" || "$2" =~ ^- ]]; then
echo "Error: --mnemonics-input requires a path."; usage; exit 1
fi
MNEMONICS_INPUT="$2"; shift 2
;;
-h|--help)
usage; exit 0
;;
*)
echo "Unknown flag passed: $key -> Aborting"; usage; exit 1
;;
esac
done
if [[ -n "$MNEMONICS_INPUT" && "$ADDITIONAL_USERS" -gt 0 ]]; then
echo "Error: --mnemonics-input and --additional-users cannot be used together."
echo "Use --mnemonics-input to provide all dev account mnemonics, or use --additional-users to generate extra accounts."
exit 1
fi
if [[ $install == true ]]; then
if [[ $BUILD_FOR_DEBUG == true ]]; then
# for remote debugging the optimization should be disabled and the debug info should not be stripped
make install COSMOS_BUILD_OPTIONS=nooptimization,nostrip
else
make install
fi
fi
# User prompt if neither -y nor -n was passed as a flag
# and an existing local node configuration is found.
if [[ $overwrite = "" ]]; then
if [ -d "$CHAINDIR" ]; then
printf "\nAn existing folder at '%s' was found. You can choose to delete this folder and start a new local node with new keys from genesis. When declined, the existing local node is started. \n" "$CHAINDIR"
echo "Overwrite the existing configuration and start a new local node? [y/n]"
read -r overwrite
else
overwrite="y"
fi
fi
# ---------- YAML reader ----------
# reads a simple yaml with:
# mnemonics:
# - "phrase here"
# - another phrase
read_mnemonics_yaml() {
local file="$1"
awk '
BEGIN { inlist=0 }
/^[[:space:]]*mnemonics:[[:space:]]*$/ { inlist=1; next }
inlist && /^[[:space:]]*-[[:space:]]*/ {
line=$0
sub(/^[[:space:]]*-[[:space:]]*/, "", line)
gsub(/^"[[:space:]]*|[[:space:]]*"$/, "", line)
gsub(/^'\''[[:space:]]*|[[:space:]]*'\''$/, "", line)
print line
next
}
inlist && NF==0 { next }
' "$file"
}
# ---------- yaml writer ----------
write_mnemonics_yaml() {
local file_path="$1"; shift
local -a mns=("$@")
mkdir -p "$(dirname "$file_path")"
{
echo "mnemonics:"
for m in "${mns[@]}"; do
printf ' - "%s"\n' "$m"
done
} > "$file_path"
echo "Wrote mnemonics to $file_path"
}
# ---------- Add funded account ----------
add_genesis_funds() {
local keyname="$1"
evmd genesis add-genesis-account "$keyname" 10000000000000000000000ogwei --keyring-backend "$KEYRING" --home "$CHAINDIR"
}
# Setup local node if overwrite is set to Yes, otherwise skip setup
if [[ $overwrite == "y" || $overwrite == "Y" ]]; then
rm -rf "$CHAINDIR"
evmd config set client chain-id "$CHAINID" --home "$CHAINDIR"
evmd config set client keyring-backend "$KEYRING" --home "$CHAINDIR"
# ---------------- Validator key ----------------
VAL_KEY="mykey"
VAL_MNEMONIC="gesture inject test cycle original hollow east ridge hen combine junk child bacon zero hope comfort vacuum milk pitch cage oppose unhappy lunar seat"
echo "$VAL_MNEMONIC" | evmd keys add "$VAL_KEY" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
# ---------------- dev mnemonics source ----------------
# dev0 address 0xC6Fe5D33615a1C52c08018c47E8Bc53646A0E101 | og1cml96vmptgw99syqrrz8az79xer2pcgpum8mp7
# dev0's private key: 0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305 # gitleaks:allow
# dev1 address 0x963EBDf2e1f8DB8707D05FC75bfeFFBa1B5BaC17 | og1jcltmuhplrdcwp7stlr4hlhlhgd4htqhgdvy48
# dev1's private key: 0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544 # gitleaks:allow
# dev2 address 0x40a0cb1C63e026A81B55EE1308586E21eec1eFa9 | og1gzsvk8rruqn2sx64acfsskrwy8hvrmafykhkwv
# dev2's private key: 0x3b7955d25189c99a7468192fcbc6429205c158834053ebe3f78f4512ab432db9 # gitleaks:allow
# dev3 address 0x498B5AeC5D439b733dC2F58AB489783A23FB26dA | og1fx944mzagwdhx0wz7k9tfztc8g3lkfk6nt6hpj
# dev3's private key: 0x8a36c69d940a92fcea94b36d0f2928c7a0ee19a90073eda769693298dfa9603b # gitleaks:allow
default_mnemonics=(
"copper push brief egg scan entry inform record adjust fossil boss egg comic alien upon aspect dry avoid interest fury window hint race symptom" # dev0
"maximum display century economy unlock van census kite error heart snow filter midnight usage egg venture cash kick motor survey drastic edge muffin visual" # dev1
"will wear settle write dance topic tape sea glory hotel oppose rebel client problem era video gossip glide during yard balance cancel file rose" # dev2
"doll midnight silk carpet brush boring pluck office gown inquiry duck chief aim exit gain never tennis crime fragile ship cloud surface exotic patch" # dev3
)
provided_mnemonics=()
if [[ -n "$MNEMONICS_INPUT" ]]; then
if [[ ! -f "$MNEMONICS_INPUT" ]]; then
echo "mnemonics input file not found: $MNEMONICS_INPUT"; exit 1
fi
tmpfile="$(mktemp -t mnemonics.XXXXXX)"
read_mnemonics_yaml "$MNEMONICS_INPUT" > "$tmpfile"
while IFS= read -r line; do
[[ -z "$line" ]] && continue
provided_mnemonics+=( "$line" )
done < "$tmpfile"
rm -f "$tmpfile"
if [[ ${#provided_mnemonics[@]} -eq 0 ]]; then
echo "no mnemonics found in $MNEMONICS_INPUT (expected a list under 'mnemonics:')"; exit 1
fi
fi
# choose base list: prefer provided over defaults
if [[ ${#provided_mnemonics[@]} -gt 0 ]]; then
echo "using provided mnemonics"
dev_mnemonics=("${provided_mnemonics[@]}")
else
echo "using default mnemonics"
dev_mnemonics=("${default_mnemonics[@]}")
fi
# init chain w/ validator mnemonic
echo "$VAL_MNEMONIC" | evmd init $MONIKER -o --chain-id "$CHAINID" --home "$CHAINDIR" --recover
# ---------- Genesis customizations ----------
jq '.app_state["staking"]["params"]["bond_denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["gov"]["deposit_params"]["min_deposit"][0]["denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["gov"]["params"]["min_deposit"][0]["denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["gov"]["params"]["expedited_min_deposit"][0]["denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["evm"]["params"]["evm_denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["mint"]["params"]["mint_denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["bank"]["denom_metadata"]=[{"description":"The native staking token for evmd.","denom_units":[{"denom":"ogwei","exponent":0,"aliases":[]},{"denom":"OPG","exponent":18,"aliases":[]}],"base":"ogwei","display":"OPG","name":"OpenGradient Token","symbol":"OPG","uri":"","uri_hash":""}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["evm"]["params"]["active_static_precompiles"]=["0x0000000000000000000000000000000000000100","0x0000000000000000000000000000000000000400","0x0000000000000000000000000000000000000800","0x0000000000000000000000000000000000000801","0x0000000000000000000000000000000000000802","0x0000000000000000000000000000000000000803","0x0000000000000000000000000000000000000804","0x0000000000000000000000000000000000000805", "0x0000000000000000000000000000000000000806", "0x0000000000000000000000000000000000000807", "0x0000000000000000000000000000000000000900"]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state["evm"]["params"]["evm_denom"]="ogwei"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state.erc20.native_precompiles=["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.app_state.erc20.token_pairs=[{contract_owner:1,erc20_address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",denom:"ogwei",enabled:true}]' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
jq '.consensus.params.block.max_gas="10000000"' "$GENESIS" >"$TMP_GENESIS" && mv "$TMP_GENESIS" "$GENESIS"
# Change proposal periods
sed -i.bak 's/"max_deposit_period": "172800s"/"max_deposit_period": "30s"/g' "$GENESIS"
sed -i.bak 's/"voting_period": "172800s"/"voting_period": "30s"/g' "$GENESIS"
sed -i.bak 's/"expedited_voting_period": "86400s"/"expedited_voting_period": "15s"/g' "$GENESIS"
# fund validator (devs already funded in the loop)
evmd genesis add-genesis-account "$VAL_KEY" 100000000000000000000000000ogwei --keyring-backend "$KEYRING" --home "$CHAINDIR"
# ---------- Config customizations ----------
sed -i.bak 's/timeout_propose = "3s"/timeout_propose = "2s"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_propose_delta = "500ms"/timeout_propose_delta = "200ms"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_prevote = "1s"/timeout_prevote = "500ms"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_prevote_delta = "500ms"/timeout_prevote_delta = "200ms"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_precommit = "1s"/timeout_precommit = "500ms"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_precommit_delta = "500ms"/timeout_precommit_delta = "200ms"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_commit = "5s"/timeout_commit = "1s"/g' "$CONFIG_TOML"
sed -i.bak 's/timeout_broadcast_tx_commit = "10s"/timeout_broadcast_tx_commit = "5s"/g' "$CONFIG_TOML"
# enable prometheus metrics and all APIs for dev node
sed -i.bak 's/prometheus = false/prometheus = true/' "$CONFIG_TOML"
sed -i.bak 's/prometheus-retention-time = "0"/prometheus-retention-time = "1000000000000"/g' "$APP_TOML"
sed -i.bak 's/enabled = false/enabled = true/g' "$APP_TOML"
sed -i.bak 's/enable = false/enable = true/g' "$APP_TOML"
sed -i.bak 's/enable-indexer = false/enable-indexer = true/g' "$APP_TOML"
# --------- maybe generate additional users ---------
# start with provided/default list
final_mnemonics=("${dev_mnemonics[@]}")
# default output path if not set
if [[ -z "$MNEMONIC_FILE" ]]; then
MNEMONIC_FILE="$CHAINDIR/mnemonics.yaml"
fi
# Process all dev mnemonics (provided or default)
for ((i=0; i<${#dev_mnemonics[@]}; i++)); do
keyname="dev${i}"
mnemonic="${dev_mnemonics[i]}"
echo "adding key for $keyname"
# Add key to keyring using the mnemonic
echo "$mnemonic" | evmd keys add "$keyname" --recover --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR"
# Fund the account in genesis
add_genesis_funds "$keyname"
done
if [[ "$ADDITIONAL_USERS" -gt 0 ]]; then
start_index=${#dev_mnemonics[@]} # continue after last provided/default entry
for ((i=0; i<ADDITIONAL_USERS; i++)); do
idx=$((start_index + i))
keyname="dev${idx}"
# create key and capture mnemonic
mnemonic_out="$(evmd keys add "$keyname" --keyring-backend "$KEYRING" --algo "$KEYALGO" --home "$CHAINDIR" 2>&1)"
# try to grab a line that looks like a seed phrase (>=12 words), else last line
user_mnemonic="$(echo "$mnemonic_out" | grep -E '([[:alpha:]]+[[:space:]]+){11,}[[:alpha:]]+$' | tail -1)"
if [[ -z "$user_mnemonic" ]]; then
user_mnemonic="$(echo "$mnemonic_out" | tail -n 1)"
fi
user_mnemonic="$(echo "$user_mnemonic" | tr -d '\r')"
if [[ -z "$user_mnemonic" ]]; then
echo "failed to capture mnemonic for $keyname"; exit 1
fi
final_mnemonics+=("$user_mnemonic")
add_genesis_funds "$keyname"
echo "created $keyname"
done
fi
# --------- Finalize genesis ---------
evmd genesis gentx "$VAL_KEY" 10000000000000000000000ogwei --gas-prices ${BASEFEE}ogwei --keyring-backend "$KEYRING" --chain-id "$CHAINID" --home "$CHAINDIR"
evmd genesis collect-gentxs --home "$CHAINDIR"
evmd genesis validate-genesis --home "$CHAINDIR"
# --------- Write YAML with mnemonics if the user specified more ---------
if [[ "$ADDITIONAL_USERS" -gt 0 ]]; then
write_mnemonics_yaml "$MNEMONIC_FILE" "${final_mnemonics[@]}"
fi
if [[ $1 == "pending" ]]; then
echo "pending mode is on, please wait for the first block committed."
fi
fi
# Start the node
evmd start "$TRACE" \
--pruning nothing \
--log_level $LOGLEVEL \
--minimum-gas-prices=0ogwei \
--evm.min-tip=0 \
--home "$CHAINDIR" \
--json-rpc.api eth,txpool,personal,net,debug,web3 \
--chain-id "$CHAINID"