forked from cosmos/relayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtwo-chainz
executable file
·123 lines (102 loc) · 4.88 KB
/
two-chainz
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
#!/bin/bash
# Ensure gopath is set and go is installed
if [[ ! -d $GOPATH ]] || [[ ! -d $GOBIN ]] || [[ ! -x "$(which go)" ]]; then
echo "Your \$GOPATH is not set or go is not installed,"
echo "ensure you have a working installation of go before trying again..."
echo "https://golang.org/doc/install"
exit 1
fi
GAIA_REPO="$GOPATH/src/github.com/cosmos/gaia"
GAIA_BRANCH=ibc-alpha
GAIA_DATA="$(pwd)/data"
# ARGS:
# $1 -> local || remote, defaults to remote
# Ensure user understands what will be deleted
if [[ -d $GAIA_DATA ]] && [[ ! "$2" == "skip" ]]; then
read -p "$0 will delete \$(pwd)/data folder. Do you wish to continue? (y/n): " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
rm -rf $GAIA_DATA &> /dev/null
killall gaiad &> /dev/null
set -e
if [[ -d $GAIA_REPO ]]; then
cd $GAIA_REPO
# remote build syncs with remote then builds
if [[ "$1" == "local" ]]; then
echo "Using local version of github.com/cosmos/gaia"
make install &> /dev/null
else
echo "Building github.com/cosmos/gaia@$GAIA_BRANCH..."
if [[ ! -n $(git status -s) ]]; then
# sync with remote $GAIA_BRANCH
git fetch --all &> /dev/null
git checkout $GAIA_BRANCH &> /dev/null
git pull origin $GAIA_BRANCH &> /dev/null
# install
make install &> /dev/null
# ensure that built binary has the same version as the repo
if [[ ! "$(gaiad version --long 2>&1 | grep "commit:" | sed 's/commit: //g')" == "$(git rev-parse HEAD)" ]]; then
echo "built version of gaiad commit doesn't match "
exit 1
fi
else
echo "uncommited changes in $GAIA_REPO, please commit or stash before building"
exit 1
fi
fi
else
echo "$GAIA_REPO doesn't exist, and you may not have have the gaia repo locally,"
echo "if you want to download gaia to your \$GOPATH try running the following command:"
echo "mkdir -p $(dirname $GAIA_REPO) && git clone [email protected]:cosmos/gaia $GAIA_REPO"
fi
chainid0=ibc0
chainid1=ibc1
echo "Generating gaia configurations..."
mkdir -p $GAIA_DATA && cd $GAIA_DATA
echo -e "\n" | gaiad testnet -o $chainid0 --v 1 --chain-id $chainid0 --node-dir-prefix n --keyring-backend test &> /dev/null
echo -e "\n" | gaiad testnet -o $chainid1 --v 1 --chain-id $chainid1 --node-dir-prefix n --keyring-backend test &> /dev/null
cfgpth="n0/gaiad/config/config.toml"
if [ "$(uname)" = "Linux" ]; then
# TODO: Just index *some* specified tags, not all
# sed -i 's/index_keys = ""/index_keys = "tx.height,tx.hash"'
# Set proper defaults and change ports
sed -i 's/"leveldb"/"goleveldb"/g' $chainid0/$cfgpth
sed -i 's/"leveldb"/"goleveldb"/g' $chainid1/$cfgpth
sed -i 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:26556"#g' $chainid1/$cfgpth
sed -i 's#"tcp://0.0.0.0:26657"#"tcp://0.0.0.0:26557"#g' $chainid1/$cfgpth
sed -i 's#"localhost:6060"#"localhost:6061"#g' $chainid1/$cfgpth
sed -i 's#"tcp://127.0.0.1:26658"#"tcp://127.0.0.1:26558"#g' $chainid1/$cfgpth
# Make blocks run faster than normal
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $chainid0/$cfgpth
sed -i 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $chainid1/$cfgpth
sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $chainid0/$cfgpth
sed -i 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $chainid1/$cfgpth
else
# TODO: Just index *some* specified tags, not all
# sed -i 's/index_keys = ""/index_keys = "tx.height,tx.hash"'
# Set proper defaults and change ports
sed -i '' 's/"leveldb"/"goleveldb"/g' $chainid0/$cfgpth
sed -i '' 's/"leveldb"/"goleveldb"/g' $chainid1/$cfgpth
sed -i '' 's#"tcp://0.0.0.0:26656"#"tcp://0.0.0.0:26556"#g' $chainid1/$cfgpth
sed -i '' 's#"tcp://0.0.0.0:26657"#"tcp://0.0.0.0:26557"#g' $chainid1/$cfgpth
sed -i '' 's#"localhost:6060"#"localhost:6061"#g' $chainid1/$cfgpth
sed -i '' 's#"tcp://127.0.0.1:26658"#"tcp://127.0.0.1:26558"#g' $chainid1/$cfgpth
# Make blocks run faster than normal
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $chainid0/$cfgpth
sed -i '' 's/timeout_commit = "5s"/timeout_commit = "1s"/g' $chainid1/$cfgpth
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $chainid0/$cfgpth
sed -i '' 's/timeout_propose = "3s"/timeout_propose = "1s"/g' $chainid1/$cfgpth
fi
gclpth="n0/gaiacli/"
gaiacli config --home $chainid0/$gclpth chain-id $chainid0 &> /dev/null
gaiacli config --home $chainid1/$gclpth chain-id $chainid1 &> /dev/null
gaiacli config --home $chainid0/$gclpth output json &> /dev/null
gaiacli config --home $chainid1/$gclpth output json &> /dev/null
gaiacli config --home $chainid0/$gclpth node http://localhost:26657 &> /dev/null
gaiacli config --home $chainid1/$gclpth node http://localhost:26557 &> /dev/null
echo "Starting Gaiad instances..."
gaiad --home $GAIA_DATA/$chainid0/n0/gaiad start --pruning=nothing > $chainid0.log 2>&1 &
gaiad --home $GAIA_DATA/$chainid1/n0/gaiad start --pruning=nothing > $chainid1.log 2>&1 &