cardano-db-sync icon indicating copy to clipboard operation
cardano-db-sync copied to clipboard

Db sync record inconsistent with Ledger state

Open dodinhvit23f opened this issue 1 year ago • 8 comments

On preprod netword with cardano-node version: 1.35.3 with dbsync version 13.0.5

When I extracted ledger state from cardano-cli to dump data for each epoch then I saw inconsistent from epoch 32 in tables (Epoch Param, Epoch Stake etc.).

Can your guy provide me the logic or SQL query to calculate amount of stake address delegation to a pool ( 1 record in Epoch Stake table). How to insert Epoch Param table .

dodinhvit23f avatar Apr 05 '23 02:04 dodinhvit23f

Could you provide a more spicific example which was inconsistent? Btw there are newer release with a number of improvements, butr afaik nothing related to Epoch Param, Epoch Stake

kderme avatar Apr 05 '23 18:04 kderme

oh yes, The inconsistent is between epoch stake records. For example: In preprod network, table epoch stake, epoch 56. with stake address: e04bec2d4e59e40ffc8ac4ed7e3b1e5b32cdc821f5f4b8447cc06d021f( address hash) delegate to pool : 7facad662e180ce45e5c504957cd1341940c72a708728f7ecfc6e349 (pool hash).

The stake amount :

  • in dbsync :83,307,794,628
  • in ledger dump: 86,027,102,326

You also can see ledger dump in here: Epoch 57

dodinhvit23f avatar Apr 06 '23 02:04 dodinhvit23f

Seems to match here (since you've sent dump for epoch 57, assume you meant to check active stake at epoch 57)?

select es.amount, encode(ph.hash_raw,'hex') as pool from epoch_stake es inner join pool_hash ph on es.pool_id=ph.id where es.addr_id in (select id from stake_address where hash_raw = decode('e04bec2d4e59e40ffc8ac4ed7e3b1e5b32cdc821f5f4b8447cc06d021f','hex')) and epoch_no=57;
   amount    |                           pool
-------------+----------------------------------------------------------
 86027102326 | 7facad662e180ce45e5c504957cd1341940c72a708728f7ecfc6e349
(1 row)

rdlrt avatar Apr 06 '23 02:04 rdlrt

I think when i dump epoch 57, the 'pstakeSet' stake would be insert for active epoch 56, right ?

dodinhvit23f avatar Apr 06 '23 02:04 dodinhvit23f

select es.amount, encode(ph.hash_raw,'hex') as pool from epoch_stake es inner join pool_hash ph on es.pool_id=ph.id where es.addr_id in (select id from stake_address where hash_raw = decode('e04bec2d4e59e40ffc8ac4ed7e3b1e5b32cdc821f5f4b8447cc06d021f','hex')) and epoch_no=57;

May I ask, which version of node and dbsync you use ? Because when i use your query mine db return 84261213980 7facad662e180ce45e5c504957cd1341940c72a708728f7ecfc6e349

dodinhvit23f avatar Apr 06 '23 02:04 dodinhvit23f

which version of node and dbsync you use ?

For this instance, node 1.35.7 w/dbsync 13.1.0.0

rdlrt avatar Apr 06 '23 02:04 rdlrt

which version of node and dbsync you use ?

For this instance, node 1.35.7 w/dbsync 13.1.0.0

With your node and dbsync version, I tried the above query but the result is the same with @dodinhvit23f

ducpm2303 avatar Apr 10 '23 10:04 ducpm2303

As documented in https://github.com/input-output-hk/cardano-db-sync/blob/master/doc/schema.md#epoch_stake the epoch_stake table is populated incrementally in the first blocks of each epoch. So the result of this query is not stable until the epoch changes or a few blocks pass.

kderme avatar Apr 13 '23 10:04 kderme