def _get_state_root_by_slot(db: DatabaseAPI, slot: Slot) -> Hash32: """ Return the requested beacon state as specified by slot. Raises StateNotFound if it is not present in the db. """ slot_to_state_root_key = SchemaV1.make_slot_to_state_root_lookup_key(slot) try: state_root = db[slot_to_state_root_key] except KeyError: raise StateNotFound("No state root for slot #{0}".format(slot)) else: return Hash32(state_root)
def _get_state_by_root(db: DatabaseAPI, state_root: Hash32, state_class: Type[BeaconState]) -> BeaconState: """ Return the requested beacon state as specified by state hash. Raises StateNotFound if it is not present in the db. """ # TODO: validate_state_root try: state_ssz = db[state_root] except KeyError: raise StateNotFound( f"No state with root {encode_hex(state_root)} found") return _decode_state(state_ssz, state_class)