Skip to content

Commit

Permalink
feat(p2p): remove sync-v1 code and disable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jansegre committed Jan 17, 2025
1 parent 508030c commit 85784bd
Show file tree
Hide file tree
Showing 112 changed files with 221 additions and 3,775 deletions.
28 changes: 2 additions & 26 deletions hathor/builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,14 @@ def add_factories(
cls,
settings: HathorSettingsType,
p2p_manager: ConnectionsManager,
sync_v1_support: 'SyncSupportLevel',
sync_v2_support: 'SyncSupportLevel',
vertex_parser: VertexParser,
vertex_handler: VertexHandler,
) -> None:
"""Adds the sync factory to the manager according to the support level."""
from hathor.p2p.sync_v1.factory import SyncV11Factory
from hathor.p2p.sync_v2.factory import SyncV2Factory
from hathor.p2p.sync_version import SyncVersion

# sync-v1 support:
if sync_v1_support > cls.UNAVAILABLE:
p2p_manager.add_sync_factory(SyncVersion.V1_1, SyncV11Factory(p2p_manager, vertex_parser=vertex_parser))
if sync_v1_support is cls.ENABLED:
p2p_manager.enable_sync_version(SyncVersion.V1_1)
# sync-v2 support:
if sync_v2_support > cls.UNAVAILABLE:
sync_v2_factory = SyncV2Factory(
Expand Down Expand Up @@ -185,8 +178,7 @@ def __init__(self) -> None:
self._enable_tokens_index: bool = False
self._enable_utxo_index: bool = False

self._sync_v1_support: SyncSupportLevel = SyncSupportLevel.UNAVAILABLE
self._sync_v2_support: SyncSupportLevel = SyncSupportLevel.UNAVAILABLE
self._sync_v2_support: SyncSupportLevel = SyncSupportLevel.ENABLED

self._enable_stratum_server: Optional[bool] = None

Expand All @@ -209,7 +201,7 @@ def build(self) -> BuildArtifacts:
if self.artifacts is not None:
raise ValueError('cannot call build twice')

if SyncSupportLevel.ENABLED not in {self._sync_v1_support, self._sync_v2_support}:
if SyncSupportLevel.ENABLED not in {self._sync_v2_support}:
raise TypeError('you must enable at least one sync version')

settings = self._get_or_create_settings()
Expand Down Expand Up @@ -435,7 +427,6 @@ def _get_or_create_p2p_manager(self) -> ConnectionsManager:
SyncSupportLevel.add_factories(
self._get_or_create_settings(),
self._p2p_manager,
self._sync_v1_support,
self._sync_v2_support,
self._get_or_create_vertex_parser(),
self._get_or_create_vertex_handler(),
Expand Down Expand Up @@ -772,26 +763,11 @@ def set_pubsub(self, pubsub: PubSubManager) -> 'Builder':
self._pubsub = pubsub
return self

def set_sync_v1_support(self, support_level: SyncSupportLevel) -> 'Builder':
self.check_if_can_modify()
self._sync_v1_support = support_level
return self

def set_sync_v2_support(self, support_level: SyncSupportLevel) -> 'Builder':
self.check_if_can_modify()
self._sync_v2_support = support_level
return self

def enable_sync_v1(self) -> 'Builder':
self.check_if_can_modify()
self._sync_v1_support = SyncSupportLevel.ENABLED
return self

def disable_sync_v1(self) -> 'Builder':
self.check_if_can_modify()
self._sync_v1_support = SyncSupportLevel.DISABLED
return self

def enable_sync_v2(self) -> 'Builder':
self.check_if_can_modify()
self._sync_v2_support = SyncSupportLevel.ENABLED
Expand Down
45 changes: 6 additions & 39 deletions hathor/builder/cli_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,46 +198,20 @@ def create_manager(self, reactor: Reactor) -> HathorManager:

hostname = self.get_hostname()

sync_choice: SyncChoice
if self._args.sync_bridge:
self.log.warn('--sync-bridge is deprecated and will be removed')
sync_choice = SyncChoice.BRIDGE_DEFAULT
raise BuilderError('--sync-bridge was removed')
elif self._args.sync_v1_only:
self.log.warn('--sync-v1-only is deprecated and will be removed')
sync_choice = SyncChoice.V1_DEFAULT
raise BuilderError('--sync-v1-only was removed')
elif self._args.sync_v2_only:
self.log.warn('--sync-v2-only is the default, this parameter has no effect')
sync_choice = SyncChoice.V2_DEFAULT
elif self._args.x_remove_sync_v1:
sync_choice = SyncChoice.V2_ONLY
self.log.warn('--x-remove-sync-v1 is deprecated and has no effect')
elif self._args.x_sync_bridge:
self.log.warn('--x-sync-bridge is deprecated and will be removed')
sync_choice = SyncChoice.BRIDGE_DEFAULT
raise BuilderError('--x-sync-bridge was removed')
elif self._args.x_sync_v1_only:
self.log.warn('--x-sync-v1-only is deprecated and will be removed')
sync_choice = SyncChoice.V1_DEFAULT
raise BuilderError('--x-sync-v1-only was removed')
elif self._args.x_sync_v2_only:
self.log.warn('--x-sync-v2-only is deprecated and will be removed')
sync_choice = SyncChoice.V2_DEFAULT
else:
# XXX: this is the default behavior when no parameter is given
sync_choice = SyncChoice.V2_DEFAULT

sync_v1_support: SyncSupportLevel
sync_v2_support: SyncSupportLevel
match sync_choice:
case SyncChoice.V1_DEFAULT:
sync_v1_support = SyncSupportLevel.ENABLED
sync_v2_support = SyncSupportLevel.DISABLED
case SyncChoice.V2_DEFAULT:
sync_v1_support = SyncSupportLevel.DISABLED
sync_v2_support = SyncSupportLevel.ENABLED
case SyncChoice.BRIDGE_DEFAULT:
sync_v1_support = SyncSupportLevel.ENABLED
sync_v2_support = SyncSupportLevel.ENABLED
case SyncChoice.V2_ONLY:
sync_v1_support = SyncSupportLevel.UNAVAILABLE
sync_v2_support = SyncSupportLevel.ENABLED

pubsub = PubSubManager(reactor)

Expand Down Expand Up @@ -345,14 +319,7 @@ def create_manager(self, reactor: Reactor) -> HathorManager:
log_vertex_bytes=self._args.log_vertex_bytes,
)

SyncSupportLevel.add_factories(
settings,
p2p_manager,
sync_v1_support,
sync_v2_support,
vertex_parser,
vertex_handler,
)
SyncSupportLevel.add_factories(settings, p2p_manager, SyncSupportLevel.ENABLED, vertex_parser, vertex_handler)

from hathor.consensus.poa import PoaBlockProducer, PoaSignerFile
poa_block_producer: PoaBlockProducer | None = None
Expand Down
15 changes: 7 additions & 8 deletions hathor/cli/run_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,13 @@ def create_parser(cls) -> ArgumentParser:
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')
sync_args = parser.add_mutually_exclusive_group()
sync_args.add_argument('--sync-bridge', action='store_true', help=SUPPRESS) # moved to --x-sync-bridge
sync_args.add_argument('--sync-v1-only', action='store_true', help=SUPPRESS) # moved to --x-sync-v1-only
sync_args.add_argument('--sync-v2-only', action='store_true', help=SUPPRESS) # already default
sync_args.add_argument('--x-remove-sync-v1', action='store_true', help='Make sync-v1 unavailable, thus '
'impossible to be enabled in runtime.')
sync_args.add_argument('--x-sync-v1-only', action='store_true', help='Disable support for running sync-v2.')
sync_args.add_argument('--x-sync-v2-only', action='store_true', help=SUPPRESS) # old argument
sync_args.add_argument('--x-sync-bridge', action='store_true', help='Enable running both sync protocols.')
sync_args.add_argument('--sync-bridge', action='store_true', help=SUPPRESS) # deprecated
sync_args.add_argument('--sync-v1-only', action='store_true', help=SUPPRESS) # deprecated
sync_args.add_argument('--sync-v2-only', action='store_true', help=SUPPRESS) # deprecated
sync_args.add_argument('--x-remove-sync-v1', action='store_true', help=SUPPRESS) # deprecated
sync_args.add_argument('--x-sync-v1-only', action='store_true', help=SUPPRESS) # deprecated
sync_args.add_argument('--x-sync-v2-only', action='store_true', help=SUPPRESS) # deprecated
sync_args.add_argument('--x-sync-bridge', action='store_true', help=SUPPRESS) # deprecated
parser.add_argument('--x-localhost-only', action='store_true', help='Only connect to peers on localhost')
parser.add_argument('--x-rocksdb-indexes', action='store_true', help=SUPPRESS)
parser.add_argument('--x-enable-event-queue', action='store_true',
Expand Down
5 changes: 0 additions & 5 deletions hathor/cli/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,6 @@ def setup_logging(
'level': 'INFO' if logging_options.debug else 'WARN',
'propagate': False,
},
'hathor.p2p.sync_v1': {
'handlers': handlers,
'level': 'DEBUG' if debug_sync else 'INFO',
'propagate': False,
},
'hathor.p2p.sync_v2': {
'handlers': handlers,
'level': 'DEBUG' if debug_sync else 'INFO',
Expand Down
Empty file removed hathor/p2p/sync_v1/__init__.py
Empty file.
Loading

0 comments on commit 85784bd

Please sign in to comment.