Cardano-node: Obtaining Sync Percentage Value

Created on 8 Apr 2020  路  3Comments  路  Source: input-output-hk/cardano-node

Hi Guys, I'm trying to write a software that integrates with the cardano node but I have no details on how to get the sync percent value so I will know when to interact with the blockchain.

Thanks!

Most helpful comment

Querying the db-sync database, the slot number of the most recent slot added to the database can be obtained using:

select slot_no from block where block_no is not null
    order by block_no desc limit 1 ;

The current slot (possibly not yet in the database) can be calculated using:

select extract (epoch from (select now() - start_time from meta)) * 1000 /
    slot_duration from meta ;

With Shelley these queries may need to change, but for the duration of Byron they are correct.

All 3 comments

Getting this directly from the node is currently not really possible (and may never be), but is definitely possible right now with cardabo-db-sync where it would simply be a (mildly complex) SQL query.

Querying the db-sync database, the slot number of the most recent slot added to the database can be obtained using:

select slot_no from block where block_no is not null
    order by block_no desc limit 1 ;

The current slot (possibly not yet in the database) can be calculated using:

select extract (epoch from (select now() - start_time from meta)) * 1000 /
    slot_duration from meta ;

With Shelley these queries may need to change, but for the duration of Byron they are correct.

Thank you, but I also just found out that Cardano Wallet has a /v2/network/information API that provides the following information that I need. For example

{
  "network_tip": {
    "epoch_number": 185,
    "slot_number": 12505
  },
  "node_tip": {
    "height": {
      "quantity": 5032,
      "unit": "block"
    },
    "epoch_number": 0,
    "slot_number": 5031
  },
  "sync_progress": {
    "status": "syncing",
    "progress": {
      "quantity": 0.13,
      "unit": "percent"
    }
  },
  "next_epoch": {
    "epoch_start_time": "2020-04-10T21:44:51Z",
    "epoch_number": 186
  }
}

I will use this for now, untill my needs will require cardano-db-sync

Was this page helpful?
0 / 5 - 0 ratings