diff --git a/Dockerfile b/Dockerfile index afeae5f1..9c8af30c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/docker-run.sh b/docker-run.sh index 6cb72df9..d7482cea 100755 --- a/docker-run.sh +++ b/docker-run.sh @@ -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)); \ diff --git a/peer_nodes.json b/peer_nodes.json new file mode 100644 index 00000000..6cf0ba89 --- /dev/null +++ b/peer_nodes.json @@ -0,0 +1,17 @@ +{ + "rpcs": [ + "https://cardchain-testnet-rpc.itrocket.net", + "http://crowd.rpc.t.stavr.tech:21207", + "https://rpc-testnet-cardchain.nodeist.net" + ], + "peers": [ + "cardchain-testnet-peer.itrocket.net:31656", + "crowd.peer.stavr.tech:21206", + "rpc-testnet-cardchain.nodeist.net:26656" + ], + "snap_rpcs": [ + "https://cardchain-testnet-rpc.itrocket.net:443", + "http://crowd.rpc.t.stavr.tech:21207", + "https://rpc-testnet-cardchain.nodeist.net:443" + ] +} \ No newline at end of file diff --git a/scripts/buildlaunch-node.sh b/scripts/buildlaunch-node.sh index 4e7354cf..2718baec 100644 --- a/scripts/buildlaunch-node.sh +++ b/scripts/buildlaunch-node.sh @@ -3,7 +3,7 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" -docker-compose build +docker-compose build --no-cache docker-compose up -d sleep 1 bash register_faucet.sh \ No newline at end of file diff --git a/scripts/download_genesis.py b/scripts/download_genesis.py index 5a38d7ff..da526c26 100644 --- a/scripts/download_genesis.py +++ b/scripts/download_genesis.py @@ -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/') \ No newline at end of file +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") \ No newline at end of file diff --git a/scripts/register_faucet.sh b/scripts/register_faucet.sh index 9992e56c..5cd8f3e3 100644 --- a/scripts/register_faucet.sh +++ b/scripts/register_faucet.sh @@ -3,4 +3,25 @@ parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P ) cd "$parent_path" -Cardchaind tx cardchain createuser $(cat ../backup/faucetaddress.txt) faucet --from jannik --gas auto --node tcp://$(cat ../syncnode.txt):26657 \ No newline at end of file +mapfile -t rpcs < <( + jq -r '.rpcs[]' peer_nodes.json +) + +for i in "${!rpcs[@]}"; do + if curl --output /dev/null --silent --head --fail --connect-timeout 5 ${rpcs[$i]}; then + echo "URL exists: ${rpcs[$i]}" + RPC=${rpcs[$i]} + + + break + else + echo "not reachable $i" + fi +done +if [ -z "$PEERS" ] +then + echo -e "\033[0;31mNo PEERS available\033[0m" + exit +fi + +Cardchaind tx cardchain createuser $(cat ../backup/faucetaddress.txt) faucet --from jannik --gas auto --node tcp://$RPC:26657 \ No newline at end of file diff --git a/syncnode.txt b/syncnode.txt deleted file mode 100644 index f1ddc936..00000000 --- a/syncnode.txt +++ /dev/null @@ -1 +0,0 @@ -lxgr.xyz \ No newline at end of file