This repository has been archived by the owner on Mar 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
statesync_client_darwin_amd64.sh
101 lines (86 loc) · 4.54 KB
/
statesync_client_darwin_amd64.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
#!/bin/bash
# Based on the work of Joe (Chorus-One) for Microtick - https://github.com/microtick/bounties/tree/main/statesync
# You need config in two peers (avoid seed servers) this values in app.toml:
# [state-sync]
# snapshot-interval = 1000
# snapshot-keep-recent = 10
# Pruning should be fine tuned also, for this testings is set to nothing
# pruning = "nothing"
set -e
export DATE_BACKUP=`date +"%d_%m_%Y-%H_%M"`
# Change for your custom chain
BINARY="https://github.com/BitCannaGlobal/bcna/releases/download/v.1.3.1/bcnad_darwin64"
GENESIS="https://raw.githubusercontent.com/BitCannaGlobal/bcna/main/genesis.json"
APP="BCNA: ~/.bcna"
echo "Welcome to the StateSync script. This script will backup your config, move the current .bcna folder to .old_bcna, sync the last state and restore the previous config.
You should have a crypted backup of your wallet keys, your node keys and your validator keys, anyway the script will make a clear backup of the last two. Ensure that you can restore your wallet keys if is needed."
read -p "$APP folder, your keys and config will be erased, a backup will be made, PROCED (y/n)? " -n 1 -r
if [[ $REPLY =~ ^[Yy]$ ]]
then
# BitCanna State Sync client config.
echo ##################################################
echo " Making a backup from .bcna config files if exist"
echo ##################################################
cd ~
if [ -d ~/.bcna ];
then
echo "There is a BCNA folder there... taking a backup and moving to .old_bcna"
tar cvfz bcna_folder_backup_$DATE_BACKUP.tgz --exclude=".bcna/data/cs.wal" --exclude=".bcna/data/application.db" --exclude=".bcna/data/blockstore.db" --exclude=".bcna/data/evidence.db" --exclude=".bcna/data/snapshots" --exclude=".bcna/data/state.db" --exclude=".bcna/data/tx_index.db" .bcna/*
mv .bcna .old_bcna
fi
if [ -f ~/bcnad ];
then
rm -f bcnad_darwin_arm64 #deletes a previous downloaded binary
fi
wget -nc $BINARY
chmod +x bcnad_darwin_arm64
mv bcnad_darwin_arm64 bcnad
./bcnad init New_peer --chain-id bitcanna-1
rm -rf $HOME/.bcnad/config/genesis.json #deletes the default created genesis
curl -s $GENESIS > $HOME/.bcna/config/genesis.json
NODE1_IP="206.189.9.95"
RPC1="http://$NODE1_IP"
P2P_PORT1=26656
RPC_PORT1=26657
NODE2_IP="159.65.198.245"
RPC2="http://$NODE2_IP"
RPC_PORT2=26657
P2P_PORT2=26656
#If you want to use a third StateSync Server...
#DOMAIN_3=seed1.bitcanna.io # If you want to use domain names
#NODE3_IP=$(dig $DOMAIN_1 +short
#RPC3="http://$NODE3_IP"
#RPC_PORT3=26657
#P2P_PORT3=26656
INTERVAL=1000
LATEST_HEIGHT=$(curl -s $RPC1:$RPC_PORT1/block | jq -r .result.block.header.height);
BLOCK_HEIGHT=$((($(($LATEST_HEIGHT / $INTERVAL)) -10) * $INTERVAL)); #Mark addition
if [ $BLOCK_HEIGHT -eq 0 ]; then
echo "Error: Cannot state sync to block 0; Latest block is $LATEST_HEIGHT and must be at least $INTERVAL; wait a few blocks!"
exit 1
fi
TRUST_HASH=$(curl -s "$RPC1:$RPC_PORT1/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
if [ "$TRUST_HASH" == "null" ]; then
echo "Error: Cannot find block hash. This shouldn't happen :/"
exit 1
fi
NODE1_ID=$(curl -s "$RPC1:$RPC_PORT1/status" | jq -r .result.node_info.id)
NODE2_ID=$(curl -s "$RPC2:$RPC_PORT2/status" | jq -r .result.node_info.id)
#NODE3_ID=$(curl -s "$RPC3:$RPC_PORT3/status" | jq -r .result.node_info.id)
sed -i.bak -E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"http://$NODE1_IP:$RPC_PORT1,http://$NODE2_IP:$RPC_PORT2\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"| ; \
s|^(persistent_peers[[:space:]]+=[[:space:]]+).*$|\1\"${NODE1_ID}@${NODE1_IP}:${P2P_PORT1},${NODE2_ID}@${NODE2_IP}:${P2P_PORT2}\"| ; \
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"[email protected]:26656,[email protected]:26656\"|" $HOME/.bcna/config/config.toml
sed -E -i -s 's/minimum-gas-prices = \".*\"/minimum-gas-prices = \"0.001ubcna\"/' $HOME/.bcna/config/app.toml
./bcnad unsafe-reset-all
./bcnad start
echo
echo Waiting 10 seconds... your backup will be restored with your previous data.... and BCNAD will start again to test it.
sleep 10
tar -xzvf bcna_folder_backup_$DATE_BACKUP.tgz
./bcnad start
echo If your node is synced considerate to create a service file. Be careful, your backup file is not crypted!
echo If process was sucessful you can delete .old_bcna
fi