From d2db923cc6ccb2591b50020a321d9cccaf205d19 Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Fri, 3 Oct 2025 17:52:21 +0200 Subject: [PATCH] feat(cli): add hidden CLI option to show nc-exec fail traces --- hathor/builder/cli_builder.py | 1 + hathor/cli/run_node.py | 1 + hathor/cli/run_node_args.py | 1 + hathor/consensus/block_consensus.py | 10 +++++++++- hathor/consensus/consensus.py | 3 ++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/hathor/builder/cli_builder.py b/hathor/builder/cli_builder.py index e89cfc1dcf..b89fd398ef 100644 --- a/hathor/builder/cli_builder.py +++ b/hathor/builder/cli_builder.py @@ -258,6 +258,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager: nc_log_storage=nc_log_storage, nc_calls_sorter=nc_calls_sorter, feature_service=self.feature_service, + nc_exec_fail_trace=self._args.nc_exec_fail_trace, ) if self._args.x_enable_event_queue or self._args.enable_event_queue: diff --git a/hathor/cli/run_node.py b/hathor/cli/run_node.py index 90b4053e65..ff65ffe635 100644 --- a/hathor/cli/run_node.py +++ b/hathor/cli/run_node.py @@ -174,6 +174,7 @@ def create_parser(cls) -> ArgumentParser: possible_nc_exec_logs = [config.value for config in NCLogConfig] parser.add_argument('--nc-exec-logs', default=NCLogConfig.NONE, choices=possible_nc_exec_logs, help=f'Enable saving Nano Contracts execution logs. One of {possible_nc_exec_logs}') + parser.add_argument('--nc-exec-fail-trace', action='store_true', help=SUPPRESS) return parser def prepare(self, *, register_resources: bool = True) -> None: diff --git a/hathor/cli/run_node_args.py b/hathor/cli/run_node_args.py index 08f47aad22..5550367393 100644 --- a/hathor/cli/run_node_args.py +++ b/hathor/cli/run_node_args.py @@ -92,3 +92,4 @@ class RunNodeArgs(BaseModel, extra=Extra.allow): localnet: bool nc_indexes: bool nc_exec_logs: NCLogConfig + nc_exec_fail_trace: bool diff --git a/hathor/consensus/block_consensus.py b/hathor/consensus/block_consensus.py index 7617345228..954ca3b4a4 100644 --- a/hathor/consensus/block_consensus.py +++ b/hathor/consensus/block_consensus.py @@ -55,12 +55,15 @@ def __init__( runner_factory: RunnerFactory, nc_log_storage: NCLogStorage, feature_service: FeatureService, + *, + nc_exec_fail_trace: bool = False, ) -> None: self._settings = settings self.context = context self._runner_factory = runner_factory self._nc_log_storage = nc_log_storage self.feature_service = feature_service + self.nc_exec_fail_trace = nc_exec_fail_trace @classproperty def log(cls) -> Any: @@ -253,6 +256,8 @@ def _nc_execute_calls(self, block: Block, *, is_reorg: bool) -> None: kwargs: dict[str, Any] = {} if tx.name: kwargs['__name'] = tx.name + if self.nc_exec_fail_trace: + kwargs['exc_info'] = True self.log.info( 'nc execution failed', tx=tx.hash.hex(), @@ -869,7 +874,7 @@ def calculate_score(self, block: Block, *, mark_as_best_chain: bool = False) -> class BlockConsensusAlgorithmFactory: - __slots__ = ('settings', 'nc_log_storage', '_runner_factory', 'feature_service') + __slots__ = ('settings', 'nc_log_storage', '_runner_factory', 'feature_service', 'nc_exec_fail_trace') def __init__( self, @@ -877,11 +882,14 @@ def __init__( runner_factory: RunnerFactory, nc_log_storage: NCLogStorage, feature_service: FeatureService, + *, + nc_exec_fail_trace: bool = False, ) -> None: self.settings = settings self._runner_factory = runner_factory self.nc_log_storage = nc_log_storage self.feature_service = feature_service + self.nc_exec_fail_trace = nc_exec_fail_trace def __call__(self, context: 'ConsensusAlgorithmContext') -> BlockConsensusAlgorithm: return BlockConsensusAlgorithm( diff --git a/hathor/consensus/consensus.py b/hathor/consensus/consensus.py index b963287dfd..4e1fc44714 100644 --- a/hathor/consensus/consensus.py +++ b/hathor/consensus/consensus.py @@ -80,6 +80,7 @@ def __init__( nc_calls_sorter: NCSorterCallable, nc_log_storage: NCLogStorage, feature_service: FeatureService, + nc_exec_fail_trace: bool = False, ) -> None: self._settings = settings self.log = logger.new() @@ -87,7 +88,7 @@ def __init__( self.nc_storage_factory = nc_storage_factory self.soft_voided_tx_ids = frozenset(soft_voided_tx_ids) self.block_algorithm_factory = BlockConsensusAlgorithmFactory( - settings, runner_factory, nc_log_storage, feature_service + settings, runner_factory, nc_log_storage, feature_service, nc_exec_fail_trace=nc_exec_fail_trace, ) self.transaction_algorithm_factory = TransactionConsensusAlgorithmFactory() self.nc_calls_sorter = nc_calls_sorter