Skip to content

Instantly share code, notes, and snippets.

@haskellcoding29
Forked from elmostake/delta2.sh
Created December 24, 2019 15:08
Show Gist options
  • Save haskellcoding29/71e9130a345799e482e9d0ff066dc38a to your computer and use it in GitHub Desktop.
Save haskellcoding29/71e9130a345799e482e9d0ff066dc38a to your computer and use it in GitHub Desktop.
Function for getting the delta between your lastBlockCount and the one from the Shelley Explorer (add to .bash_profile)
# Note that it seems like the explorer is load balanced across multiple nodes, as sometimes a call will show that
# you are ahead by a few blocks, but an immediate subsequent call will show you are in sync.
# Add this to your .bash_profile
function delta2() {
# Kudos to @pheelLikeWater for original version of this!
lastBlockHash=`stats | head -n 6 | tail -n 1 | awk '{print $2}'`
lastBlockCount=`stats | head -n 7 | tail -n 1 | awk '{print $2}' | tr -d \"`
shelleyExplorerJson=`curl -X POST -H "Content-Type: application/json" --data '{"query":" query { allBlocks (last: 1) { pageInfo { hasNextPage hasPreviousPage startCursor endCursor } totalCount edges { node { id date { slot epoch { id firstBlock { id } lastBlock { id } totalBlocks } } transactions { totalCount edges { node { id block { id date { slot epoch { id firstBlock { id } lastBlock { id } totalBlocks } } leader { __typename ... on Pool { id blocks { totalCount } registration { startValidity managementThreshold owners operators rewards { fixed ratio { numerator denominator } maxLimit } rewardAccount { id } } } } } inputs { amount address { id } } outputs { amount address { id } } } cursor } } previousBlock { id } chainLength leader { __typename ... on Pool { id blocks { totalCount } registration { startValidity managementThreshold owners operators rewards { fixed ratio { numerator denominator } maxLimit } rewardAccount { id } } } } } cursor } } } "}' https://explorer.incentivized-testnet.iohkdev.io/explorer/graphql`
shelleyLastBlockCount=`echo $shelleyExplorerJson | grep -o '"endCursor":"[^"]*' | cut -d'"' -f4`
deltaBlockCount=`echo $(($shelleyLastBlockCount-$lastBlockCount))`
echo "----------"
echo "LastBlockCount: " $lastBlockCount
echo "LastShelleyBlockCount: " $shelleyLastBlockCount
echo "DeltaBlockCount: " $deltaBlockCount
echo "----------"
# Once the delta is greater (node is behind explorer) than 3, or less than -3 (node is ahead of
# explorer), output a warning. If alerting from logs you can grep for "DeltaBlockCountWarning"
if [ $deltaBlockCount -gt 3 ]
then
echo "[DeltaBlockCountWarningBehind] Node is behind Explorer, delta: " $deltaBlockCount
echo "----------"
elif [ $deltaBlockCount -lt -3 ]
then
echo "[DeltaBlockCountWarningAhead] Node is ahead of Explorer, delta: " $deltaBlockCount
echo "----------"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment