Cardano-db-sync: Add nullable slot_leader.pool_hash_id

Created on 19 Jul 2020  ·  4Comments  ·  Source: input-output-hk/cardano-db-sync

To enable a model of Block.forgedBy -> StakePool and StakePool.blocksForged -> [Block]
See https://github.com/input-output-hk/cardano-ledger-specs/pull/1637

enhancement

Most helpful comment

Yea, you can get to pool id through the slot_leaders table. It would, however, be very convenient if we could have the pool id in the slot leader table rather than part of the vkey. I currently convert the vkey to a pool id as follows and store it in a new column in the slot leader table:

vkey = "5820"+p['hash'][2:]
h = hashlib.blake2b(digest_size=28)
h.update(binascii.unhexlify(p['hash'][2:]))
poolid = h.hexdigest()

This allows me to do a join and build out blocks per pool fairly easily.

All 4 comments

Doesn't this duplicate the slot_leader table?

Yea, you can get to pool id through the slot_leaders table. It would, however, be very convenient if we could have the pool id in the slot leader table rather than part of the vkey. I currently convert the vkey to a pool id as follows and store it in a new column in the slot leader table:

vkey = "5820"+p['hash'][2:]
h = hashlib.blake2b(digest_size=28)
h.update(binascii.unhexlify(p['hash'][2:]))
poolid = h.hexdigest()

This allows me to do a join and build out blocks per pool fairly easily.

@disassembler Yes, it would. I've updated the title to extend the leaders table with a key for joining easily

@papacarp thanks for adding your workaround. Hopefully you can refactor away from this, as modifying schema of the tables managed by cardano-db-sync is advised against by @erikd

Was this page helpful?
0 / 5 - 0 ratings

Related issues

erikd picture erikd  ·  10Comments

erikd picture erikd  ·  4Comments

alexqrid picture alexqrid  ·  11Comments

erikd picture erikd  ·  3Comments

kzka90 picture kzka90  ·  3Comments