Skip to content

Instantly share code, notes, and snippets.

@PaulVMo
Last active May 13, 2022 16:53
Show Gist options
  • Save PaulVMo/cce7b21c86e714bca8e615b2e406ca7b to your computer and use it in GitHub Desktop.
Save PaulVMo/cce7b21c86e714bca8e615b2e406ca7b to your computer and use it in GitHub Desktop.
Helium Validator GRPC Port Checker
#!/bin/bash
# For each staked validator, get the release version
# command to call miner of the desired validator to use
MINER=miner1
# connect to each validator first so the peerbook is fresh
for val in $(${MINER} ledger validators --format csv -v | awk -F, '$7 == "staked" {print $2}');
do
${MINER} peer connect /p2p/${val}
done
# clear csv. format is: validator address, grpc address, port reachable status
echo "address,ip,grpc_port,port_status" > validatorGRPCPorts.csv
# for each validator, get the grpc address from the peerbook, then check it for connectivity
for val in $(${MINER} ledger validators --format csv -v | awk -F, '$7 == "staked" {print $2}');
do
# use miner eval to get the signed metadata which contains the grpc_address
grpc_address=$(${MINER} eval 'SM=libp2p_peer:signed_metadata(element(2,libp2p_peerbook:get(libp2p_swarm:peerbook(blockchain_swarm:tid()), libp2p_crypto:pubkey_to_bin(libp2p_crypto:b58_to_pubkey("'${val}'"))))),binary_to_list(maps:get(<<"grpc_address">>,SM)).')
#echo $grpc_address
if [[ "$grpc_address" =~ .*"badkey".* ]]; then
echo "${val}: not_found"
echo "${val},not_found,not_found,no_port_not_upgraded" >> validatorGRPCPorts.csv
elif [[ "$grpc_address" =~ .*"not_found".* ]]; then
echo "${val}: not_found"
echo "${val},not_found,not_found,not_found_in_peerbook" >> validatorGRPCPorts.csv
else
ip=$(echo ${grpc_address} | sed 's/http:\/\///' | sed 's/"//' | sed 's/:/ /' | awk '{print $1}' )
port=$(echo ${grpc_address} | sed 's/"//' | sed 's/"//' | sed 's/http:\/\///' | sed 's/:/ /' | awk '{print $2}' )
nc -z -w 2 $ip $port
if [[ $? == 0 ]]; then
echo "${val}: ${grpc_address} is open"
echo "${val},${ip},${port},open," >> validatorGRPCPorts.csv
else
echo "${val}: ${grpc_address} timeout"
echo "${val},${ip},${port},timeout," >> validatorGRPCPorts.csv
fi
fi
done
echo "\n---SUMMARY---\n"
cat validatorGRPCPorts.csv | awk -F, '{count[$4]++} END {for (word in count) print word, "\t" count[word]}' | sort > validatorGRPCSummary
cat validatorGRPCSummary
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment