Skip to content

Commit

Permalink
Merge pull request #961 from HathorNetwork/release-candidate
Browse files Browse the repository at this point in the history
Release v0.59.0
  • Loading branch information
jansegre authored Mar 1, 2024
2 parents 0d94549 + f46f0be commit eb8f521
Show file tree
Hide file tree
Showing 163 changed files with 3,209 additions and 1,629 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ jobs:
matrix:
python-impl:
- python
- pypy
python-version:
- '3.10'
- '3.11'
exclude:
# XXX: pypy-3.11 does exist yet
- '3.12'
include:
- python-impl: pypy
python-version: '3.11'
python-version: '3.10'
steps:
- name: Checkout
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
import os
import json
full_matrix = {
'python': ['3.10', '3.11'],
'python': ['3.10', '3.11', '3.12'],
# available OS's: https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idruns-on
'os': ['ubuntu-22.04', 'macos-12', 'windows-2022'],
'include': [
Expand All @@ -33,7 +33,7 @@ jobs:
}
# this is the fastest one:
reduced_matrix = {
'python': ['3.11'],
'python': ['3.12'],
'os': ['ubuntu-22.04'],
}
github_repository = os.environ['GITHUB_REPOSITORY']
Expand Down
4 changes: 2 additions & 2 deletions hathor/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from structlog import get_logger

from hathor.checkpoint import Checkpoint
from hathor.conf.get_settings import get_settings
from hathor.conf.get_settings import get_global_settings
from hathor.conf.settings import HathorSettings as HathorSettingsType
from hathor.consensus import ConsensusAlgorithm
from hathor.daa import DifficultyAdjustmentAlgorithm
Expand Down Expand Up @@ -285,7 +285,7 @@ def set_peer_id(self, peer_id: PeerId) -> 'Builder':
def _get_or_create_settings(self) -> HathorSettingsType:
"""Return the HathorSettings instance set on this builder, or a new one if not set."""
if self._settings is None:
self._settings = get_settings()
self._settings = get_global_settings()
return self._settings

def _get_reactor(self) -> Reactor:
Expand Down
65 changes: 61 additions & 4 deletions hathor/builder/cli_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import os
import platform
import sys
from enum import Enum, auto
from typing import Any, Optional

from structlog import get_logger
Expand Down Expand Up @@ -45,6 +46,12 @@
logger = get_logger()


class SyncChoice(Enum):
V1_ONLY = auto()
V2_ONLY = auto()
BRIDGE = auto()


class CliBuilder:
"""CliBuilder builds the core objects from args.
Expand All @@ -61,7 +68,7 @@ def check_or_raise(self, condition: bool, message: str) -> None:

def create_manager(self, reactor: Reactor) -> HathorManager:
import hathor
from hathor.conf.get_settings import get_settings, get_settings_source
from hathor.conf.get_settings import get_global_settings, get_settings_source
from hathor.daa import TestMode
from hathor.event.storage import EventMemoryStorage, EventRocksDBStorage, EventStorage
from hathor.event.websocket.factory import EventWebsocketFactory
Expand All @@ -79,7 +86,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
)
from hathor.util import get_environment_info

settings = get_settings()
settings = get_global_settings()

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

# XXX Remove this protection after Nano Contracts are launched.
if settings.NETWORK_NAME not in {'nano-testnet-alpha', 'unittests'}:
# Add protection to prevent enabling Nano Contracts due to misconfigurations.
self.check_or_raise(not settings.ENABLE_NANO_CONTRACTS,
'configuration error: NanoContracts can only be enabled on localnets for now')

tx_storage: TransactionStorage
event_storage: EventStorage
indexes: IndexesManager
Expand Down Expand Up @@ -158,8 +171,36 @@ def create_manager(self, reactor: Reactor) -> HathorManager:

hostname = self.get_hostname()
network = settings.NETWORK_NAME
enable_sync_v1 = not self._args.x_sync_v2_only
enable_sync_v2 = self._args.x_sync_v2_only or self._args.x_sync_bridge

sync_choice: SyncChoice
if self._args.sync_bridge:
self.log.warn('--sync-bridge is the default, this parameter has no effect')
sync_choice = SyncChoice.BRIDGE
elif self._args.sync_v1_only:
sync_choice = SyncChoice.V1_ONLY
elif self._args.sync_v2_only:
sync_choice = SyncChoice.V2_ONLY
elif self._args.x_sync_bridge:
self.log.warn('--x-sync-bridge is deprecated and will be removed, use --sync-bridge instead')
sync_choice = SyncChoice.BRIDGE
elif self._args.x_sync_v2_only:
self.log.warn('--x-sync-v2-only is deprecated and will be removed, use --sync-v2-only instead')
sync_choice = SyncChoice.V2_ONLY
else:
sync_choice = SyncChoice.BRIDGE

enable_sync_v1: bool
enable_sync_v2: bool
match sync_choice:
case SyncChoice.V1_ONLY:
enable_sync_v1 = True
enable_sync_v2 = False
case SyncChoice.V2_ONLY:
enable_sync_v1 = False
enable_sync_v2 = True
case SyncChoice.BRIDGE:
enable_sync_v1 = True
enable_sync_v2 = True

pubsub = PubSubManager(reactor)

Expand Down Expand Up @@ -270,6 +311,11 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
cpu_mining_service=cpu_mining_service
)

if self._args.x_ipython_kernel:
self.check_or_raise(self._args.x_asyncio_reactor,
'--x-ipython-kernel must be used with --x-asyncio-reactor')
self._start_ipykernel()

p2p_manager.set_manager(self.manager)

if self._args.stratum:
Expand Down Expand Up @@ -376,3 +422,14 @@ def create_wallet(self) -> BaseWallet:
return wallet
else:
raise BuilderError('Invalid type of wallet')

def _start_ipykernel(self) -> None:
# breakpoints are not expected to be used with the embeded ipykernel, to prevent this warning from being
# unnecessarily annoying, PYDEVD_DISABLE_FILE_VALIDATION should be set to 1 before debugpy is imported, or in
# practice, before importing hathor.ipykernel, if for any reason support for breakpoints is needed, the flag
# -Xfrozen_modules=off has to be passed to the python interpreter
# see:
# https://github.com/microsoft/debugpy/blob/main/src/debugpy/_vendored/pydevd/pydevd_file_utils.py#L587-L592
os.environ['PYDEVD_DISABLE_FILE_VALIDATION'] = '1'
from hathor.ipykernel import embed_kernel
embed_kernel(self.manager, runtime_dir=self._args.data, extra_ns=dict(run_node=self))
4 changes: 2 additions & 2 deletions hathor/builder/resources_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def create_prometheus(self) -> PrometheusMetricsExporter:
return prometheus

def create_resources(self) -> server.Site:
from hathor.conf.get_settings import get_settings
from hathor.conf.get_settings import get_global_settings
from hathor.debug_resources import (
DebugCrashResource,
DebugLogResource,
Expand Down Expand Up @@ -142,7 +142,7 @@ def create_resources(self) -> server.Site:
)
from hathor.websocket import HathorAdminWebsocketFactory, WebsocketStatsResource

settings = get_settings()
settings = get_global_settings()
cpu = get_cpu_profiler()

# TODO get this from a file. How should we do with the factory?
Expand Down
3 changes: 2 additions & 1 deletion hathor/builder/sysctl_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

from hathor.builder import BuildArtifacts
from hathor.sysctl import ConnectionsManagerSysctl, Sysctl, WebsocketManagerSysctl
from hathor.sysctl import ConnectionsManagerSysctl, HathorManagerSysctl, Sysctl, WebsocketManagerSysctl


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

ws_factory = self.artifacts.manager.metrics.websocket_factory
Expand Down
8 changes: 4 additions & 4 deletions hathor/cli/db_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def register_signal_handlers(self) -> None:

@classmethod
def create_parser(cls) -> ArgumentParser:
from hathor.conf.get_settings import get_settings
settings = get_settings()
from hathor.conf.get_settings import get_global_settings
settings = get_global_settings()

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

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

for tx in self._iter_tx:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def __init__(self, simulator: 'Simulator', *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)

def buildProtocol(self, _: IAddress) -> 'EventForwardingWebsocketProtocol':
from hathor.cli.events_simulator.event_forwarding_websocket_protocol import EventForwardingWebsocketProtocol
protocol = EventForwardingWebsocketProtocol(self._simulator)
protocol.factory = self
return protocol
12 changes: 8 additions & 4 deletions hathor/cli/events_simulator/events_simulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@

import os
from argparse import ArgumentParser, Namespace
from typing import TYPE_CHECKING

from autobahn.twisted.resource import WebSocketResource
from structlog import get_logger
from twisted.web.resource import Resource
from twisted.web.server import Site

if TYPE_CHECKING:
from hathor.reactor import ReactorProtocol

DEFAULT_PORT = 8080

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


def execute(args: Namespace) -> None:
def execute(args: Namespace, reactor: 'ReactorProtocol') -> None:
from hathor.conf import UNITTESTS_SETTINGS_FILEPATH
os.environ['HATHOR_CONFIG_YAML'] = UNITTESTS_SETTINGS_FILEPATH
from hathor.cli.events_simulator.event_forwarding_websocket_factory import EventForwardingWebsocketFactory
from hathor.cli.events_simulator.scenario import Scenario
from hathor.reactor import get_global_reactor
from hathor.simulator import Simulator

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

reactor = get_global_reactor()
log = logger.new()
simulator = Simulator(args.seed)
simulator.start()
Expand Down Expand Up @@ -90,6 +92,8 @@ def execute(args: Namespace) -> None:


def main():
from hathor.reactor import initialize_global_reactor
parser = create_parser()
args = parser.parse_args()
execute(args)
reactor = initialize_global_reactor()
execute(args, reactor)
9 changes: 5 additions & 4 deletions hathor/cli/events_simulator/scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ def simulate_single_chain_one_block(simulator: 'Simulator', manager: 'HathorMana


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

settings = get_settings()
settings = get_global_settings()
assert manager.wallet is not None
address = manager.wallet.get_unused_address(mark_as_used=False)

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


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

settings = get_settings()
settings = get_global_settings()
assert manager.wallet is not None
address = manager.wallet.get_unused_address(mark_as_used=False)

Expand Down Expand Up @@ -134,6 +134,7 @@ def simulate_unvoided_transaction(simulator: 'Simulator', manager: 'HathorManage
settings.GENESIS_TX1_HASH,
not_none(tx2.hash),
]
block.update_hash()
assert manager.propagate_tx(block, fails_silently=False)
simulator.run(60)

Expand Down
8 changes: 5 additions & 3 deletions hathor/cli/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,14 @@ def execute(args: Namespace) -> None:
block.nonce, block.weight))

try:
from hathor.conf.get_settings import get_settings
from unittest.mock import Mock

from hathor.conf.get_settings import get_global_settings
from hathor.daa import DifficultyAdjustmentAlgorithm
from hathor.verification.verification_service import VerificationService, VertexVerifiers
settings = get_settings()
settings = get_global_settings()
daa = DifficultyAdjustmentAlgorithm(settings=settings)
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa)
verifiers = VertexVerifiers.create_defaults(settings=settings, daa=daa, feature_service=Mock())
verification_service = VerificationService(verifiers=verifiers)
verification_service.verify_without_storage(block)
except HathorError:
Expand Down
4 changes: 2 additions & 2 deletions hathor/cli/nginx_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ def generate_nginx_config(openapi: dict[str, Any], *, out_file: TextIO, rate_k:
"""
from datetime import datetime

from hathor.conf.get_settings import get_settings
from hathor.conf.get_settings import get_global_settings

settings = get_settings()
settings = get_global_settings()
api_prefix = settings.API_VERSION_PREFIX

locations: dict[str, dict[str, Any]] = {}
Expand Down
2 changes: 1 addition & 1 deletion hathor/cli/openapi_files/openapi_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"info": {
"title": "Hathor API",
"version": "0.58.0"
"version": "0.59.0"
},
"consumes": [
"application/json"
Expand Down
Loading

0 comments on commit eb8f521

Please sign in to comment.