0

I tried to get all the snapshots data via the tzstats API. Here you find the documentation for the snapshots: https://tzstats.com/docs/api#snapshot-table

As far as I know there are 16 snapshots taken per cycle. A cycle has 4096 blocks and we have roughly 1.6 million blocks. Now we have roughly 400 cycles therefore we should have 400* 16 = 6400 snapshots. The problem is that with my request i get way more snapshots (in the range of 100'000). Why do I get too many snapshots? And how do I get only the 6400 snapshots that I want? Who creates this snapshot (the system itself or a "supernode"?) Note: For every cycle i get between 100 and 500 snapshots (multiplied by about 400 cycles we get about 40'000/50'000 snapshots in total for all cycles ), where an index occurs multiple times. The index is between 0 and 15 and indicates which snapshot it is and therefore for a single cycle each index should occur only once. Below you find my code for the request. One has to request the snapshots with the addresses. I got all the addresses which are about 394 baker addresses.

api_url_bakers = 'https://api.tzstats.com/explorer/bakers'
params = {'limit': 10000}
r = requests.get(api_url_bakers, params=params)
baker_response = r.json()

addresses = [r['address'] for r in baker_response]
snapshots= []
for address in addresses: 
    r = requests.get(snapshot_table_api_url + '?address=' + address + "&cycle=57", params=params)
    snapshot_response = r.json()
    snapshots.extend(snapshot_response)

Thanks for your help. Best regards, Anja

1

1 Answer 1

0

A cycle has 8192 blocks since Granada. You must take this calculation into account. Before block 1589247, there were 4096 blocks per cycle, but after that, there are now 8192 per cycle. After Granada, snapshots were taken every 512 blocks, but before Granada, every 256.

7
  • Thanks for your answer. Good to know that but when i take for example the cycle 57 (which is in Athens i think, way before granada) there are also too many snapshots. So also before Granada i have more than the expected 6500 snapshots. For every index (0 to 15) in a cycle there are multiple entries which does not make sense because in a cycle (before granada) we have only 16 snapshots. Oct 21, 2021 at 14:22
  • The API you are using is for fetching the snapshot of the chain, not for fetching the snapshot metadata. I think what you want is this: api.tzstats.com/tables/block?cycle=150&is_cycle_snapshot=1 which will tell you the metadata for the chosen snapshot block for a specific cycle.
    – utdrmac
    Oct 22, 2021 at 16:23
  • Thanks a lot. That makes sense. The thing is that i need the roll distribution. And from the blocks table with the API link you sent i do not get the roll distribution. Do you know how I can get this? Thanks :) Oct 26, 2021 at 6:01
  • curl "api.tzstats.com/explorer/bakers" <-- rolls for each baker. curl "api.tzstats.com/explorer/cycle/X" <-- total rolls for cycle X. Please read the tzstats docs entirely, that's all I'm doing and posting here. :P Join tzstats discord as the lead dev/owner is very responsive.
    – utdrmac
    Oct 27, 2021 at 1:31
  • what is the tzstats discord? i.e. how can I find it? Oct 27, 2021 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.