cardano-community / koios-artifacts

Artifacts for https://koios.rest and https://api.koios.rest websites
Creative Commons Attribution 4.0 International
20 stars 25 forks source link

Build last epoch Active stake cache #49

Closed rdlrt closed 2 years ago

rdlrt commented 2 years ago

Is your feature request related to a problem? Please describe. cardano-db-sync [v10-v13] does not know of active stake from last epoch, and has to wait for a while before it's able to finish calculation of active stake from 'active' epoch (new epoch - 2) prior to epoch transition. This results in active stake being reported as null for few hours post entering new epoch for any stake addresses. One option could be to have a special condition for stake distribution cache at epoch transition to fill the data in recent_epoch_stake table.

Describe the solution you'd like Build an active stake cache dedicated to pre-filling the information after recently finished epoch, to have the data ready to read upon next epoch transition

Describe alternatives you've considered Wait for fixes upstream, but that will likely be deferred to v14

Additional context With the recent changes on node post 1.35, there will be increase in reliance on query layers like Koios' gRest (remotely or as local instance), it will also prevent being able to provide leadership schedule nonce right at epoch transition easily

dostrelith678 commented 2 years ago

Links to #52

  1. new cron job at end of epoch (5 mins into new epoch)
  2. structure: addr_id, epoch_no, amount
  3. maintain n - 1 and n-2 epoch active stake cache (based on each account)
  4. Use the code from SDC with the previous epoch last block upper boundary
  5. Update affected endpoints