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)
def _get_canonical_crystallized_state_root(db: BaseDB, slot: int) -> Hash32: validate_slot(slot) slot_to_hash_key = SchemaV1.make_slot_to_crystallized_state_lookup_key( slot) try: encoded_key = db[slot_to_hash_key] except KeyError: raise StateRootNotFound( "No canonical crystallized state for slot #{0}".format(slot)) else: return rlp.decode(encoded_key, sedes=rlp.sedes.binary)
def test_validate_slot(slot, is_valid): if is_valid: validate_slot(slot) else: with pytest.raises(ValidationError): validate_slot(slot)
def _get_canonical_block_by_slot(cls, db: BaseDB, slot: int) -> BaseBeaconBlock: validate_slot(slot) canonical_block_hash = cls._get_canonical_block_hash(db, slot) return cls._get_block_by_hash(db, canonical_block_hash)
def _get_canonical_block_hash_by_slot(cls, db: BaseDB, slot: int) -> Hash32: validate_slot(slot) return cls._get_canonical_block_hash(db, slot)