Exemplo n.º 1
0
 def _get_canonical_block_hash(db: BaseDB, slot: int) -> Hash32:
     validate_slot(slot)
     slot_to_hash_key = SchemaV1.make_block_slot_to_hash_lookup_key(slot)
     try:
         encoded_key = db[slot_to_hash_key]
     except KeyError:
         raise BlockNotFound(
             "No canonical block for block slot #{0}".format(slot))
     else:
         return rlp.decode(encoded_key, sedes=rlp.sedes.binary)
Exemplo n.º 2
0
 def _add_block_slot_to_hash_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_hash_key = SchemaV1.make_block_slot_to_hash_lookup_key(
         block.slot_number)
     db.set(
         block_slot_to_hash_key,
         rlp.encode(block.hash, sedes=rlp.sedes.binary),
     )
Exemplo n.º 3
0
def test_chaindb_add_block_number_to_hash_lookup(chaindb, block):
    block_slot_to_hash_key = SchemaV1.make_block_slot_to_hash_lookup_key(
        block.slot)
    assert not chaindb.exists(block_slot_to_hash_key)
    chaindb.persist_block(block)
    assert chaindb.exists(block_slot_to_hash_key)