17
17
import os
18
18
import platform
19
19
import sys
20
+ from enum import Enum , auto
20
21
from typing import Any , Optional
21
22
22
23
from structlog import get_logger
45
46
logger = get_logger ()
46
47
47
48
49
+ class SyncChoice (Enum ):
50
+ V1_ONLY = auto ()
51
+ V2_ONLY = auto ()
52
+ BRIDGE = auto ()
53
+
54
+
48
55
class CliBuilder :
49
56
"""CliBuilder builds the core objects from args.
50
57
@@ -61,7 +68,7 @@ def check_or_raise(self, condition: bool, message: str) -> None:
61
68
62
69
def create_manager (self , reactor : Reactor ) -> HathorManager :
63
70
import hathor
64
- from hathor .conf .get_settings import get_settings , get_settings_source
71
+ from hathor .conf .get_settings import get_global_settings , get_settings_source
65
72
from hathor .daa import TestMode
66
73
from hathor .event .storage import EventMemoryStorage , EventRocksDBStorage , EventStorage
67
74
from hathor .event .websocket .factory import EventWebsocketFactory
@@ -79,7 +86,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
79
86
)
80
87
from hathor .util import get_environment_info
81
88
82
- settings = get_settings ()
89
+ settings = get_global_settings ()
83
90
84
91
# only used for logging its location
85
92
settings_source = get_settings_source ()
@@ -103,6 +110,12 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
103
110
reactor_type = type (reactor ).__name__ ,
104
111
)
105
112
113
+ # XXX Remove this protection after Nano Contracts are launched.
114
+ if settings .NETWORK_NAME not in {'nano-testnet-alpha' , 'unittests' }:
115
+ # Add protection to prevent enabling Nano Contracts due to misconfigurations.
116
+ self .check_or_raise (not settings .ENABLE_NANO_CONTRACTS ,
117
+ 'configuration error: NanoContracts can only be enabled on localnets for now' )
118
+
106
119
tx_storage : TransactionStorage
107
120
event_storage : EventStorage
108
121
indexes : IndexesManager
@@ -158,8 +171,36 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
158
171
159
172
hostname = self .get_hostname ()
160
173
network = settings .NETWORK_NAME
161
- enable_sync_v1 = not self ._args .x_sync_v2_only
162
- enable_sync_v2 = self ._args .x_sync_v2_only or self ._args .x_sync_bridge
174
+
175
+ sync_choice : SyncChoice
176
+ if self ._args .sync_bridge :
177
+ self .log .warn ('--sync-bridge is the default, this parameter has no effect' )
178
+ sync_choice = SyncChoice .BRIDGE
179
+ elif self ._args .sync_v1_only :
180
+ sync_choice = SyncChoice .V1_ONLY
181
+ elif self ._args .sync_v2_only :
182
+ sync_choice = SyncChoice .V2_ONLY
183
+ elif self ._args .x_sync_bridge :
184
+ self .log .warn ('--x-sync-bridge is deprecated and will be removed, use --sync-bridge instead' )
185
+ sync_choice = SyncChoice .BRIDGE
186
+ elif self ._args .x_sync_v2_only :
187
+ self .log .warn ('--x-sync-v2-only is deprecated and will be removed, use --sync-v2-only instead' )
188
+ sync_choice = SyncChoice .V2_ONLY
189
+ else :
190
+ sync_choice = SyncChoice .BRIDGE
191
+
192
+ enable_sync_v1 : bool
193
+ enable_sync_v2 : bool
194
+ match sync_choice :
195
+ case SyncChoice .V1_ONLY :
196
+ enable_sync_v1 = True
197
+ enable_sync_v2 = False
198
+ case SyncChoice .V2_ONLY :
199
+ enable_sync_v1 = False
200
+ enable_sync_v2 = True
201
+ case SyncChoice .BRIDGE :
202
+ enable_sync_v1 = True
203
+ enable_sync_v2 = True
163
204
164
205
pubsub = PubSubManager (reactor )
165
206
@@ -270,6 +311,11 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
270
311
cpu_mining_service = cpu_mining_service
271
312
)
272
313
314
+ if self ._args .x_ipython_kernel :
315
+ self .check_or_raise (self ._args .x_asyncio_reactor ,
316
+ '--x-ipython-kernel must be used with --x-asyncio-reactor' )
317
+ self ._start_ipykernel ()
318
+
273
319
p2p_manager .set_manager (self .manager )
274
320
275
321
if self ._args .stratum :
@@ -376,3 +422,14 @@ def create_wallet(self) -> BaseWallet:
376
422
return wallet
377
423
else :
378
424
raise BuilderError ('Invalid type of wallet' )
425
+
426
+ def _start_ipykernel (self ) -> None :
427
+ # breakpoints are not expected to be used with the embeded ipykernel, to prevent this warning from being
428
+ # unnecessarily annoying, PYDEVD_DISABLE_FILE_VALIDATION should be set to 1 before debugpy is imported, or in
429
+ # practice, before importing hathor.ipykernel, if for any reason support for breakpoints is needed, the flag
430
+ # -Xfrozen_modules=off has to be passed to the python interpreter
431
+ # see:
432
+ # https://github.com/microsoft/debugpy/blob/main/src/debugpy/_vendored/pydevd/pydevd_file_utils.py#L587-L592
433
+ os .environ ['PYDEVD_DISABLE_FILE_VALIDATION' ] = '1'
434
+ from hathor .ipykernel import embed_kernel
435
+ embed_kernel (self .manager , runtime_dir = self ._args .data , extra_ns = dict (run_node = self ))
0 commit comments