Check sync status of node

Hi,

Could anyone please explain me how to check the sync status of my node with the network?
The following script used to work:

GENESIS=shelley-genesis.json
start=$(jq -r '.systemStart' $GENESIS)
start_sec=$(date -d $start +'%s')
epoch_length=$(jq -r '.epochLength' $GENESIS)
now=$(date +'%s')
epoch=$(expr \( $now - $start_sec \) / $epoch_length)
slot=$(expr \( $now - $start_sec \) % $epoch_length)
unSlot=$(expr $epoch \* $epoch_length + $slot)
currentUnSlot=$(cardano-cli shelley query tip ${NETWORK_ARGUMENT} | jq -r '.slotNo')
echo "slot $currentUnSlot/$unSlot $(expr $currentUnSlot \* 100 / $unSlot)%"

but it does not seem to produce the correct result anymore.

No one can help with this?
There must be some way to check if your node is completely up to date with the network, as its necessary for the node to be synced when getting the tip for defining the TTL for transactions, KES keys, etc. ?

cardano-cli shelley query tip --testnet-magic 42

will output the current tip info example

{
“blockNo”: 11188,
“headerHash”: “119f763db992b60bb53415e840ad08f1cd8f329add9d8c4f97e60ab709253350”,
“slotNo”: 222400
}

sorry I don’t frequent the forums I have several other places I am watching like telegram reddit discord I would suggest joining the telegram channel we can usually help you more timely there

Thank you for your response glitch.
But, I know that command, and it doesn’t give any info regarding the tip of the blockchain, only where my current node is at.

I need to know that my node is completely synced (my tip is the same as the tip of the blockchain) before using my tip to calculate the TTL, etc. right?

There are other sources to check against to get the current tip to compare such as pooltool or the grafana instances iohk has hosted or the explorer.
The reason this script is likely broken is from the change over from Byron to Shelley with the use of both networks you need to check against the genesis info in the proper file which depends on the epoch you are in at the time.


https://monitoring.mainnet-candidate-4.dev.cardano.org/grafana/d/Oe0reiHef/cardano-application-metrics-v2?orgId=1&refresh=1m
https://explorer.mainnet-candidate-4.dev.cardano.org/en

Okay, thank you for that.
It would be nice if it was possible to check directly from the node though.
The following script used to work:

GENESIS=shelley-genesis.json
start=$(jq -r '.systemStart' $GENESIS)
start_sec=$(date -d $start +'%s')
epoch_length=$(jq -r '.epochLength' $GENESIS)
now=$(date +'%s')
epoch=$(expr \( $now - $start_sec \) / $epoch_length)
slot=$(expr \( $now - $start_sec \) % $epoch_length)
unSlot=$(expr $epoch \* $epoch_length + $slot)
currentUnSlot=$(cardano-cli shelley query tip ${NETWORK_ARGUMENT} | jq -r '.slotNo')
echo "slot $currentUnSlot/$unSlot $(expr $currentUnSlot \* 100 / $unSlot)%"

But now its stuck at 91% for the mainnet-candidate.

my assumption on this as I haven’t tried is that you would use the “shelley” side and calculate the approximate location based on the info inside that genesis file which has changed from the previous shelley chains for MC… if you need more support on this I would suggest going to the telegram channel

Okay, thank you.

1 Like

Hi,

It looks like the script I posted a month ago in telegram workgroup channel.
It was made for chains in Shelley mode only, as it ignores the Byron area.

Here is an updated version (in bash to be a slightly more legible) that should work with current mainnet candidate 4 and should hopefully work with mainnet once the HARDFORK_EPOCH and NETWORK constants are updated correctly:

#!/bin/bash

GENESIS=genesis.json
BYRON_GENESIS=byron-genesis.json
HARDFORK_EPOCH=1 # MC4 only, to be updated for mainnet
NETWORK="--testnet-magic 42" # replace by --mainnet for mainnet

epoch_length=$(jq -r .epochLength $GENESIS)
slot_length=$(jq -r .slotLength $GENESIS)
byron_slot_length=$(( $(jq -r .blockVersionData.slotDuration $BYRON_GENESIS) / 1000 ))
byron_epoch_length=$(( $(jq -r .protocolConsts.k $BYRON_GENESIS) * 10 ))

byron_start=$(jq -r .startTime $BYRON_GENESIS)
byron_end=$((byron_start + HARDFORK_EPOCH * byron_epoch_length * byron_slot_length))
byron_slots=$(($HARDFORK_EPOCH * byron_epoch_length))
now=$(date +'%s')

expected_slot=$((byron_slots + (now - byron_end) / slot_length))
current_slot=$(cardano-cli shelley query tip $NETWORK | jq -r '.slotNo')
percent=$(echo -e "scale=2\n$current_slot * 100 / $expected_slot" | bc)

echo "slot ${current_slot}/${expected_slot} ${percent}%"

For example currently:

$ sync
slot 236000/236002 99.99%

Edit: Updated using some improvements for mainnet from the great folks at cardano-community/guild-operators. Note that it will correctly work only once the hard fork period is completed as I have not handled the transition period.

5 Likes

Thank you very much Smaug!

1 Like

Also, I just wanted to leave you a “thank you”. This was helpful to me :slight_smile: