-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest_node.sh
More file actions
executable file
·216 lines (174 loc) · 9.84 KB
/
Copy pathtest_node.sh
File metadata and controls
executable file
·216 lines (174 loc) · 9.84 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
#!/bin/bash
# Run this script to quickly install, setup, and run the current version of the network with Cosmovisor.
# Cosmovisor enables automatic binary upgrades during chain operation.
#
# Examples:
# CHAIN_ID="localchain_9000-1" HOME_DIR="~/.pchain" BLOCK_TIME="1000ms" CLEAN=true sh scripts/test_node.sh
# CHAIN_ID="localchain_9000-2" HOME_DIR="~/.pchain" CLEAN=true RPC=36657 REST=2317 PROFF=6061 P2P=36656 GRPC=8090 GRPC_WEB=8091 ROSETTA=8081 BLOCK_TIME="500ms" sh scripts/test_node.sh
shopt -s expand_aliases
set -eu
export KEY1="acc1"
export KEY2="acc2"
export KEY3="acc3"
export CHAIN_ID=${CHAIN_ID:-"localchain_9000-1"}
export MONIKER=${MONIKER:-"localvalidator"}
export KEYALGO="eth_secp256k1"
export KEYRING=${KEYRING:-"test"}
export HOME_DIR=$(eval echo "${HOME_DIR:-"~/.pchain"}")
export BINARY=${BINARY:-pchaind}
export DENOM=${DENOM:-upc}
export CLEAN=${CLEAN:-"false"}
export RPC=${RPC:-"26657"}
export REST=${REST:-"1317"}
export PROFF=${PROFF:-"6060"}
export P2P=${P2P:-"26656"}
export GRPC=${GRPC:-"9090"}
export GRPC_WEB=${GRPC_WEB:-"9091"}
export ROSETTA=${ROSETTA:-"8080"}
export BLOCK_TIME=${BLOCK_TIME:-"1s"}
# Cosmovisor environment
export DAEMON_NAME=$(basename "$BINARY")
export DAEMON_HOME=$HOME_DIR
export DAEMON_RESTART_AFTER_UPGRADE=true
export DAEMON_ALLOW_DOWNLOAD_BINARIES=${DAEMON_ALLOW_DOWNLOAD_BINARIES:-true}
export DAEMON_DOWNLOAD_MUST_HAVE_CHECKSUM=${DAEMON_DOWNLOAD_MUST_HAVE_CHECKSUM:-true}
export UNSAFE_SKIP_BACKUP=true
export DAEMON_RESTART_DELAY=5s
# Check if BINARY exists (either as command or file path)
if [ ! -x "$BINARY" ] && ! command -v "$BINARY" > /dev/null 2>&1; then
make install
if ! command -v "$BINARY" > /dev/null 2>&1; then
echo "Ensure $BINARY is installed and in your PATH"
exit 1
fi
fi
alias BINARY="$BINARY --home=$HOME_DIR"
# Verify binary is accessible
if [ ! -x "$BINARY" ] && ! command -v "$BINARY" > /dev/null 2>&1; then
echo >&2 "$BINARY command not found. Ensure this is setup / properly installed in your GOPATH (make install)."
exit 1
fi
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; }
set_config() {
$BINARY config set client chain-id $CHAIN_ID
$BINARY config set client keyring-backend $KEYRING
}
set_config
from_scratch () {
# Fresh install on current branch (skip if using external binary)
if [ ! -x "$BINARY" ]; then
make install
fi
# remove existing daemon files.
if [ ${#HOME_DIR} -le 2 ]; then
echo "HOME_DIR must be more than 2 characters long"
return
fi
rm -rf $HOME_DIR && echo "Removed $HOME_DIR"
# reset values if not set already after whipe
set_config
add_key() {
key=$1
mnemonic=$2
echo $mnemonic | BINARY keys add $key --keyring-backend $KEYRING --algo $KEYALGO --recover
}
# push1ss5j8c8j453uecnczt3ms23lze30kxt4pzfvh9
add_key $KEY1 "surface task term spring horse impact tortoise often session cable off catch harvest rain able jealous coral cargo portion surge spring genre mix avoid"
# push1j55s4vpvmncruakqhj2k2fywnc9mvsuhcap28q
add_key $KEY2 "season wing cost lunch leg absurd parent practice frost mistake choose leopard switch shrug wrist this pistol bright spike hurt fit meadow smart hazard"
# push1fgaewhyd9fkwtqaj9c233letwcuey6dgly9gv9
add_key $KEY3 "episode silver life middle tumble slogan genius loop divide alpha raven bridge drive calm club system school raccoon unfold marine oyster radio treat sphere"
BINARY init $MONIKER --chain-id $CHAIN_ID --default-denom $DENOM
update_test_genesis () {
cat $HOME_DIR/config/genesis.json | jq "$1" > $HOME_DIR/config/tmp_genesis.json && mv $HOME_DIR/config/tmp_genesis.json $HOME_DIR/config/genesis.json
}
# === CORE MODULES ===
# Block
update_test_genesis '.consensus_params["block"]["max_gas"]="100000000"'
# Gov
update_test_genesis `printf '.app_state["gov"]["params"]["min_deposit"]=[{"denom":"%s","amount":"1000000"}]' $DENOM`
update_test_genesis '.app_state["gov"]["params"]["voting_period"]="30s"'
update_test_genesis '.app_state["gov"]["params"]["expedited_voting_period"]="15s"'
update_test_genesis `printf '.app_state["evm"]["params"]["evm_denom"]="%s"' $DENOM`
# cosmos/evm v0.5+ derives EVM coin info from bank denom_metadata at InitGenesis
# (LoadEvmCoinInfo); without metadata for the base denom the node panics on start
# with "denom metadata <denom> could not be found".
update_test_genesis '.app_state["bank"]["denom_metadata"]=[{"description":"Native token of Push Chain","denom_units":[{"denom":"upc","exponent":0,"aliases":[]},{"denom":"pushchain","exponent":18,"aliases":[]}],"base":"upc","display":"pushchain","name":"Push Chain","symbol":"PC"}]'
update_test_genesis '.app_state["evm"]["params"]["active_static_precompiles"]=["0x00000000000000000000000000000000000000CB","0x00000000000000000000000000000000000000ca","0x0000000000000000000000000000000000000100","0x0000000000000000000000000000000000000400","0x0000000000000000000000000000000000000800","0x0000000000000000000000000000000000000801","0x0000000000000000000000000000000000000802","0x0000000000000000000000000000000000000803","0x0000000000000000000000000000000000000804","0x0000000000000000000000000000000000000805"]'
update_test_genesis '.app_state["erc20"]["params"]["native_precompiles"]=["0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"]' # https://eips.ethereum.org/EIPS/eip-7528
update_test_genesis `printf '.app_state["erc20"]["token_pairs"]=[{contract_owner:1,erc20_address:"0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",denom:"%s",enabled:true}]' $DENOM`
update_test_genesis '.app_state["feemarket"]["params"]["no_base_fee"]=false'
update_test_genesis '.app_state["feemarket"]["params"]["base_fee"]="1000000000.000000000000000000"'
update_test_genesis '.app_state["feemarket"]["params"]["min_gas_price"]="1000000000.000000000000000000"'
# staking
update_test_genesis `printf '.app_state["staking"]["params"]["bond_denom"]="%s"' $DENOM`
update_test_genesis '.app_state["staking"]["params"]["min_commission_rate"]="0.050000000000000000"'
# mint
update_test_genesis `printf '.app_state["mint"]["params"]["mint_denom"]="%s"' $DENOM`
# crisis
update_test_genesis `printf '.app_state["crisis"]["constant_fee"]={"denom":"%s","amount":"1000"}' $DENOM`
## abci
update_test_genesis '.consensus["params"]["abci"]["vote_extensions_enable_height"]="1"'
# === CUSTOM MODULES ===
# tokenfactory
update_test_genesis '.app_state["tokenfactory"]["params"]["denom_creation_fee"]=[]'
update_test_genesis '.app_state["tokenfactory"]["params"]["denom_creation_gas_consume"]=100000'
# setting admin of uregistry, utss, uvalidator modules
ADMIN_ADDR=$(BINARY keys show $KEY1 -a --keyring-backend $KEYRING)
update_test_genesis ".app_state[\"uregistry\"][\"params\"][\"admin\"]=\"$ADMIN_ADDR\""
update_test_genesis ".app_state[\"utss\"][\"params\"][\"admin\"]=\"$ADMIN_ADDR\""
update_test_genesis ".app_state[\"uvalidator\"][\"params\"][\"admin\"]=\"$ADMIN_ADDR\""
# Allocate genesis accounts
# Total: 10 000000000 . 000000000 000000000
BINARY genesis add-genesis-account $KEY1 5000000000000000000000000000$DENOM,100000000test --keyring-backend $KEYRING --append
BINARY genesis add-genesis-account $KEY2 3000000000000000000000000000$DENOM,90000000test --keyring-backend $KEYRING --append
BINARY genesis add-genesis-account $KEY3 2000000000000000000000000000$DENOM,90000000test --keyring-backend $KEYRING --append
# Sign genesis transaction
# 10 000 . 000000000 000000000
BINARY genesis gentx $KEY1 10000000000000000000000$DENOM --gas-prices 1000000000${DENOM} --keyring-backend $KEYRING --chain-id $CHAIN_ID
BINARY genesis collect-gentxs
BINARY genesis validate-genesis
err=$?
if [ $err -ne 0 ]; then
echo "Failed to validate genesis"
return
fi
}
# check if CLEAN is not set to false
if [ "$CLEAN" != "false" ]; then
echo "Starting from a clean state"
from_scratch
fi
# Setup Cosmovisor directory (after from_scratch wipes HOME_DIR)
mkdir -p "$HOME_DIR/cosmovisor/genesis/bin"
mkdir -p "$HOME_DIR/cosmovisor/upgrades"
# Copy binary to cosmovisor (handle both PATH commands and file paths)
if [ -x "$BINARY" ]; then
cp "$BINARY" "$HOME_DIR/cosmovisor/genesis/bin/$DAEMON_NAME"
# Also copy libwasmvm.dylib if it exists alongside the binary (macOS)
BINARY_DIR=$(dirname "$BINARY")
if [ -f "$BINARY_DIR/libwasmvm.dylib" ]; then
cp "$BINARY_DIR/libwasmvm.dylib" "$HOME_DIR/cosmovisor/genesis/bin/"
fi
else
cp "$(which $BINARY)" "$HOME_DIR/cosmovisor/genesis/bin/"
fi
# Opens the RPC endpoint to outside connections
sed -i -e 's/laddr = "tcp:\/\/127.0.0.1:26657"/c\laddr = "tcp:\/\/0.0.0.0:'$RPC'"/g' $HOME_DIR/config/config.toml
sed -i -e 's/cors_allowed_origins = \[\]/cors_allowed_origins = \["\*"\]/g' $HOME_DIR/config/config.toml
# REST endpoint
sed -i -e 's/address = "tcp:\/\/localhost:1317"/address = "tcp:\/\/0.0.0.0:'$REST'"/g' $HOME_DIR/config/app.toml
sed -i -e 's/enable = false/enable = true/g' $HOME_DIR/config/app.toml
sed -i -e 's/enabled-unsafe-cors = false/enabled-unsafe-cors = true/g' $HOME_DIR/config/app.toml
# peer exchange
sed -i -e 's/pprof_laddr = "localhost:6060"/pprof_laddr = "localhost:'$PROFF'"/g' $HOME_DIR/config/config.toml
sed -i -e 's/laddr = "tcp:\/\/0.0.0.0:26656"/laddr = "tcp:\/\/0.0.0.0:'$P2P'"/g' $HOME_DIR/config/config.toml
# GRPC
sed -i -e 's/address = "localhost:9090"/address = "0.0.0.0:'$GRPC'"/g' $HOME_DIR/config/app.toml
sed -i -e 's/address = "localhost:9091"/address = "0.0.0.0:'$GRPC_WEB'"/g' $HOME_DIR/config/app.toml
# Rosetta Api
sed -i -e 's/address = ":8080"/address = "0.0.0.0:'$ROSETTA'"/g' $HOME_DIR/config/app.toml
# Faster blocks
sed -i -e 's/timeout_commit = "5s"/timeout_commit = "'$BLOCK_TIME'"/g' $HOME_DIR/config/config.toml
# Start node with Cosmovisor (enables automatic upgrades)
cosmovisor run start --pruning=nothing --minimum-gas-prices=1000000000$DENOM --rpc.laddr="tcp://0.0.0.0:$RPC" --json-rpc.api=eth,txpool,personal,net,debug,web3 --chain-id="$CHAIN_ID"