Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publicnode #173

Merged
merged 2 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 17 additions & 0 deletions peer_nodes.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
2 changes: 1 addition & 1 deletion scripts/buildlaunch-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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")
23 changes: 22 additions & 1 deletion scripts/register_faucet.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
1 change: 0 additions & 1 deletion syncnode.txt

This file was deleted.

Loading