Skip to content

Instantly share code, notes, and snippets.

@mcanvar
Last active February 3, 2021 15:23
Show Gist options
  • Save mcanvar/9692197f41de23398792e0524694e34c to your computer and use it in GitHub Desktop.
Save mcanvar/9692197f41de23398792e0524694e34c to your computer and use it in GitHub Desktop.
A status tracker for the nodes in Crypto.com Crossfire contest. We will be running below two script with this(checker.sh) automator. In ortder to run this in background: `nohup ./checker.sh >/dev/null 2>&1 &` and to stop it: `killall checker.sh`
#!/bin/bash
while true
do
#This is actually official check-validator-up.sh script, I copy to put telegram bot commands in it.
./cv.sh --tendermint-url https://crossfire.crypto.com:443 --pubkey $(cat ~/.chain-maind/config/priv_validator_key.json | jq -r '.pub_key.value')
#And this one the script @arc shared here: https://discord.com/channels/783264383978569728/790404424433926155/805786007140040804
#To get your validator address run: jq -r '.address' ~/.chain-maind/config/priv_validator_key.json
./history.sh <YOUR_VALIDATOR_ADDRESS> 10
sleep 60
done
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
RET_VALUE=0
TENDERMINT_URL=127.0.0.1:26657
echoerr() { echo "$@" 1>&2; exit 1; }
check_curl() {
set +e
command -v curl > /dev/null
RET_VALUE=$?
set -e
}
check_jq() {
set +e
command -v jq > /dev/null
RET_VALUE=$?
set -e
}
check_chain_maind() {
set +e
command -v chain-maind > /dev/null
RET_VALUE=$?
set -e
}
helpFunction() {
cat << EOF
Flags:
--help help for the script
--tendermint-url tendermint rpc interface for this chain (default "http://127.0.0.1:26657" if omitted)
--pubkey tendermint Ed25519 PubKey; can be found in ".chain-maind/config/priv_validator_key.json"
--bechpubkey bech32 consensus PubKey; converted to tendermint Ed25519 PubKey automatically; useful for node using tmkms.
EOF
exit 1 # Exit script after printing help
}
check_curl
if [[ "${RET_VALUE}" != 0 ]]; then
echoerr "curl is not installed. Please install it first."
fi
check_jq
if [[ "${RET_VALUE}" != 0 ]]; then
echoerr "jq is not installed. Please install it first."
fi
while [[ $# > 0 ]]; do
case "$1" in
--tendermint-url)
shift 1
TENDERMINT_URL="$1"
shift 1
;;
--pubkey)
shift 1
PUBKEY="$1"
shift 1
;;
--bechpubkey)
shift 1
BECH_PUBKEY="$1"
shift 1
;;
--help)
helpFunction
;;
*)
echo "Unknown argument: $1"
helpFunction
;;
esac
done
set +u
if [[ ! -z "${BECH_PUBKEY}" ]]; then
check_chain_maind
if [[ "${RET_VALUE}" != 0 ]]; then
echoerr "chain-maind is not installed or not in PATH. Please install it first or check chain-maind is added to PATH for pubkey key conversion."
fi
$(curl -s -H 'Content-Type: application/json' -d '{"chat_id":"[YOUR_TELEGRAM_BOT_CHAT_ID]", "text": "Decode Pubkey Failed ❌"}' https://api.telegram.org/bot[YOUR_TELEGRAM_BOT_API_TOKEN]/sendMessage | jq .ok)
PUBKEY=$(chain-maind debug pubkey ${BECH_PUBKEY} 2>&1 | grep "tendermint/PubKeyEd25519" | cut -d : -f2- | jq -r .value || echoerr "Decode Pubkey Failed ❌")
fi
if [[ -z "${PUBKEY}" ]]; then
$(curl -s -H 'Content-Type: application/json' -d '{"chat_id":"[YOUR_TELEGRAM_BOT_CHAT_ID]", "text": "Missing --pubkey (base64 encoded Tendermint public key)"}' https://api.telegram.org/bot[YOUR_TELEGRAM_BOT_API_TOKEN]/sendMessage | jq .ok)
echoerr "Missing --pubkey {base64 encoded Tendermint public key}"
fi
set -u
NUM=1
while true; do
ERR=$(curl -sSL "${TENDERMINT_URL}/validators?per_page=100&page=${NUM}" | jq -r .error)
if [[ $ERR == "null" ]]; then
ADDRESS=$(curl --max-time 10 -sSL "${TENDERMINT_URL}/validators?per_page=100&page=${NUM}" | jq -r --arg PUBKEY "${PUBKEY}" '.result.validators[] | select(.pub_key.value == $PUBKEY) | .address')
if [[ ! -z "${ADDRESS}" ]]; then
break;
fi
else
break;
fi;
((NUM=NUM+1))
done
if [[ -z "${ADDRESS}" ]]; then
$(curl -s -H 'Content-Type: application/json' -d '{"chat_id":"[YOUR_TELEGRAM_BOT_CHAT_ID]", "text": "The validator is not active ❌"}' https://api.telegram.org/bot[YOUR_TELEGRAM_BOT_API_TOKEN]/sendMessage | jq .ok)
echoerr "The validator is not active ❌"
else
echo "The validator is in the active validator set under the address ${ADDRESS}"
fi
HEIGHT=$(curl --max-time 10 -sSL "${TENDERMINT_URL}/block" | jq -r --arg ADDRESS "${ADDRESS}" '.result as $result | .result.block.last_commit.signatures[] | select(.validator_address | . != null and . != "" and . == $ADDRESS) | $result.block.header.height')
if [[ -z "${HEIGHT}" ]]; then
$(curl -s -H 'Content-Type: application/json' -d '{"chat_id":"[YOUR_TELEGRAM_BOT_CHAT_ID]", "text": "Not Signing ❌"}' https://api.telegram.org/bot[YOUR_TELEGRAM_BOT_API_TOKEN]/sendMessage | jq .ok)
echoerr "Not Signing ❌"
else
echo "The validator is signing @ Block#${HEIGHT} 👍"
#$(curl -s -H 'Content-Type: application/json' -d '{"chat_id":"[YOUR_TELEGRAM_BOT_CHAT_ID]", "text": "Signing at '$HEIGHT' 👍"}' https://api.telegram.org/bot[YOUR_TELEGRAM_BOT_API_TOKEN]/sendMessage | jq .ok)
fi
#!/bin/bash
address=$1
hist=$2
if [ -z "$hist" ] || [ -z $address ] || [ ! $hist -gt 0 ] ; then
echo ""
echo -e "Usage:\n\t$0 validator_address number_of_history_blocks"
echo ""
echo -e "Example:\n\t$0 0E0DA7A5005429525A080C026D8DB0E7C85C5A11 20"
echo ""
echo "Hint: you can find your validator with the command:"
echo -e "\tjq -r '.address' ~/.chain-maind/config/priv_validator_key.json"
echo ""
exit
fi
cheight=$(curl -s https://crossfire.crypto.com:443/commit | jq -r .result.signed_header.header.height)
lheight=$(expr $cheight - $hist)
sigs=0
for (( height=$lheight ; height < $cheight ; height++)); do
sig=$( curl -s https://crossfire.crypto.com:443/block?height=$height | jq -r .result.block.last_commit.signatures | grep -c $address )
#echo "$height: $sig"
sigs=$(( $sigs + $sig ))
done
perc=$( echo "$sigs / ( $hist / 100 )" | bc -l | sed '/\./ s/\.\{0,1\}0\{1,\}$//')
#$(printf "\nValidator %s signed %.2f of the last %d blocks.\n" $address $perc $hist)
#For creating and getting API keys have a look at here: https://core.telegram.org/bots#3-how-do-i-create-a-bot
#TL;DR Basically visit @botfather in telegram and create a bot, get it's API TOKEN. then we need chat id, type your bot username and send it a message, then visit this url with your token: https://api.telegram.org/bot[YOUR_BOT_API_TOKEN]/getUpdates you will find your message object, take the id under chat, this is your chat_id.
$(curl -s -H 'Content-Type: application/json' -d '{"chat_id":"[YOUR_TELEGRAM_BOT_CHAT_ID]", "text": "Signed '$perc'% of the last '$hist' blocks."}' https://api.telegram.org/bot[YOUR_TELEGRAM_BOT_API_TOKEN]/sendMessage | jq .ok)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment