diff --git a/hathor/builder/builder.py b/hathor/builder/builder.py index 911569488..7794979fa 100644 --- a/hathor/builder/builder.py +++ b/hathor/builder/builder.py @@ -140,8 +140,7 @@ def __init__(self) -> None: self._enable_tokens_index: bool = False self._enable_utxo_index: bool = False - self._enable_sync_v1: bool = False - self._enable_sync_v1_1: bool = True + self._enable_sync_v1: bool = True self._enable_sync_v2: bool = False self._enable_stratum_server: Optional[bool] = None @@ -350,7 +349,6 @@ def _get_p2p_manager(self) -> ConnectionsManager: whitelist_only=False, rng=self._rng, enable_sync_v1=self._enable_sync_v1, - enable_sync_v1_1=self._enable_sync_v1_1, enable_sync_v2=self._enable_sync_v2, ) return p2p_manager @@ -637,11 +635,6 @@ def set_enable_sync_v1(self, enable_sync_v1: bool) -> 'Builder': self._enable_sync_v1 = enable_sync_v1 return self - def set_enable_sync_v1_1(self, enable_sync_v1_1: bool) -> 'Builder': - self.check_if_can_modify() - self._enable_sync_v1_1 = enable_sync_v1_1 - return self - def set_enable_sync_v2(self, enable_sync_v2: bool) -> 'Builder': self.check_if_can_modify() self._enable_sync_v2 = enable_sync_v2 @@ -657,16 +650,6 @@ def disable_sync_v1(self) -> 'Builder': self._enable_sync_v1 = False return self - def enable_sync_v1_1(self) -> 'Builder': - self.check_if_can_modify() - self._enable_sync_v1_1 = True - return self - - def disable_sync_v1_1(self) -> 'Builder': - self.check_if_can_modify() - self._enable_sync_v1_1 = False - return self - def enable_sync_v2(self) -> 'Builder': self.check_if_can_modify() self._enable_sync_v2 = True diff --git a/hathor/builder/cli_builder.py b/hathor/builder/cli_builder.py index 18abf1856..11a36ddda 100644 --- a/hathor/builder/cli_builder.py +++ b/hathor/builder/cli_builder.py @@ -152,8 +152,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager: hostname = self.get_hostname() network = settings.NETWORK_NAME - enable_sync_v1 = self._args.x_enable_legacy_sync_v1_0 - enable_sync_v1_1 = not self._args.x_sync_v2_only + 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 pubsub = PubSubManager(reactor) @@ -235,7 +234,6 @@ def create_manager(self, reactor: Reactor) -> HathorManager: whitelist_only=False, rng=Random(), enable_sync_v1=enable_sync_v1, - enable_sync_v1_1=enable_sync_v1_1, enable_sync_v2=enable_sync_v2, ) diff --git a/hathor/cli/run_node.py b/hathor/cli/run_node.py index d2d75058c..40d1004ca 100644 --- a/hathor/cli/run_node.py +++ b/hathor/cli/run_node.py @@ -102,8 +102,6 @@ def create_parser(cls) -> ArgumentParser: parser.add_argument('--sentry-dsn', help='Sentry DSN') parser.add_argument('--enable-debug-api', action='store_true', help='Enable _debug/* endpoints') parser.add_argument('--enable-crash-api', action='store_true', help='Enable _crash/* endpoints') - parser.add_argument('--x-enable-legacy-sync-v1_0', action='store_true', help='Enable sync-v1.0, will not ' - 'disable sync-v1.1') v2args = parser.add_mutually_exclusive_group() v2args.add_argument('--x-sync-bridge', action='store_true', help='Enable support for running both sync protocols. DO NOT ENABLE, IT WILL BREAK.') diff --git a/hathor/cli/run_node_args.py b/hathor/cli/run_node_args.py index eb9ddcd0c..bde32a6e8 100644 --- a/hathor/cli/run_node_args.py +++ b/hathor/cli/run_node_args.py @@ -63,7 +63,6 @@ class RunNodeArgs(BaseModel, extra=Extra.allow): sentry_dsn: Optional[str] enable_debug_api: bool enable_crash_api: bool - x_enable_legacy_sync_v1_0: bool x_sync_bridge: bool x_sync_v2_only: bool x_localhost_only: bool diff --git a/hathor/p2p/manager.py b/hathor/p2p/manager.py index 187efcb2b..24dc4a01f 100644 --- a/hathor/p2p/manager.py +++ b/hathor/p2p/manager.py @@ -98,13 +98,11 @@ def __init__(self, rng: Random, whitelist_only: bool, enable_sync_v1: bool, - enable_sync_v2: bool, - enable_sync_v1_1: bool) -> None: - from hathor.p2p.sync_v1.factory_v1_0 import SyncV10Factory - from hathor.p2p.sync_v1.factory_v1_1 import SyncV11Factory + enable_sync_v2: bool) -> None: + from hathor.p2p.sync_v1.factory import SyncV11Factory from hathor.p2p.sync_v2.factory import SyncV2Factory - if not (enable_sync_v1 or enable_sync_v1_1 or enable_sync_v2): + if not (enable_sync_v1 or enable_sync_v2): raise TypeError(f'{type(self).__name__}() at least one sync version is required') self.log = logger.new() @@ -187,7 +185,6 @@ def __init__(self, self.whitelist_only = whitelist_only self.enable_sync_v1 = enable_sync_v1 - self.enable_sync_v1_1 = enable_sync_v1_1 self.enable_sync_v2 = enable_sync_v2 # Timestamp when the last discovery ran @@ -196,8 +193,6 @@ def __init__(self, # sync-manager factories self._sync_factories = {} if enable_sync_v1: - self._sync_factories[SyncVersion.V1] = SyncV10Factory(self) - if enable_sync_v1_1: self._sync_factories[SyncVersion.V1_1] = SyncV11Factory(self) if enable_sync_v2: self._sync_factories[SyncVersion.V2] = SyncV2Factory(self) @@ -289,9 +284,10 @@ def get_sync_versions(self) -> set[SyncVersion]: if self.manager.has_sync_version_capability(): return set(self._sync_factories.keys()) else: - assert SyncVersion.V1 in self._sync_factories, 'sync-versions capability disabled, but sync-v1 not enabled' + assert SyncVersion.V1_1 in self._sync_factories, \ + 'sync-versions capability disabled, but sync-v1 not enabled' # XXX: this is to make it easy to simulate old behavior if we disable the sync-version capability - return {SyncVersion.V1} + return {SyncVersion.V1_1} def get_sync_factory(self, sync_version: SyncVersion) -> SyncAgentFactory: """Get the sync factory for a given version, support MUST be checked beforehand or it will raise an assert.""" diff --git a/hathor/p2p/states/hello.py b/hathor/p2p/states/hello.py index d731e2bfa..d6cc80fca 100644 --- a/hathor/p2p/states/hello.py +++ b/hathor/p2p/states/hello.py @@ -181,4 +181,4 @@ def _parse_sync_versions(hello_data: dict[str, Any]) -> set[SyncVersion]: return set(SyncVersion(x) for x in recognized_values) else: # XXX: implied value when sync-version capability isn't present - return {SyncVersion.V1} + return {SyncVersion.V1_1} diff --git a/hathor/p2p/sync_v1/factory_v1_1.py b/hathor/p2p/sync_v1/factory.py similarity index 100% rename from hathor/p2p/sync_v1/factory_v1_1.py rename to hathor/p2p/sync_v1/factory.py diff --git a/hathor/p2p/sync_v1/factory_v1_0.py b/hathor/p2p/sync_v1/factory_v1_0.py deleted file mode 100644 index acd430474..000000000 --- a/hathor/p2p/sync_v1/factory_v1_0.py +++ /dev/null @@ -1,40 +0,0 @@ -# Copyright 2021 Hathor Labs -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -from typing import TYPE_CHECKING, Optional - -from hathor.p2p.manager import ConnectionsManager -from hathor.p2p.sync_agent import SyncAgent -from hathor.p2p.sync_factory import SyncAgentFactory -from hathor.p2p.sync_v1.agent import NodeSyncTimestamp -from hathor.p2p.sync_v1.downloader import Downloader -from hathor.util import Reactor - -if TYPE_CHECKING: - from hathor.p2p.protocol import HathorProtocol - - -class SyncV10Factory(SyncAgentFactory): - def __init__(self, connections: ConnectionsManager): - self.connections = connections - self._downloader: Optional[Downloader] = None - - def get_downloader(self) -> Downloader: - if self._downloader is None: - assert self.connections.manager is not None - self._downloader = Downloader(self.connections.manager) - return self._downloader - - def create_sync_agent(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncAgent: - return NodeSyncTimestamp(protocol, downloader=self.get_downloader(), reactor=reactor) diff --git a/hathor/p2p/sync_version.py b/hathor/p2p/sync_version.py index 8db49918a..2a51293c5 100644 --- a/hathor/p2p/sync_version.py +++ b/hathor/p2p/sync_version.py @@ -22,7 +22,6 @@ class SyncVersion(Enum): # to no match different values and in turn not select a certain protocol, this can be done intentionally, for # example, peers using `v2-fake` (which just uses sync-v1) will not connect to peers using `v2-alpha`, and so # on. - V1 = 'v1' V1_1 = 'v1.1' V2 = 'v2' @@ -37,10 +36,7 @@ def get_priority(self) -> int: # XXX: these values are only used internally and in memory, there is no need to keep them consistency, for # example, if we need more granularity, we can just add a 0 to all values and use the values in between, # although this shouldn't really be necessary - if self is SyncVersion.V1: - # low priority - return 10 - elif self is SyncVersion.V1_1: + if self is SyncVersion.V1_1: return 11 elif self is SyncVersion.V2: return 20 @@ -48,7 +44,7 @@ def get_priority(self) -> int: raise ValueError('value is either invalid for this enum or not implemented') def is_v1(self) -> bool: - """Return True for V1 and V1_1.""" + """Return True for V1_1.""" return self.get_priority() < 20 # XXX: total_ordering decorator will implement the other methods: __le__, __gt__, and __ge__ diff --git a/tests/others/test_cli_builder.py b/tests/others/test_cli_builder.py index c2705b032..1c9c05be9 100644 --- a/tests/others/test_cli_builder.py +++ b/tests/others/test_cli_builder.py @@ -57,7 +57,6 @@ def test_all_default(self): self.assertIsInstance(manager.tx_storage.indexes, RocksDBIndexesManager) self.assertIsNone(manager.wallet) self.assertEqual('unittests', manager.network) - self.assertNotIn(SyncVersion.V1, manager.connections._sync_factories) self.assertIn(SyncVersion.V1_1, manager.connections._sync_factories) self.assertNotIn(SyncVersion.V2, manager.connections._sync_factories) self.assertFalse(self.resources_builder._built_prometheus) @@ -102,22 +101,14 @@ def test_memory_storage(self): def test_memory_storage_with_rocksdb_indexes(self): self._build_with_error(['--memory-storage', '--x-rocksdb-indexes'], 'RocksDB indexes require RocksDB data') - def test_sync_v1_0_legacy(self): - manager = self._build(['--memory-storage', '--x-enable-legacy-sync-v1_0']) - self.assertIn(SyncVersion.V1, manager.connections._sync_factories) - self.assertIn(SyncVersion.V1_1, manager.connections._sync_factories) - self.assertNotIn(SyncVersion.V2, manager.connections._sync_factories) - def test_sync_bridge(self): manager = self._build(['--memory-storage', '--x-sync-bridge']) - self.assertNotIn(SyncVersion.V1, manager.connections._sync_factories) self.assertIn(SyncVersion.V1_1, manager.connections._sync_factories) self.assertIn(SyncVersion.V2, manager.connections._sync_factories) def test_sync_v2_only(self): manager = self._build(['--memory-storage', '--x-sync-v2-only']) self.assertNotIn(SyncVersion.V1_1, manager.connections._sync_factories) - self.assertNotIn(SyncVersion.V1, manager.connections._sync_factories) self.assertIn(SyncVersion.V2, manager.connections._sync_factories) def test_keypair_wallet(self): diff --git a/tests/others/test_init_manager.py b/tests/others/test_init_manager.py index 51d7e5b93..8ca7228a2 100644 --- a/tests/others/test_init_manager.py +++ b/tests/others/test_init_manager.py @@ -50,7 +50,6 @@ def test_invalid_arguments(self): builder = TestBuilder() builder.set_tx_storage(self.tx_storage) builder.disable_sync_v1() - builder.disable_sync_v1_1() builder.disable_sync_v2() builder.build() diff --git a/tests/unittest.py b/tests/unittest.py index 5b3b3cb7f..ab64814bb 100644 --- a/tests/unittest.py +++ b/tests/unittest.py @@ -228,11 +228,9 @@ def create_peer(self, network, peer_id=None, wallet=None, tx_storage=None, unloc builder.force_memory_index() if enable_sync_v1 is True: - # Enable Sync v1.1 (instead of v1.0) - builder.enable_sync_v1_1() + builder.enable_sync_v1() elif enable_sync_v1 is False: - # Disable Sync v1.1 (instead of v1.0) - builder.disable_sync_v1_1() + builder.disable_sync_v1() if enable_sync_v2 is True: builder.enable_sync_v2() @@ -255,10 +253,8 @@ def create_peer(self, network, peer_id=None, wallet=None, tx_storage=None, unloc else: assert SyncVersion.V2 not in manager.connections._sync_factories if enable_sync_v1: - assert SyncVersion.V1 not in manager.connections._sync_factories assert SyncVersion.V1_1 in manager.connections._sync_factories else: - assert SyncVersion.V1 not in manager.connections._sync_factories assert SyncVersion.V1_1 not in manager.connections._sync_factories return manager