-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathstate_sync.sh
54 lines (43 loc) · 2.43 KB
/
state_sync.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
#!/usr/bin/env bash
set -euo pipefail
# Check if a haqqd directory provided as an argument
if [ -z "$1" ]; then
echo "Usage: $0 <haqqd_directory>"
exit 1
fi
# Define the Tendermint RPC endpoint's of the HAQQ network
SNAP_RPC1="https://rpc.tm.haqq.network:443"
SNAP_RPC2="https://rpc.haqq.sh:443"
# Select one available SNAP_RPC
if curl -Is "$SNAP_RPC1/health" | head -n 1 | grep "200" > /dev/null; then
echo "[INFO] SNAP_RPC1 ($SNAP_RPC1) is available and selected for requests"
SNAP_RPC=$SNAP_RPC1
elif curl -Is "$SNAP_RPC2/health" | head -n 1 | grep "200" > /dev/null; then
echo "[INFO] SNAP_RPC2 ($SNAP_RPC2) is available and selected for requests"
SNAP_RPC=$SNAP_RPC2
else
echo "[ERROR] Both SNAP_RPC1 and SNAP_RPC2 are not available. Exiting..."
exit 1
fi
SNAP_RPC=$SNAP_RPC2
# Retrieve the latest block height of the HAQQ network
LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height)
# Calculate the height of the block to be trusted
BLOCK_HEIGHT=$((LATEST_HEIGHT - 10000))
# Retrieve the hash of the block to be trusted
TRUST_HASH=$(curl -s "$SNAP_RPC/block?height=$BLOCK_HEIGHT" | jq -r .result.block_id.hash)
# Define persistent peers
P_PEERS=""
# Define seed nodes
SEEDS="[email protected]:26656,e1b058e5cfa2b836ddaa496b10911da62dcf182e@haqq-seed-de.allnodes.me:26656,e726816f42831689eab9378d5d577f1d06d25716@haqq-seed-us.allnodes.me:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:26656,[email protected]:666"
# Modify the HAQQ configuration file to add the trusted block and other parameters
sed -i.bak \
-E "s|^(enable[[:space:]]+=[[:space:]]+).*$|\1true| ; \
s|^(rpc_servers[[:space:]]+=[[:space:]]+).*$|\1\"$SNAP_RPC,$SNAP_RPC\"| ; \
s|^(trust_height[[:space:]]+=[[:space:]]+).*$|\1$BLOCK_HEIGHT| ; \
s|^(trust_hash[[:space:]]+=[[:space:]]+).*$|\1\"$TRUST_HASH\"| ; \
s|^(persistent_peers[[:space:]]+=[[:space:]]+).*$|\1\"$P_PEERS\"| ; \
s|^(seeds[[:space:]]+=[[:space:]]+).*$|\1\"$SEEDS\"|" \
$1/config/config.toml
# Print a message indicating that the configuration file has been updated
echo "HAQQ configuration file updated with the trusted block $BLOCK_HEIGHT ($TRUST_HASH)"