forked from informalsystems/hermes
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathone-chain
executable file
·159 lines (131 loc) · 6 KB
/
one-chain
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
#!/bin/bash
# Copied from https://github.com/cosmos/relayer/tree/master/scripts
usage() {
echo "Usage: $0 BINARY CHAIN_ID CHAIN_DIR RPC_PORT P2P_PORT PROFILING_PORT GRPC_PORT SAMOLEANS"
echo "Example: $0 gaiad ibc-0 ./data 26657 26656 6060 9090 100"
exit 1
}
missing() {
echo "Missing $1 parameter. Please check if all parameters were specified."
usage
}
if [ -z "$1" ]; then
missing "[BINARY] (gaiad|akash)"
fi
if [ -z "$2" ]; then
missing "[CHAIN_ID]"
fi
if [ -z "$3" ]; then
missing "[CHAIN_DIR]"
fi
if [ -z "$4" ]; then
missing "[RPC_PORT]"
fi
if [ -z "$5" ]; then
missing "[P2P_PORT]"
fi
if [ -z "$6" ]; then
missing "[PROFILING_PORT]"
fi
if [ -z "$7" ]; then
missing "[GRPC_PORT]"
fi
if [ -z "$8" ]; then
missing "[SAMOLEANS]"
fi
if [ "$#" -gt 8 ]; then
echo "Incorrect number of parameters."
usage
fi
BINARY=$1
CHAIN_ID=$2
CHAIN_DIR=$3
RPC_PORT=$4
P2P_PORT=$5
PROF_PORT=$6
GRPC_PORT=$7
SAMOLEANS=$8
echo "Creating $BINARY instance: home=$CHAIN_DIR | chain-id=$CHAIN_ID | p2p=:$P2P_PORT | rpc=:$RPC_PORT | profiling=:$PROF_PORT | grpc=:$GRPC_PORT | samoleans=:$SAMOLEANS"
# Add dir for chain, exit if error
if ! mkdir -p $CHAIN_DIR/$CHAIN_ID 2>/dev/null; then
echo "Failed to create chain folder. Aborting..."
exit 1
fi
# Build genesis file incl account for passed address
STAKE="100000000000stake"
# The user also needs stake to perform actions
USER_COINS="${STAKE},${SAMOLEANS}samoleans"
# Hermes also needs stake to perform actions
HERMES_COINS="${STAKE},${SAMOLEANS}samoleans"
$BINARY --home $CHAIN_DIR/$CHAIN_ID --chain-id $CHAIN_ID init $CHAIN_ID &> /dev/null
sleep 1
echo "Creating validator key"
$BINARY --home $CHAIN_DIR/$CHAIN_ID keys add validator --keyring-backend="test" --output json > $CHAIN_DIR/$CHAIN_ID/validator_seed.json 2>&1
sleep 1
echo "Creating user key"
$BINARY --home $CHAIN_DIR/$CHAIN_ID keys add user --keyring-backend="test" --output json > $CHAIN_DIR/$CHAIN_ID/user_seed.json 2>&1
sleep 1
echo "Creating user2 key"
$BINARY --home $CHAIN_DIR/$CHAIN_ID keys add user2 --keyring-backend="test" --output json > $CHAIN_DIR/$CHAIN_ID/user2_seed.json 2>&1
sleep 1
# Add samoleans to user
USER=$($BINARY --home $CHAIN_DIR/$CHAIN_ID keys --keyring-backend="test" show user -a)
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $USER $USER_COINS &> /dev/null
sleep 1
# Add samoleans to user2
USER2=$($BINARY --home $CHAIN_DIR/$CHAIN_ID keys --keyring-backend="test" show user2 -a)
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $USER2 $USER_COINS &> /dev/null
sleep 1
# Add stake to validator
VALIDATOR=$($BINARY --home $CHAIN_DIR/$CHAIN_ID keys --keyring-backend="test" show validator -a)
$BINARY --home $CHAIN_DIR/$CHAIN_ID add-genesis-account $VALIDATOR $STAKE &> /dev/null
sleep 1
# Stake everything
$BINARY --home $CHAIN_DIR/$CHAIN_ID gentx validator --keyring-backend="test" --chain-id $CHAIN_ID $STAKE &> /dev/null
sleep 1
$BINARY --home $CHAIN_DIR/$CHAIN_ID collect-gentxs &> /dev/null
sleep 1
# Check platform
platform='unknown'
unamestr=`uname`
if [ "$unamestr" = 'Linux' ]; then
platform='linux'
fi
# Set proper defaults and change ports (use a different sed for Mac or Linux)
echo "Change settings in config.toml file..."
if [ $platform = 'linux' ]; then
sed -i 's#"172800s"#"200s"#g' $CHAIN_DIR/$CHAIN_ID/config/genesis.json
sed -i 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPC_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2P_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's#"localhost:6060"#"localhost:'"$PROF_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '/^\[grpc-web\]/,/^\[/s/^enable = true/enable = false/' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
else
sed -i '' 's#"172800s"#"200s"#g' $CHAIN_DIR/$CHAIN_ID/config/genesis.json
sed -i '' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:'"$RPC_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:'"$P2P_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's#"localhost:6060"#"localhost:'"$PROF_PORT"'"#g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' 's/index_all_keys = false/index_all_keys = true/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
sed -i '' '/^\[grpc-web\]/,/^\[/s/^enable = true/enable = false/' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's/min-retain-blocks = 0/min-retain-blocks = 100/g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's#index-events = \[\]#index-events = \["message.action","send_packet.packet_src_channel","send_packet.packet_sequence"\]#g' $CHAIN_DIR/$CHAIN_ID/config/app.toml
# sed -i '' 's/error/debug/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
# sed -i '' 's/info/debug/g' $CHAIN_DIR/$CHAIN_ID/config/config.toml
fi
# Start gaia
echo "Start gaia on grpc port: $GRPC_PORT..."
$BINARY --home $CHAIN_DIR/$CHAIN_ID start --pruning=nothing --grpc.address="0.0.0.0:$GRPC_PORT" --log_level info > $CHAIN_DIR/$CHAIN_ID.log 2>&1 &
# Show validator's and user's balance
sleep 3
RPC_ADDR="tcp://localhost:$RPC_PORT"
echo "Balances for validator '$VALIDATOR' @ '$RPC_ADDR'"
$BINARY --node "$RPC_ADDR" query bank balances $VALIDATOR --log_level error
echo "Balances for user '$USER' @ '$RPC_ADDR'"
$BINARY --node "$RPC_ADDR" query bank balances $USER --log_level error
echo "Balances for user '$USER2' @ '$RPC_ADDR'"
$BINARY --node "$RPC_ADDR" query bank balances $USER2 --log_level error