IntersectMBO / cardano-db-sync

A component that follows the Cardano chain and stores blocks and transactions in PostgreSQL
Apache License 2.0
288 stars 162 forks source link

No information on block table for blocks not created by pools #1377

Closed saratomaz closed 1 year ago

saratomaz commented 1 year ago

OS Your OS: Ubuntu

Versions The db-sync version (eg cardano-db-sync --version): 13.1.0.0 PostgreSQL version: 13.6

Build/Install Method The method you use to build or install cardano-db-sync: nix

Additional context Steps to reproduce:

  1. Starting cardano-node-tests local cluster details --> script used to start the cluster

  2. Check the tables block and epoch for the first epochs, the values don't match.

    SELECT block.id, block.epoch_no, block.slot_no, block.epoch_slot_no, block.block_no, block.previous_id, block.tx_count, block.proto_major, block.proto_minor, pool_hash.view 
    FROM block INNER JOIN slot_leader ON slot_leader.id = block.slot_leader_id INNER JOIN pool_hash ON pool_hash.id = slot_leader.pool_hash_id 
    WHERE (epoch_no BETWEEN 0 AND 2) ORDER BY block.id;
SELECT epoch.id, epoch.out_sum, epoch.fees, epoch.tx_count, epoch.blk_count, epoch.no 
FROM epoch 
WHERE (no BETWEEN 0 AND 2);

Problem Report

Using our local cluster I see zero blocks on block table for the first 3 epochs, and on the epoch table the blk_count is different than zero.

Some context about our local cluster: With local cluster, we start in Byron era, there is no concept of stake pools yet and all blocks are created by bft node. In epoch 1 we are in Shelley era and we create stake pools. However these pool are too new to create any blocks, so all blocks are created by bft node. In epoch 2 the pools still can't create any blocks - they need to be working for at least one whole epoch before they can start creating blocks. Again, all blocks are created by bft node. In epoch 3 the pools are ready to create blocks, and since d = 0, all blocks are created by pools and bft node no longer creates any blocks.

erikd commented 1 year ago

@saratomaz In the Byron era, all blocks were produced by 7 block producers run by IOHK/IOG and there were no pools.

However, your query includes INNER JOIN pool_hash ON pool_hash.id = slot_leader.pool_hash_id . For Byron there are exactly zero blocks that will satisfy that requirement.