Skip to content

Commit 389509b

Browse files
committed
refactor(nano): Make NCBlockExecutor a pure executor with no side effects
1 parent f618470 commit 389509b

File tree

5 files changed

+433
-241
lines changed

5 files changed

+433
-241
lines changed

hathor/consensus/block_consensus.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
from hathor.conf.settings import HathorSettings
3232
from hathor.consensus.context import ConsensusAlgorithmContext
3333
from hathor.feature_activation.feature_service import FeatureService
34-
from hathor.nanocontracts.execution import NCBlockExecutor
34+
from hathor.nanocontracts.execution import NCConsensusBlockExecutor
3535
from hathor.nanocontracts.nc_exec_logs import NCLogStorage
3636

3737
logger = get_logger()
@@ -46,7 +46,7 @@ def __init__(
4646
self,
4747
settings: 'HathorSettings',
4848
context: 'ConsensusAlgorithmContext',
49-
block_executor: 'NCBlockExecutor',
49+
block_executor: 'NCConsensusBlockExecutor',
5050
feature_service: 'FeatureService',
5151
) -> None:
5252
self._settings = settings
@@ -601,7 +601,7 @@ class BlockConsensusAlgorithmFactory:
601601
def __init__(
602602
self,
603603
settings: 'HathorSettings',
604-
block_executor: 'NCBlockExecutor',
604+
block_executor: 'NCConsensusBlockExecutor',
605605
feature_service: 'FeatureService',
606606
) -> None:
607607
self.settings = settings

hathor/consensus/consensus.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from hathor.execution_manager import non_critical_code
2727
from hathor.feature_activation.feature import Feature
2828
from hathor.nanocontracts.exception import NCInvalidSignature
29-
from hathor.nanocontracts.execution import NCBlockExecutor
29+
from hathor.nanocontracts.execution import NCBlockExecutor, NCConsensusBlockExecutor
3030
from hathor.profiler import get_cpu_profiler
3131
from hathor.pubsub import HathorEvents
3232
from hathor.transaction import BaseTransaction, Block, Transaction
@@ -100,18 +100,25 @@ def __init__(
100100
self.nc_storage_factory = nc_storage_factory
101101
self.soft_voided_tx_ids = frozenset(soft_voided_tx_ids)
102102

103-
# Create NCBlockExecutor with all NC-related dependencies
103+
# Create NCBlockExecutor (pure) for execution
104104
self._block_executor = NCBlockExecutor(
105105
settings=settings,
106106
runner_factory=runner_factory,
107107
nc_storage_factory=nc_storage_factory,
108-
nc_log_storage=nc_log_storage,
109108
nc_calls_sorter=nc_calls_sorter,
109+
)
110+
111+
# Create NCConsensusBlockExecutor (with side effects) for consensus
112+
self._consensus_block_executor = NCConsensusBlockExecutor(
113+
settings=settings,
114+
block_executor=self._block_executor,
115+
nc_storage_factory=nc_storage_factory,
116+
nc_log_storage=nc_log_storage,
110117
nc_exec_fail_trace=nc_exec_fail_trace,
111118
)
112119

113120
self.block_algorithm_factory = BlockConsensusAlgorithmFactory(
114-
settings, self._block_executor, feature_service,
121+
settings, self._consensus_block_executor, feature_service,
115122
)
116123
self.transaction_algorithm_factory = TransactionConsensusAlgorithmFactory()
117124
self.nc_calls_sorter = nc_calls_sorter

hathor/nanocontracts/execution/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
"""Nano contract block execution module."""
1616

1717
from hathor.nanocontracts.execution.block_executor import NCBlockExecutor
18+
from hathor.nanocontracts.execution.consensus_block_executor import NCConsensusBlockExecutor
1819

1920
__all__ = [
2021
'NCBlockExecutor',
22+
'NCConsensusBlockExecutor',
2123
]

0 commit comments

Comments
 (0)