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.

6 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:

yeah i am also finding the docs and help not to great. i am syncing for last 2 days and its so slow that i will take over a year at this rate to have my node fully synced ? there is no discort chat only tg and when you ask devs questions for help they are to up them selfs to help. Not Good.

should it be so slow at syncing, i am on block slot 21683218 and its taken days one block every few minutes is not good

        GENESIS=/testnet-shelley-genesis.json
        BYRON_GENESIS=/testnet-byron-genesis.json
        HARDFORK_EPOCH=1 # MC4 only, to be updated for mainnet
        NETWORK="--testnet-magic 1097911063" # 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 query tip $NETWORK | jq -r '.slot')
        percent=$(echo -e "scale=2\n$current_slot * 100 / $expected_slot" | bc)

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

UPDATED SCRIPT FOR TESTNET IN VERSION 1.26

1 Like

Running this on mainet with the only change being to replace $NETWORK is unlikely to give the correct results. You will also need to replace the testnet genesis config files with the relevant mainnet ones.

Update: This script has been confirmed to be wrong when run on mainnet.

Update #2: A better solution would be the implementation of the ticket Add a synchronisation percentage figure to the query tip command output .

2 Likes

It was very helpful. Thank you.

I made it for mainnet.

The output at the current time is shown below.
slot 34006443/34006449 99.99%

#!/bin/sh

GENESIS=mainnet-shelley-genesis.json
BYRON_GENESIS=mainnet-byron-genesis.json
HARDFORK_EPOCH=208
NETWORK="--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 query tip $NETWORK | jq -r '.slot')
percent=$(echo -e "scale=2\n$current_slot * 100 / $expected_slot" | bc)

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

Thank you very much. This was very helpful & works great. Much appreciated

Guys, just a small remark.
You don’t really need to parse Byron stuff all the time, do you?
Byron variables are constants.

Given,

BYRON_END_TIME=“1596059091”
BYRON_SLOTS=“4492800”

Everything else boils down to only a couple of lines.

If you are using testnet configurations for example, the variables are different. So that is why they are not defined as constants in the script. :slight_smile:

hi SirPickelhaupt,

Have you solved your problem. I’m also want to how much percentage synchronisation is completed. Could you please help me out. I have installed Cardano 1.35.3.

CARDANO_NODE_SOCKET_PATH='/run/cardano/mainnet-node.socket' cardano-cli query tip --mainnet

{
“block”: 7153708,
“epoch”: 334,
“era”: “Alonzo”,
“hash”: “31fa984f2c4829563a6f072bd073960cd4ee2e92888ea24c0c52eb368e98746f”,
“slot”: 59031834,
“syncProgress”: “90.65”
}