Skip to content

Commit eb8f521

Browse files
authored
Merge pull request #961 from HathorNetwork/release-candidate
Release v0.59.0
2 parents 0d94549 + f46f0be commit eb8f521

File tree

163 files changed

+3209
-1629
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

163 files changed

+3209
-1629
lines changed

.github/workflows/docker.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ jobs:
2222
matrix:
2323
python-impl:
2424
- python
25-
- pypy
2625
python-version:
2726
- '3.10'
2827
- '3.11'
29-
exclude:
30-
# XXX: pypy-3.11 does exist yet
28+
- '3.12'
29+
include:
3130
- python-impl: pypy
32-
python-version: '3.11'
31+
python-version: '3.10'
3332
steps:
3433
- name: Checkout
3534
uses: actions/checkout@v3

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
import os
2424
import json
2525
full_matrix = {
26-
'python': ['3.10', '3.11'],
26+
'python': ['3.10', '3.11', '3.12'],
2727
# available OS's: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
2828
'os': ['ubuntu-22.04', 'macos-12', 'windows-2022'],
2929
'include': [
@@ -33,7 +33,7 @@ jobs:
3333
}
3434
# this is the fastest one:
3535
reduced_matrix = {
36-
'python': ['3.11'],
36+
'python': ['3.12'],
3737
'os': ['ubuntu-22.04'],
3838
}
3939
github_repository = os.environ['GITHUB_REPOSITORY']

hathor/builder/builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from structlog import get_logger
1919

2020
from hathor.checkpoint import Checkpoint
21-
from hathor.conf.get_settings import get_settings
21+
from hathor.conf.get_settings import get_global_settings
2222
from hathor.conf.settings import HathorSettings as HathorSettingsType
2323
from hathor.consensus import ConsensusAlgorithm
2424
from hathor.daa import DifficultyAdjustmentAlgorithm
@@ -285,7 +285,7 @@ def set_peer_id(self, peer_id: PeerId) -> 'Builder':
285285
def _get_or_create_settings(self) -> HathorSettingsType:
286286
"""Return the HathorSettings instance set on this builder, or a new one if not set."""
287287
if self._settings is None:
288-
self._settings = get_settings()
288+
self._settings = get_global_settings()
289289
return self._settings
290290

291291
def _get_reactor(self) -> Reactor:

hathor/builder/cli_builder.py

+61-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import os
1818
import platform
1919
import sys
20+
from enum import Enum, auto
2021
from typing import Any, Optional
2122

2223
from structlog import get_logger
@@ -45,6 +46,12 @@
4546
logger = get_logger()
4647

4748

49+
class SyncChoice(Enum):
50+
V1_ONLY = auto()
51+
V2_ONLY = auto()
52+
BRIDGE = auto()
53+
54+
4855
class CliBuilder:
4956
"""CliBuilder builds the core objects from args.
5057
@@ -61,7 +68,7 @@ def check_or_raise(self, condition: bool, message: str) -> None:
6168

6269
def create_manager(self, reactor: Reactor) -> HathorManager:
6370
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
6572
from hathor.daa import TestMode
6673
from hathor.event.storage import EventMemoryStorage, EventRocksDBStorage, EventStorage
6774
from hathor.event.websocket.factory import EventWebsocketFactory
@@ -79,7 +86,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
7986
)
8087
from hathor.util import get_environment_info
8188

82-
settings = get_settings()
89+
settings = get_global_settings()
8390

8491
# only used for logging its location
8592
settings_source = get_settings_source()
@@ -103,6 +110,12 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
103110
reactor_type=type(reactor).__name__,
104111
)
105112

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+
106119
tx_storage: TransactionStorage
107120
event_storage: EventStorage
108121
indexes: IndexesManager
@@ -158,8 +171,36 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
158171

159172
hostname = self.get_hostname()
160173
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
163204

164205
pubsub = PubSubManager(reactor)
165206

@@ -270,6 +311,11 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
270311
cpu_mining_service=cpu_mining_service
271312
)
272313

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+
273319
p2p_manager.set_manager(self.manager)
274320

275321
if self._args.stratum:
@@ -376,3 +422,14 @@ def create_wallet(self) -> BaseWallet:
376422
return wallet
377423
else:
378424
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))

hathor/builder/resources_builder.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def create_prometheus(self) -> PrometheusMetricsExporter:
7777
return prometheus
7878

7979
def create_resources(self) -> server.Site:
80-
from hathor.conf.get_settings import get_settings
80+
from hathor.conf.get_settings import get_global_settings
8181
from hathor.debug_resources import (
8282
DebugCrashResource,
8383
DebugLogResource,
@@ -142,7 +142,7 @@ def create_resources(self) -> server.Site:
142142
)
143143
from hathor.websocket import HathorAdminWebsocketFactory, WebsocketStatsResource
144144

145-
settings = get_settings()
145+
settings = get_global_settings()
146146
cpu = get_cpu_profiler()
147147

148148
# TODO get this from a file. How should we do with the factory?

hathor/builder/sysctl_builder.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
from hathor.builder import BuildArtifacts
16-
from hathor.sysctl import ConnectionsManagerSysctl, Sysctl, WebsocketManagerSysctl
16+
from hathor.sysctl import ConnectionsManagerSysctl, HathorManagerSysctl, Sysctl, WebsocketManagerSysctl
1717

1818

1919
class SysctlBuilder:
@@ -25,6 +25,7 @@ def __init__(self, artifacts: BuildArtifacts) -> None:
2525
def build(self) -> Sysctl:
2626
"""Build the sysctl tree."""
2727
root = Sysctl()
28+
root.put_child('core', HathorManagerSysctl(self.artifacts.manager))
2829
root.put_child('p2p', ConnectionsManagerSysctl(self.artifacts.p2p_manager))
2930

3031
ws_factory = self.artifacts.manager.metrics.websocket_factory

hathor/cli/db_export.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def register_signal_handlers(self) -> None:
3434

3535
@classmethod
3636
def create_parser(cls) -> ArgumentParser:
37-
from hathor.conf.get_settings import get_settings
38-
settings = get_settings()
37+
from hathor.conf.get_settings import get_global_settings
38+
settings = get_global_settings()
3939

4040
def max_height(arg: str) -> Optional[int]:
4141
if arg.lower() == 'checkpoint':
@@ -80,8 +80,8 @@ def prepare(self, *, register_resources: bool = True) -> None:
8080
self.skip_voided = self._args.export_skip_voided
8181

8282
def iter_tx(self) -> Iterator['BaseTransaction']:
83-
from hathor.conf.get_settings import get_settings
84-
settings = get_settings()
83+
from hathor.conf.get_settings import get_global_settings
84+
settings = get_global_settings()
8585
soft_voided_ids = set(settings.SOFT_VOIDED_TX_IDS)
8686

8787
for tx in self._iter_tx:

hathor/cli/events_simulator/event_forwarding_websocket_factory.py

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def __init__(self, simulator: 'Simulator', *args: Any, **kwargs: Any) -> None:
2929
super().__init__(*args, **kwargs)
3030

3131
def buildProtocol(self, _: IAddress) -> 'EventForwardingWebsocketProtocol':
32+
from hathor.cli.events_simulator.event_forwarding_websocket_protocol import EventForwardingWebsocketProtocol
3233
protocol = EventForwardingWebsocketProtocol(self._simulator)
3334
protocol.factory = self
3435
return protocol

hathor/cli/events_simulator/events_simulator.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,16 @@
1414

1515
import os
1616
from argparse import ArgumentParser, Namespace
17+
from typing import TYPE_CHECKING
1718

1819
from autobahn.twisted.resource import WebSocketResource
1920
from structlog import get_logger
2021
from twisted.web.resource import Resource
2122
from twisted.web.server import Site
2223

24+
if TYPE_CHECKING:
25+
from hathor.reactor import ReactorProtocol
26+
2327
DEFAULT_PORT = 8080
2428

2529
logger = get_logger()
@@ -39,12 +43,11 @@ def create_parser() -> ArgumentParser:
3943
return parser
4044

4145

42-
def execute(args: Namespace) -> None:
46+
def execute(args: Namespace, reactor: 'ReactorProtocol') -> None:
4347
from hathor.conf import UNITTESTS_SETTINGS_FILEPATH
4448
os.environ['HATHOR_CONFIG_YAML'] = UNITTESTS_SETTINGS_FILEPATH
4549
from hathor.cli.events_simulator.event_forwarding_websocket_factory import EventForwardingWebsocketFactory
4650
from hathor.cli.events_simulator.scenario import Scenario
47-
from hathor.reactor import get_global_reactor
4851
from hathor.simulator import Simulator
4952

5053
try:
@@ -53,7 +56,6 @@ def execute(args: Namespace) -> None:
5356
possible_scenarios = [scenario.name for scenario in Scenario]
5457
raise ValueError(f'Invalid scenario "{args.scenario}". Choose one of {possible_scenarios}') from e
5558

56-
reactor = get_global_reactor()
5759
log = logger.new()
5860
simulator = Simulator(args.seed)
5961
simulator.start()
@@ -90,6 +92,8 @@ def execute(args: Namespace) -> None:
9092

9193

9294
def main():
95+
from hathor.reactor import initialize_global_reactor
9396
parser = create_parser()
9497
args = parser.parse_args()
95-
execute(args)
98+
reactor = initialize_global_reactor()
99+
execute(args, reactor)

hathor/cli/events_simulator/scenario.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ def simulate_single_chain_one_block(simulator: 'Simulator', manager: 'HathorMana
5252

5353

5454
def simulate_single_chain_blocks_and_transactions(simulator: 'Simulator', manager: 'HathorManager') -> None:
55-
from hathor.conf.get_settings import get_settings
55+
from hathor.conf.get_settings import get_global_settings
5656
from hathor.simulator.utils import add_new_blocks, gen_new_tx
5757

58-
settings = get_settings()
58+
settings = get_global_settings()
5959
assert manager.wallet is not None
6060
address = manager.wallet.get_unused_address(mark_as_used=False)
6161

@@ -97,11 +97,11 @@ def simulate_reorg(simulator: 'Simulator', manager: 'HathorManager') -> None:
9797

9898

9999
def simulate_unvoided_transaction(simulator: 'Simulator', manager: 'HathorManager') -> None:
100-
from hathor.conf.get_settings import get_settings
100+
from hathor.conf.get_settings import get_global_settings
101101
from hathor.simulator.utils import add_new_block, add_new_blocks, gen_new_tx
102102
from hathor.util import not_none
103103

104-
settings = get_settings()
104+
settings = get_global_settings()
105105
assert manager.wallet is not None
106106
address = manager.wallet.get_unused_address(mark_as_used=False)
107107

@@ -134,6 +134,7 @@ def simulate_unvoided_transaction(simulator: 'Simulator', manager: 'HathorManage
134134
settings.GENESIS_TX1_HASH,
135135
not_none(tx2.hash),
136136
]
137+
block.update_hash()
137138
assert manager.propagate_tx(block, fails_silently=False)
138139
simulator.run(60)
139140

hathor/cli/mining.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,14 @@ def execute(args: Namespace) -> None:
135135
block.nonce, block.weight))
136136

137137
try:
138-
from hathor.conf.get_settings import get_settings
138+
from unittest.mock import Mock
139+
140+
from hathor.conf.get_settings import get_global_settings
139141
from hathor.daa import DifficultyAdjustmentAlgorithm
140142
from hathor.verification.verification_service import VerificationService, VertexVerifiers
141-
settings = get_settings()
143+
settings = get_global_settings()
142144
daa = DifficultyAdjustmentAlgorithm(settings=settings)
143-
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)
145+
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa, feature_service=Mock())
144146
verification_service = VerificationService(verifiers=verifiers)
145147
verification_service.verify_without_storage(block)
146148
except HathorError:

hathor/cli/nginx_config.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k:
114114
"""
115115
from datetime import datetime
116116

117-
from hathor.conf.get_settings import get_settings
117+
from hathor.conf.get_settings import get_global_settings
118118

119-
settings = get_settings()
119+
settings = get_global_settings()
120120
api_prefix = settings.API_VERSION_PREFIX
121121

122122
locations: dict[str, dict[str, Any]] = {}

hathor/cli/openapi_files/openapi_base.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"info": {
99
"title": "Hathor API",
10-
"version": "0.58.0"
10+
"version": "0.59.0"
1111
},
1212
"consumes": [
1313
"application/json"

0 commit comments

Comments
 (0)