Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion hathor/dag_builder/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from __future__ import annotations

from typing import TYPE_CHECKING, Iterator, NamedTuple, Sequence, TypeVar
from typing import TYPE_CHECKING, Callable, Iterator, NamedTuple, Sequence, TypeVar

from hathor.dag_builder.types import DAGNode
from hathor.manager import HathorManager
Expand Down Expand Up @@ -42,6 +42,11 @@ def __init__(self, items: Iterator[tuple[DAGNode, BaseTransaction]]) -> None:

self.list: tuple[_Pair, ...] = tuple(v)
self._last_propagated: str | None = None
self._step_fns: list[Callable[[DAGNode, BaseTransaction], None]] = []

def register_step_fn(self, step_fn: Callable[[DAGNode, BaseTransaction], None]) -> None:
"""Register a new step function to be called between vertex propagations."""
self._step_fns.append(step_fn)

def get_typed_vertex(self, name: str, type_: type[T]) -> T:
"""Get a vertex by name, asserting it is of the provided type."""
Expand Down Expand Up @@ -83,6 +88,8 @@ def propagate_with(
assert manager.vertex_handler.on_new_relayed_vertex(vertex)
except Exception as e:
raise Exception(f'failed on_new_tx({node.name})') from e
for step_fn in self._step_fns:
step_fn(node, vertex)
self._last_propagated = node.name

if node.name == self._last_propagated:
Expand Down
Loading