Example #1
0
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)
Example #2
0
 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)
Example #3
0
 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)
Example #4
0
 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)
Example #5
0
 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)
Example #6
0
 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),
     )
Example #7
0
 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),
     )
Example #8
0
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)