def _get_active_state_root_by_crystallized( db: BaseDB, crystallized_state_root: Hash32) -> Hash32: state_root_to_hash_key = SchemaV1.make_crystallized_to_active_state_root_lookup_key( crystallized_state_root) try: encoded_key = db[state_root_to_hash_key] except KeyError: raise StateRootNotFound( "No canonical active state for crystallized_state_root #{0}". format(state_root_to_hash_key)) 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 apply_transaction(self, transaction): """ Apply transaction to the vm state :param transaction: the transaction to apply :return: the new state root, and the computation """ if self.state_root != BLANK_ROOT_HASH and not self.account_db.has_root(self.state_root): raise StateRootNotFound(self.state_root) computation = self.execute_transaction(transaction) state_root = self.account_db.make_state_root() return state_root, computation
def _get_state_by_root(db: BaseDB, state_root: Hash32) -> BeaconState: """ Return the requested beacon state as specified by state hash. Raises StateRootNotFound if it is not present in the db. """ # TODO: validate_state_root try: state_rlp = db[state_root] except KeyError: raise StateRootNotFound(f"No state with root {encode_hex(state_root)} found") return _decode_state(state_rlp)
def apply_transaction( self, transaction: BaseOrSpoofTransaction) -> 'BaseComputation': """ Apply transaction to the vm state :param transaction: the transaction to apply :return: the computation """ if self.state_root != BLANK_ROOT_HASH and not self._account_db.has_root(self.state_root): raise StateRootNotFound(self.state_root) else: return self.execute_transaction(transaction)
def _get_active_state_by_root(db: BaseDB, state_root: Hash32) -> ActiveState: """ Return the requested crystallized state as specified by state hash. Raises StateRootNotFound if it is not present in the db. """ # TODO: validate_active_state_root try: state_rlp = db[state_root] except KeyError: raise StateRootNotFound("No state with root {0} found".format( encode_hex(state_rlp))) return _decode_active_state(state_rlp)
def _get_state_by_slot(db: BaseDB, slot: Slot, state_class: Type[BeaconState]) -> BeaconState: """ Return the requested beacon state as specified by slot. Raises StateSlotNotFound 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_ssz = db[slot_to_state_root_key] except KeyError: raise StateSlotNotFound("No state root for slot #{0}".format(slot)) state_root = ssz.decode(state_root_ssz, sedes=ssz.sedes.bytes32) try: state_ssz = db[state_root] except KeyError: raise StateRootNotFound( f"No state with root {encode_hex(state_root)} found") return _decode_state(state_ssz, state_class)