forked from eminmtas/aligned_layer_tendermint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multi_node_setup.sh
executable file
·148 lines (119 loc) · 6.89 KB
/
multi_node_setup.sh
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
#!/bin/bash
: "${CHAIN_ID:=alignedlayer}"
: "${PASSWORD:=password}"
: "${FAUCET_DIR:=./faucet}"
token="stake"
initial_balance=1000000000000
initial_faucet_balance=1000000000
initial_stake=10000000
minimum_gas_price=0.0001
if [ $# -lt 1 ]; then
echo "Usage: $0 <node1> [<node2> ...]"
exit 1
fi
echo "Creating directories for nodes..."
rm -rf prod-sim
for node in "$@"; do
mkdir -p prod-sim/$node
done
node_ids=()
for node in "$@"; do
echo "Initializing $node..."
docker run --rm -v $(pwd)/prod-sim/$node:/root/.alignedlayer -it alignedlayerd_i init alignedlayer_$node --chain-id $CHAIN_ID > /dev/null
docker run --rm -it -v $(pwd)/prod-sim/$node:/root/.alignedlayer --entrypoint sed alignedlayerd_i -i 's/"stake"/"'$token'"/g' /root/.alignedlayer/config/genesis.json
docker run --rm -v $(pwd)/prod-sim/$node:/root/.alignedlayer -it alignedlayerd_i config set app minimum-gas-prices "$minimum_gas_price$token"
docker run --rm -v $(pwd)/prod-sim/$node:/root/.alignedlayer -it alignedlayerd_i config set app pruning "nothing"
node_id=$(docker run --rm -i -v $(pwd)/prod-sim/$node:/root/.alignedlayer alignedlayerd_i tendermint show-node-id)
node_ids+=($node_id)
echo "Node ID for $node: $node_id"
done
for (( i=1; i <= "$#"; i++ )); do
echo "Creating key for ${!i} user..."
printf "$PASSWORD\n$PASSWORD\n" | docker run --rm -i -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer alignedlayerd_i keys --keyring-backend file --keyring-dir /root/.alignedlayer/keys add val_${!i} > /dev/null 2> ./prod-sim/${!i}/mnemonic.txt
val_address=$(echo $PASSWORD | docker run --rm -i -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer alignedlayerd_i keys --keyring-backend file --keyring-dir /root/.alignedlayer/keys show val_${!i} --address)
echo "val_${!i} address: $val_address"
echo "val_${!i} mnemonic: $(cat ./prod-sim/${!i}/mnemonic.txt)"
echo "Giving val_${!i} some tokens..."
if [ $i -eq 1 ]; then
faucet_initial_balance=$((initial_faucet_balance + initial_stake))
docker run --rm -it -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer alignedlayerd_i genesis add-genesis-account $val_address $faucet_initial_balance$token
else
docker run --rm -it -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer alignedlayerd_i genesis add-genesis-account $val_address $initial_balance$token
fi
if [ $((i+1)) -le "$#" ]; then
j=$((i+1))
cp prod-sim/${!i}/config/genesis.json prod-sim/${!j}/config/genesis.json
elif [ $# != 1 ] && [ $((i+1)) -gt $# ]; then
cp prod-sim/${!i}/config/genesis.json prod-sim/$1/config/genesis.json
fi
done
for (( i=1; i <= "$#"; i++ )); do
echo "Giving val_${!i} some stake..."
echo $PASSWORD | docker run --rm -i -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer alignedlayerd_i genesis gentx val_${!i} $initial_stake$token --keyring-backend file --keyring-dir /root/.alignedlayer/keys --account-number 0 --sequence 0 --chain-id $CHAIN_ID --gas 1000000 --gas-prices $minimum_gas_price$token
if [ $i -gt 1 ]; then
cp prod-sim/${!i}/config/gentx/* prod-sim/$1/config/gentx/
fi
if [ $((i+1)) -le "$#" ]; then
j=$((i+1))
cp prod-sim/${!i}/config/genesis.json prod-sim/${!j}/config/genesis.json
elif [ $# != 1 ] && [ $((i+1)) -gt $# ]; then
cp prod-sim/${!i}/config/genesis.json prod-sim/$1/config/genesis.json
fi
done
echo "Collecting genesis transactions..."
docker run --rm -it -v $(pwd)/prod-sim/$1:/root/.alignedlayer alignedlayerd_i genesis collect-gentxs > /dev/null
if ! docker run --rm -it -v $(pwd)/prod-sim/$1:/root/.alignedlayer alignedlayerd_i genesis validate-genesis; then
echo "Invalid genesis"
exit 1
fi
cat prod-sim/$1/config/genesis.json \
| jq '.app_state.slashing.params = {
"downtime_jail_duration": "30s",
"min_signed_per_window": "0.2",
"signed_blocks_window": "120",
"slash_fraction_double_sign": "0.050000000000000000",
"slash_fraction_downtime": "0.000100000000000000" }' \
| sponge prod-sim/$1/config/genesis.json
cat prod-sim/$1/config/genesis.json \
| jq '.app_state.staking.params.max_validators = "300"' \
| sponge prod-sim/$1/config/genesis.json
echo "Copying genesis file to other nodes..."
for node in "${@:2}"; do
cp prod-sim/$1/config/genesis.json prod-sim/$node/config/genesis.json
done
echo "Setting node addresses in config..."
for (( i=1; i <= "$#"; i++ )); do
other_addresses=()
for (( j=1; j <= "$#"; j++ )); do
if [ $j -ne $i ]; then
other_addresses+=("${node_ids[$j - 1]}@${!j}:26656")
fi
done
other_addresses=$(IFS=,; echo "${other_addresses[*]}")
#Peer configuration
docker run --rm -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer -it alignedlayerd_i config set config p2p.persistent_peers "$other_addresses" --skip-validate
#RPC configuration
docker run --rm -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer -it alignedlayerd_i config set config rpc.laddr "tcp://0.0.0.0:26657" --skip-validate
#Explorer configuration
docker run --rm -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer -it alignedlayerd_i config set config rpc.cors_allowed_origins '["*"]' --skip-validate
docker run --rm -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer -it alignedlayerd_i config set app api.enable true --skip-validate
docker run --rm -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer -it alignedlayerd_i config set app api.enabled-unsafe-cors true --skip-validate
docker run --rm -v $(pwd)/prod-sim/${!i}:/root/.alignedlayer -it alignedlayerd_i config set app api.address "tcp://0.0.0.0:1317" --skip-validate
done
echo "Setting up faucet files..."
mkdir -p prod-sim/faucet/.faucet
mkdir -p prod-sim/faucet/config
cp $FAUCET_DIR/config/config.js prod-sim/faucet/config/config.js
sed -n '6p' ./prod-sim/$1/mnemonic.txt | tr -d '\n' > temp.txt && mv temp.txt ./prod-sim/faucet/.faucet/mnemonic.txt
sed -i '' 's|\(rpc_endpoint: \).*"|\1"http://'$1':26657"|' prod-sim/faucet/config/config.js
echo "Setting up docker compose..."
rm -f ./prod-sim/docker-compose.yml
printf "version: '3.7'\nnetworks:\n net-public:\nservices:\n" > ./prod-sim/docker-compose.yml
for node in "$@"; do
printf " alignedlayerd-$node:\n command: start\n image: alignedlayerd_i\n container_name: $node\n volumes:\n - ./$node:/root/.alignedlayer\n networks:\n - net-public\n" >> ./prod-sim/docker-compose.yml
if [ $node == "$1" ]; then
printf " ports:\n - 0.0.0.0:26657:26657\n" >> ./prod-sim/docker-compose.yml
fi
printf "\n" >> ./prod-sim/docker-compose.yml
done
printf " alignedlayerd-faucet:\n command: faucet.js\n image: alignedlayerd_faucet\n container_name: faucet\n volumes:\n - ./faucet/config:/faucet/config\n - ./faucet/.faucet:/faucet/.faucet\n networks:\n - net-public\n ports:\n - 8088:8088\n" >> ./prod-sim/docker-compose.yml