Skip to content

Commit

Permalink
update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickwieth committed Oct 16, 2023
1 parent 18e6955 commit b6752fb
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ RUN apt-get -y -qq update && \
apt-get install -y -qq apt-transport-https curl wget unzip screen bash jq python3 pip && \
apt-get clean


# install python script to download genesis
RUN pip install tendermint-chunked-genesis-download



# install correct go version
RUN wget https://go.dev/dl/go1.20.2.linux-amd64.tar.gz
RUN tar -xvf go1.20.2.linux-amd64.tar.gz
Expand Down
75 changes: 51 additions & 24 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,34 +12,61 @@ then
exit 1
fi

#we can derive the peer id from the address and should do so!
NODE_ADDR=$(cat syncnode.txt)
PEER_ID=$(curl -s "http://"$NODE_ADDR":26657/status" | jq -r .result.node_info.id)
#we can derive the peer id from the rpc
mapfile -t peers < <(
jq -r '.peers[]' peer_nodes.json
)

for item in "${peers[@]}"; do
echo "peers: ${item}"
done

mapfile -t rpcs < <(
jq -r '.rpcs[]' peer_nodes.json
)

echo "peers" $peers

for i in "${!rpcs[@]}"; do
if curl --output /dev/null --silent --head --fail --connect-timeout 5 ${rpcs[$i]}; then
echo "URL exists: ${rpcs[$i]}"
PEER_ID=$(curl -s ${rpcs[$i]}"/status" | jq -r .result.node_info.id)

PEERS=$PEER_ID"@"${peers[$i]}
break
else
echo "not reachable $i"
fi
done
if [ -z "$PEERS" ]
then
echo -e "\033[0;31mNo PEERS available\033[0m"
exit
fi

SEEDS=""
PEERS=$PEER_ID"@"$NODE_ADDR":26656"
echo "peers is:" $PEERS
sed -i.bak -e "s/^seeds *=.*/seeds = \"$SEEDS\"/; s/^persistent_peers *=.*/persistent_peers = \"$PEERS\"/" $HOME/.Cardchain/config/config.toml

SNAP_RPCs=("http://crowd.rpc.t.stavr.tech:21207"
"https://cardchain-testnet.nodejumper.io:443"
"https://cardchain-rpc.acloud.pp.ua:443")

# for i in "${SNAP_RPCs[@]}"; do
# if curl --output /dev/null --silent --head --fail --connect-timeout 5 $i; then
# echo "URL exists: $i"
# SNAP_RPC=$i
# break
# else
# echo "not reachable $i"
# fi
# done

# if [ -z "$SNAP_RPC" ]
# then
# echo -e "\033[0;31mNo SNAP_RPC available\033[0m"
# fi

SNAP_RPC="http://$(cat syncnode.txt):26657"
mapfile -t snap_rpcs < <(
jq -r '.snap_rpcs[]' peer_nodes.json
)

for i in "${snap_rpcs[@]}"; do
if curl --output /dev/null --silent --head --fail --connect-timeout 5 $i; then
echo "URL exists: $i"
SNAP_RPC=$i
break
else
echo "not reachable $i"
fi
done
if [ -z "$SNAP_RPC" ]
then
echo -e "\033[0;31mNo SNAP_RPC available\033[0m"
exit
fi

LATEST_HEIGHT=$(curl -s $SNAP_RPC/block | jq -r .result.block.header.height)
echo $LATEST_HEIGHT
BLOCK_HEIGHT=$((LATEST_HEIGHT)); \
Expand Down
16 changes: 16 additions & 0 deletions peer_nodes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"rpcs": [
"http://crowd.rpc.t.stavr.tech:21207",
"https://cardchain-testnet-rpc.itrocket.net",
"https://rpc-testnet-cardchain.nodeist.net"
],
"peers": [
"crowd.peer.stavr.tech:21206",
"cardchain-testnet-peer.itrocket.net:31656",
"rpc-testnet-cardchain.nodeist.net:26656"
],
"snap_rpcs": [
"http://crowd.rpc.t.stavr.tech:21207",
"https://rpc-testnet-cardchain.nodeist.net:443"
]
}
15 changes: 13 additions & 2 deletions scripts/download_genesis.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import json
import requests
import tendermint_chunked_genesis_download as tcgd
f = open('syncnode.txt', 'r')

tcgd.download_genesis('http://'+f.read()+':26657/')
with open('peer_nodes.json', 'r') as f:
data = json.load(f)

for url in data['rpcs']:
try:
page = requests.get(url)
print(url, page.status_code)
tcgd.download_genesis(url)
break
except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError):
print("Error")
1 change: 0 additions & 1 deletion syncnode.txt

This file was deleted.

0 comments on commit b6752fb

Please sign in to comment.