def test_chaindb_add_block_number_to_root_lookup(chaindb, block, fork_choice_scoring): block_slot_to_root_key = SchemaV1.make_block_slot_to_root_lookup_key( block.message.slot) assert not chaindb.exists(block_slot_to_root_key) chaindb.persist_block(block, block.__class__, fork_choice_scoring) assert chaindb.exists(block_slot_to_root_key)
def _add_block_slot_to_root_lookup(db: DatabaseAPI, 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, block.message.hash_tree_root)
def _get_canonical_block_root(db: DatabaseAPI, slot: Slot) -> Root: slot_to_root_key = SchemaV1.make_block_slot_to_root_lookup_key(slot) try: root = db[slot_to_root_key] except KeyError: raise BlockNotFound("No canonical block for block slot #{0}".format(slot)) else: return cast(Root, root)
def _get_canonical_block_root(db: DatabaseAPI, slot: Slot) -> Hash32: 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 ssz.decode(encoded_key, sedes=ssz.sedes.bytes32)
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: DatabaseAPI, 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, ssz.encode(block.signing_root, sedes=ssz.sedes.bytes32), )
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)