def _find_oldest_unpruned_task_id(self, finished_task_id: TTaskID) -> TTaskID: get_dependency_of_id = compose( curry(do)(self._validate_has_task), self._dependency_of, attrgetter('task'), self._tasks.get, ) ancestors = iterate(get_dependency_of_id, finished_task_id) return nth(self._max_depth, ancestors)
def get_ancestor_hash(self, block_number: int) -> Hash32: ancestor_depth = self.block_number - block_number - 1 is_ancestor_depth_out_of_range = ( ancestor_depth >= MAX_PREV_HEADER_DEPTH or ancestor_depth < 0 or block_number < 0) if is_ancestor_depth_out_of_range: return Hash32(b'') try: return nth(ancestor_depth, self.execution_context.prev_hashes) except StopIteration: # Ancestor with specified depth not present return Hash32(b'')
def get_ancestor_hash(self, block_number: int) -> Hash32: """ Return the hash for the ancestor block with number ``block_number``. Return the empty bytestring ``b''`` if the block number is outside of the range of available block numbers (typically the last 255 blocks). """ ancestor_depth = self.block_number - block_number - 1 is_ancestor_depth_out_of_range = ( ancestor_depth >= MAX_PREV_HEADER_DEPTH or ancestor_depth < 0 or block_number < 0) if is_ancestor_depth_out_of_range: return Hash32(b'') try: return nth(ancestor_depth, self.execution_context.prev_hashes) except StopIteration: # Ancestor with specified depth not present return Hash32(b'')
def flatten(self) -> None: if self.is_flattened: return checkpoint_after_root = nth(1, self._checkpoint_stack) self.commit_checkpoint(checkpoint_after_root)
def flatten(self) -> None: if self.is_flattened: return changeset_id_after_root = nth(1, self.journal_data.keys()) self.commit_changeset(changeset_id_after_root)
def test_cached_generator(): use_once = itertools.count() repeated_use = CachedIterable(use_once) for find_val in [1, 0, 10, 5]: assert find_val == nth(find_val, repeated_use)