def _get_canonical_block_root(db: BaseDB, slot: int) -> Hash32: validate_slot(slot) slot_to_root_key = SchemaV1.make_block_slot_to_root_lookup_key(slot) try: encoded_key = db[slot_to_root_key] except KeyError: raise BlockNotFound( "No canonical block for block slot #{0}".format(slot)) else: return rlp.decode(encoded_key, sedes=rlp.sedes.binary)
def _add_block_slot_to_root_lookup(db: BaseDB, block: BaseBeaconBlock) -> None: """ Set a record in the database to allow looking up this block by its block slot. """ block_slot_to_root_key = SchemaV1.make_block_slot_to_root_lookup_key( block.slot) db.set( block_slot_to_root_key, rlp.encode(block.root, sedes=rlp.sedes.binary), )
def test_chaindb_add_block_number_to_root_lookup(chaindb, block): block_slot_to_root_key = SchemaV1.make_block_slot_to_root_lookup_key(block.slot) assert not chaindb.exists(block_slot_to_root_key) chaindb.persist_block(block, block.__class__) assert chaindb.exists(block_slot_to_root_key)