From 1d487760bed08e0f321e89e9685d703e71c3b1c7 Mon Sep 17 00:00:00 2001 From: Jan Segre Date: Wed, 26 Jul 2023 13:03:49 -0300 Subject: [PATCH] refactor(p2p): rename sync *manager* to sync *agent* --- hathor/p2p/manager.py | 6 ++-- hathor/p2p/protocol.py | 6 ++-- hathor/p2p/resources/status.py | 2 +- hathor/p2p/states/ready.py | 20 +++++------ hathor/p2p/{sync_manager.py => sync_agent.py} | 2 +- hathor/p2p/sync_factory.py | 6 ++-- hathor/p2p/sync_v1/agent.py | 4 +-- hathor/p2p/sync_v1/factory_v1_0.py | 8 ++--- hathor/p2p/sync_v1/factory_v1_1.py | 8 ++--- hathor/p2p/sync_v2/factory.py | 8 ++--- hathor/p2p/sync_v2/manager.py | 4 +-- hathor/p2p/sync_v2/mempool.py | 18 +++++----- hathor/simulator/fake_connection.py | 16 ++++----- tests/p2p/test_capabilities.py | 16 ++++----- tests/p2p/test_split_brain.py | 2 +- tests/p2p/test_split_brain2.py | 4 +-- tests/p2p/test_sync.py | 34 +++++++++---------- tests/p2p/test_sync_rate_limiter.py | 8 ++--- tests/p2p/test_sync_v2.py | 6 ++-- 19 files changed, 89 insertions(+), 89 deletions(-) rename hathor/p2p/{sync_manager.py => sync_agent.py} (98%) diff --git a/hathor/p2p/manager.py b/hathor/p2p/manager.py index 067fd4030..007851ff6 100644 --- a/hathor/p2p/manager.py +++ b/hathor/p2p/manager.py @@ -29,7 +29,7 @@ from hathor.p2p.protocol import HathorProtocol from hathor.p2p.rate_limiter import RateLimiter from hathor.p2p.states.ready import ReadyState -from hathor.p2p.sync_factory import SyncManagerFactory +from hathor.p2p.sync_factory import SyncAgentFactory from hathor.p2p.sync_version import SyncVersion from hathor.p2p.utils import description_to_connection_string, parse_whitelist from hathor.pubsub import HathorEvents, PubSubManager @@ -83,7 +83,7 @@ class GlobalRateLimiter: connecting_peers: dict[IStreamClientEndpoint, _ConnectingPeer] handshaking_peers: set[HathorProtocol] whitelist_only: bool - _sync_factories: dict[SyncVersion, SyncManagerFactory] + _sync_factories: dict[SyncVersion, SyncAgentFactory] rate_limiter: RateLimiter @@ -258,7 +258,7 @@ def get_sync_versions(self) -> set[SyncVersion]: # XXX: this is to make it easy to simulate old behavior if we disable the sync-version capability return {SyncVersion.V1} - def get_sync_factory(self, sync_version: SyncVersion) -> SyncManagerFactory: + 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.""" assert sync_version in self._sync_factories, 'get_sync_factory must be called for a supported version' return self._sync_factories[sync_version] diff --git a/hathor/p2p/protocol.py b/hathor/p2p/protocol.py index 651442b50..af7298aa3 100644 --- a/hathor/p2p/protocol.py +++ b/hathor/p2p/protocol.py @@ -363,21 +363,21 @@ def is_sync_enabled(self) -> bool: if not self.is_state(self.PeerState.READY): return False assert isinstance(self.state, ReadyState) - return self.state.sync_manager.is_sync_enabled() + return self.state.sync_agent.is_sync_enabled() def enable_sync(self) -> None: """Enable sync for this connection.""" assert self.is_state(self.PeerState.READY) assert isinstance(self.state, ReadyState) self.log.info('enable sync') - self.state.sync_manager.enable_sync() + self.state.sync_agent.enable_sync() def disable_sync(self) -> None: """Disable sync for this connection.""" assert self.is_state(self.PeerState.READY) assert isinstance(self.state, ReadyState) self.log.info('disable sync') - self.state.sync_manager.disable_sync() + self.state.sync_agent.disable_sync() class HathorLineReceiver(LineReceiver, HathorProtocol): diff --git a/hathor/p2p/resources/status.py b/hathor/p2p/resources/status.py index fdefb58a5..bda60cc1c 100644 --- a/hathor/p2p/resources/status.py +++ b/hathor/p2p/resources/status.py @@ -58,7 +58,7 @@ def render_GET(self, request): for conn in self.manager.connections.iter_ready_connections(): remote = conn.transport.getPeer() status = {} - status[conn.state.sync_manager.name] = conn.state.sync_manager.get_status() + status[conn.state.sync_agent.name] = conn.state.sync_agent.get_status() connected_peers.append({ 'id': conn.peer.id, 'app_version': conn.app_version, diff --git a/hathor/p2p/states/ready.py b/hathor/p2p/states/ready.py index f035cf241..5262f4e7d 100644 --- a/hathor/p2p/states/ready.py +++ b/hathor/p2p/states/ready.py @@ -21,7 +21,7 @@ from hathor.p2p.messages import ProtocolMessages from hathor.p2p.peer_id import PeerId from hathor.p2p.states.base import BaseState -from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_agent import SyncAgent from hathor.transaction import BaseTransaction from hathor.util import json_dumps, json_loads @@ -77,8 +77,8 @@ def __init__(self, protocol: 'HathorProtocol') -> None: self.log.debug(f'loading {sync_version}') sync_factory = connections.get_sync_factory(sync_version) - self.sync_manager: SyncManager = sync_factory.create_sync_manager(self.protocol, reactor=self.reactor) - self.cmd_map.update(self.sync_manager.get_cmd_dict()) + self.sync_agent: SyncAgent = sync_factory.create_sync_agent(self.protocol, reactor=self.reactor) + self.cmd_map.update(self.sync_agent.get_cmd_dict()) def on_enter(self) -> None: if self.protocol.connections: @@ -87,24 +87,24 @@ def on_enter(self) -> None: self.lc_ping.start(1, now=False) self.send_get_peers() - self.sync_manager.start() + self.sync_agent.start() def on_exit(self) -> None: if self.lc_ping.running: self.lc_ping.stop() - if self.sync_manager.is_started(): - self.sync_manager.stop() + if self.sync_agent.is_started(): + self.sync_agent.stop() def prepare_to_disconnect(self) -> None: - if self.sync_manager.is_started(): - self.sync_manager.stop() + if self.sync_agent.is_started(): + self.sync_agent.stop() def send_tx_to_peer(self, tx: BaseTransaction) -> None: - self.sync_manager.send_tx_to_peer_if_possible(tx) + self.sync_agent.send_tx_to_peer_if_possible(tx) def is_synced(self) -> bool: - return self.sync_manager.is_synced() + return self.sync_agent.is_synced() def send_get_peers(self) -> None: """ Send a GET-PEERS command, requesting a list of nodes. diff --git a/hathor/p2p/sync_manager.py b/hathor/p2p/sync_agent.py similarity index 98% rename from hathor/p2p/sync_manager.py rename to hathor/p2p/sync_agent.py index 64db8121c..a700335ed 100644 --- a/hathor/p2p/sync_manager.py +++ b/hathor/p2p/sync_agent.py @@ -19,7 +19,7 @@ from hathor.transaction import BaseTransaction -class SyncManager(ABC): +class SyncAgent(ABC): @abstractmethod def is_started(self) -> bool: """Whether the manager started running""" diff --git a/hathor/p2p/sync_factory.py b/hathor/p2p/sync_factory.py index f171f432b..4f04a734b 100644 --- a/hathor/p2p/sync_factory.py +++ b/hathor/p2p/sync_factory.py @@ -15,14 +15,14 @@ from abc import ABC, abstractmethod from typing import TYPE_CHECKING, Optional -from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_agent import SyncAgent from hathor.util import Reactor if TYPE_CHECKING: from hathor.p2p.protocol import HathorProtocol -class SyncManagerFactory(ABC): +class SyncAgentFactory(ABC): @abstractmethod - def create_sync_manager(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncManager: + def create_sync_agent(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncAgent: pass diff --git a/hathor/p2p/sync_v1/agent.py b/hathor/p2p/sync_v1/agent.py index 3cdc8965f..7ec670065 100644 --- a/hathor/p2p/sync_v1/agent.py +++ b/hathor/p2p/sync_v1/agent.py @@ -26,7 +26,7 @@ from hathor.conf import HathorSettings from hathor.p2p.messages import GetNextPayload, GetTipsPayload, NextPayload, ProtocolMessages, TipsPayload -from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_agent import SyncAgent from hathor.p2p.sync_v1.downloader import Downloader from hathor.transaction import BaseTransaction from hathor.transaction.base_transaction import tx_or_block_from_bytes @@ -172,7 +172,7 @@ def stopProducing(self) -> None: self.priority_queue.clear() -class NodeSyncTimestamp(SyncManager): +class NodeSyncTimestamp(SyncAgent): """ An algorithm to sync the DAG between two peers using the timestamp of the transactions. This algorithm must assume that a new item may arrive while it is running. The item's timestamp diff --git a/hathor/p2p/sync_v1/factory_v1_0.py b/hathor/p2p/sync_v1/factory_v1_0.py index 5b618a7a1..acd430474 100644 --- a/hathor/p2p/sync_v1/factory_v1_0.py +++ b/hathor/p2p/sync_v1/factory_v1_0.py @@ -15,8 +15,8 @@ from typing import TYPE_CHECKING, Optional from hathor.p2p.manager import ConnectionsManager -from hathor.p2p.sync_factory import SyncManagerFactory -from hathor.p2p.sync_manager import SyncManager +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 @@ -25,7 +25,7 @@ from hathor.p2p.protocol import HathorProtocol -class SyncV10Factory(SyncManagerFactory): +class SyncV10Factory(SyncAgentFactory): def __init__(self, connections: ConnectionsManager): self.connections = connections self._downloader: Optional[Downloader] = None @@ -36,5 +36,5 @@ def get_downloader(self) -> Downloader: self._downloader = Downloader(self.connections.manager) return self._downloader - def create_sync_manager(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncManager: + 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_v1/factory_v1_1.py b/hathor/p2p/sync_v1/factory_v1_1.py index 43c7e11a8..57d8819ae 100644 --- a/hathor/p2p/sync_v1/factory_v1_1.py +++ b/hathor/p2p/sync_v1/factory_v1_1.py @@ -15,8 +15,8 @@ from typing import TYPE_CHECKING, Optional from hathor.p2p.manager import ConnectionsManager -from hathor.p2p.sync_factory import SyncManagerFactory -from hathor.p2p.sync_manager import SyncManager +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 @@ -25,7 +25,7 @@ from hathor.p2p.protocol import HathorProtocol -class SyncV11Factory(SyncManagerFactory): +class SyncV11Factory(SyncAgentFactory): def __init__(self, connections: ConnectionsManager): self.connections = connections self._downloader: Optional[Downloader] = None @@ -36,5 +36,5 @@ def get_downloader(self) -> Downloader: self._downloader = Downloader(self.connections.manager) return self._downloader - def create_sync_manager(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncManager: + 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_v2/factory.py b/hathor/p2p/sync_v2/factory.py index 1d28278e8..40b2b8294 100644 --- a/hathor/p2p/sync_v2/factory.py +++ b/hathor/p2p/sync_v2/factory.py @@ -15,8 +15,8 @@ from typing import TYPE_CHECKING, Optional from hathor.p2p.manager import ConnectionsManager -from hathor.p2p.sync_factory import SyncManagerFactory -from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_agent import SyncAgent +from hathor.p2p.sync_factory import SyncAgentFactory from hathor.p2p.sync_v2.manager import NodeBlockSync from hathor.util import Reactor @@ -24,9 +24,9 @@ from hathor.p2p.protocol import HathorProtocol -class SyncV2Factory(SyncManagerFactory): +class SyncV2Factory(SyncAgentFactory): def __init__(self, connections: ConnectionsManager): self.connections = connections - def create_sync_manager(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncManager: + def create_sync_agent(self, protocol: 'HathorProtocol', reactor: Optional[Reactor] = None) -> SyncAgent: return NodeBlockSync(protocol, reactor=reactor) diff --git a/hathor/p2p/sync_v2/manager.py b/hathor/p2p/sync_v2/manager.py index 3de3e94a3..e44bf2709 100644 --- a/hathor/p2p/sync_v2/manager.py +++ b/hathor/p2p/sync_v2/manager.py @@ -26,7 +26,7 @@ from hathor.conf import HathorSettings from hathor.p2p.messages import ProtocolMessages -from hathor.p2p.sync_manager import SyncManager +from hathor.p2p.sync_agent import SyncAgent from hathor.p2p.sync_v2.mempool import SyncMempoolManager from hathor.p2p.sync_v2.streamers import DEFAULT_STREAMING_LIMIT, BlockchainStreaming, StreamEnd, TransactionsStreaming from hathor.transaction import BaseTransaction, Block, Transaction @@ -53,7 +53,7 @@ class PeerState(Enum): SYNCING_MEMPOOL = 'syncing-mempool' -class NodeBlockSync(SyncManager): +class NodeBlockSync(SyncAgent): """ An algorithm to sync two peers based on their blockchain. """ name: str = 'node-block-sync' diff --git a/hathor/p2p/sync_v2/mempool.py b/hathor/p2p/sync_v2/mempool.py index 7c2130251..da7f5d040 100644 --- a/hathor/p2p/sync_v2/mempool.py +++ b/hathor/p2p/sync_v2/mempool.py @@ -29,15 +29,15 @@ class SyncMempoolManager: """Manage the sync-v2 mempool with one peer. """ - def __init__(self, sync_manager: 'NodeBlockSync'): + def __init__(self, sync_agent: 'NodeBlockSync'): """Initialize the sync-v2 mempool manager.""" - self.log = logger.new(peer=sync_manager.protocol.get_short_peer_id()) + self.log = logger.new(peer=sync_agent.protocol.get_short_peer_id()) # Shortcuts. - self.sync_manager = sync_manager - self.manager = self.sync_manager.manager + self.sync_agent = sync_agent + self.manager = self.sync_agent.manager self.tx_storage = self.manager.tx_storage - self.reactor = self.sync_manager.reactor + self.reactor = self.sync_agent.reactor # Set of tips we know but couldn't add to the DAG yet. self.missing_tips: set[bytes] = set() @@ -65,7 +65,7 @@ def _run(self) -> Generator[Deferred, Any, None]: try: yield self._unsafe_run() finally: - # sync_manager.run_sync will start it again when needed + # sync_agent.run_sync will start it again when needed self._is_running = False @inlineCallbacks @@ -73,13 +73,13 @@ def _unsafe_run(self) -> Generator[Deferred, Any, None]: """Run a single loop of the sync-v2 mempool.""" if not self.missing_tips: # No missing tips? Let's get them! - tx_hashes: list[bytes] = yield self.sync_manager.get_tips() + tx_hashes: list[bytes] = yield self.sync_agent.get_tips() self.missing_tips.update(h for h in tx_hashes if not self.tx_storage.transaction_exists(h)) while self.missing_tips: self.log.debug('We have missing tips! Let\'s start!', missing_tips=[x.hex() for x in self.missing_tips]) tx_id = next(iter(self.missing_tips)) - tx: BaseTransaction = yield self.sync_manager.get_tx(tx_id) + tx: BaseTransaction = yield self.sync_agent.get_tx(tx_id) # Stack used by the DFS in the dependencies. # We use a deque for performance reasons. self.log.debug('start mempool DSF', tx=tx.hash_hex) @@ -98,7 +98,7 @@ def _dfs(self, stack: deque[BaseTransaction]) -> Generator[Deferred, Any, None]: assert tx == stack.pop() else: self.log.debug('Iterate in the DFS.', missing_dep=missing_dep.hex()) - tx_dep = yield self.sync_manager.get_tx(missing_dep) + tx_dep = yield self.sync_agent.get_tx(missing_dep) stack.append(tx_dep) if len(stack) > self.MAX_STACK_LENGTH: stack.popleft() diff --git a/hathor/simulator/fake_connection.py b/hathor/simulator/fake_connection.py index dde2a91fd..9db893559 100644 --- a/hathor/simulator/fake_connection.py +++ b/hathor/simulator/fake_connection.py @@ -91,13 +91,13 @@ def is_both_synced(self) -> bool: return False assert isinstance(state1, ReadyState) # mypy can't infer this from the above assert isinstance(state2, ReadyState) # mypy can't infer this from the above - state1_is_errored = state1.sync_manager.is_errored() - state2_is_errored = state2.sync_manager.is_errored() + state1_is_errored = state1.sync_agent.is_errored() + state2_is_errored = state2.sync_agent.is_errored() if state1_is_errored or state2_is_errored: self.log.debug('peer errored', peer1_errored=state1_is_errored, peer2_errored=state2_is_errored) return False - state1_is_synced = state1.sync_manager.is_synced() - state2_is_synced = state2.sync_manager.is_synced() + state1_is_synced = state1.sync_agent.is_synced() + state2_is_synced = state2.sync_agent.is_synced() if not state1_is_synced or not state2_is_synced: self.log.debug('peer not synced', peer1_synced=state1_is_synced, peer2_synced=state2_is_synced) return False @@ -120,13 +120,13 @@ def can_step(self) -> bool: return True assert isinstance(state1, ReadyState) # mypy can't infer this from the above assert isinstance(state2, ReadyState) # mypy can't infer this from the above - state1_is_errored = state1.sync_manager.is_errored() - state2_is_errored = state2.sync_manager.is_errored() + state1_is_errored = state1.sync_agent.is_errored() + state2_is_errored = state2.sync_agent.is_errored() if state1_is_errored or state2_is_errored: self.log.debug('peer errored', peer1_errored=state1_is_errored, peer2_errored=state2_is_errored) return False - state1_is_synced = state1.sync_manager.is_synced() - state2_is_synced = state2.sync_manager.is_synced() + state1_is_synced = state1.sync_agent.is_synced() + state2_is_synced = state2.sync_agent.is_synced() if not state1_is_synced or not state2_is_synced: self.log.debug('peer not synced', peer1_synced=state1_is_synced, peer2_synced=state2_is_synced) return True diff --git a/tests/p2p/test_capabilities.py b/tests/p2p/test_capabilities.py index cfc4719f0..874267910 100644 --- a/tests/p2p/test_capabilities.py +++ b/tests/p2p/test_capabilities.py @@ -23,8 +23,8 @@ def test_capabilities(self): # Even if we don't have the capability we must connect because the whitelist url conf is None self.assertEqual(conn._proto1.state.state_name, 'READY') self.assertEqual(conn._proto2.state.state_name, 'READY') - self.assertIsInstance(conn._proto1.state.sync_manager, NodeSyncTimestamp) - self.assertIsInstance(conn._proto2.state.sync_manager, NodeSyncTimestamp) + self.assertIsInstance(conn._proto1.state.sync_agent, NodeSyncTimestamp) + self.assertIsInstance(conn._proto2.state.sync_agent, NodeSyncTimestamp) manager3 = self.create_peer(network, capabilities=[settings.CAPABILITY_WHITELIST]) manager4 = self.create_peer(network, capabilities=[settings.CAPABILITY_WHITELIST]) @@ -38,8 +38,8 @@ def test_capabilities(self): self.assertEqual(conn2._proto1.state.state_name, 'READY') self.assertEqual(conn2._proto2.state.state_name, 'READY') - self.assertIsInstance(conn2._proto1.state.sync_manager, NodeSyncTimestamp) - self.assertIsInstance(conn2._proto2.state.sync_manager, NodeSyncTimestamp) + self.assertIsInstance(conn2._proto1.state.sync_agent, NodeSyncTimestamp) + self.assertIsInstance(conn2._proto2.state.sync_agent, NodeSyncTimestamp) class SyncV2HathorCapabilitiesTestCase(unittest.SyncV2Params, unittest.TestCase): @@ -59,8 +59,8 @@ def test_capabilities(self): # Even if we don't have the capability we must connect because the whitelist url conf is None self.assertEqual(conn._proto1.state.state_name, 'READY') self.assertEqual(conn._proto2.state.state_name, 'READY') - self.assertIsInstance(conn._proto1.state.sync_manager, NodeBlockSync) - self.assertIsInstance(conn._proto2.state.sync_manager, NodeBlockSync) + self.assertIsInstance(conn._proto1.state.sync_agent, NodeBlockSync) + self.assertIsInstance(conn._proto2.state.sync_agent, NodeBlockSync) manager3 = self.create_peer(network, capabilities=[settings.CAPABILITY_WHITELIST, settings.CAPABILITY_SYNC_VERSION]) @@ -76,8 +76,8 @@ def test_capabilities(self): self.assertEqual(conn2._proto1.state.state_name, 'READY') self.assertEqual(conn2._proto2.state.state_name, 'READY') - self.assertIsInstance(conn2._proto1.state.sync_manager, NodeBlockSync) - self.assertIsInstance(conn2._proto2.state.sync_manager, NodeBlockSync) + self.assertIsInstance(conn2._proto1.state.sync_agent, NodeBlockSync) + self.assertIsInstance(conn2._proto2.state.sync_agent, NodeBlockSync) # sync-bridge should behave like sync-v2 diff --git a/tests/p2p/test_split_brain.py b/tests/p2p/test_split_brain.py index 02214a56b..7bc2f44c6 100644 --- a/tests/p2p/test_split_brain.py +++ b/tests/p2p/test_split_brain.py @@ -92,7 +92,7 @@ def test_split_brain_plain(self): dot2 = GraphvizVisualizer(manager2.tx_storage, include_verifications=True).dot() dot2.render('dot2-post') - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertSyncedProgress(node_sync) self.assertTipsEqual(manager1, manager2) self.assertConsensusEqual(manager1, manager2) diff --git a/tests/p2p/test_split_brain2.py b/tests/p2p/test_split_brain2.py index 59d24e6cb..fc4601898 100644 --- a/tests/p2p/test_split_brain2.py +++ b/tests/p2p/test_split_brain2.py @@ -67,8 +67,8 @@ def test_split_brain(self): dot2 = GraphvizVisualizer(manager2.tx_storage, include_verifications=True).dot() dot2.render('dot2-post') - self.assertSyncedProgress(conn12.proto1.state.sync_manager) - self.assertSyncedProgress(conn12.proto2.state.sync_manager) + self.assertSyncedProgress(conn12.proto1.state.sync_agent) + self.assertSyncedProgress(conn12.proto2.state.sync_agent) self.assertTipsEqual(manager1, manager2) self.assertConsensusEqual(manager1, manager2) self.assertConsensusValid(manager1) diff --git a/tests/p2p/test_sync.py b/tests/p2p/test_sync.py index 2c4709fb2..72d1d6592 100644 --- a/tests/p2p/test_sync.py +++ b/tests/p2p/test_sync.py @@ -101,7 +101,7 @@ def test_block_sync_only_genesis(self): conn.run_one_step() # PEER-ID conn.run_one_step() # READY - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(node_sync.synced_timestamp, node_sync.peer_timestamp) self.assertTipsEqual(self.manager1, manager2) @@ -119,7 +119,7 @@ def test_block_sync_new_blocks(self): conn.run_one_step(debug=True) self.clock.advance(0.1) - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(node_sync.synced_timestamp, node_sync.peer_timestamp) self.assertTipsEqual(self.manager1, manager2) self.assertConsensusEqual(self.manager1, manager2) @@ -139,7 +139,7 @@ def test_block_sync_many_new_blocks(self): conn.run_one_step(debug=True) self.clock.advance(0.1) - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(node_sync.synced_timestamp, node_sync.peer_timestamp) self.assertTipsEqual(self.manager1, manager2) self.assertConsensusEqual(self.manager1, manager2) @@ -167,7 +167,7 @@ def test_block_sync_new_blocks_and_txs(self): # dot2 = manager2.tx_storage.graphviz(format='pdf') # dot2.render('dot2') - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(self.manager1.tx_storage.latest_timestamp, manager2.tx_storage.latest_timestamp) self.assertEqual(node_sync.synced_timestamp, node_sync.peer_timestamp) self.assertTipsEqual(self.manager1, manager2) @@ -501,8 +501,8 @@ def test_sync_metadata(self): self.clock.advance(1) # check they have the same consensus - node_sync1 = conn.proto1.state.sync_manager - node_sync2 = conn.proto2.state.sync_manager + node_sync1 = conn.proto1.state.sync_agent + node_sync2 = conn.proto2.state.sync_agent self.assertEqual(node_sync1.peer_height, height) self.assertEqual(node_sync1.synced_height, height) self.assertEqual(node_sync2.peer_height, height) @@ -525,13 +525,13 @@ def test_sync_metadata(self): def test_tx_propagation_nat_peers(self): super().test_tx_propagation_nat_peers() - node_sync1 = self.conn1.proto1.state.sync_manager + node_sync1 = self.conn1.proto1.state.sync_agent self.assertEqual(self.manager1.tx_storage.latest_timestamp, self.manager2.tx_storage.latest_timestamp) self.assertEqual(node_sync1.peer_height, node_sync1.synced_height) self.assertEqual(node_sync1.peer_height, self.manager1.tx_storage.get_height_best_block()) self.assertConsensusEqual(self.manager1, self.manager2) - node_sync2 = self.conn2.proto1.state.sync_manager + node_sync2 = self.conn2.proto1.state.sync_agent self.assertEqual(self.manager2.tx_storage.latest_timestamp, self.manager3.tx_storage.latest_timestamp) self.assertEqual(node_sync2.peer_height, node_sync2.synced_height) self.assertEqual(node_sync2.peer_height, self.manager2.tx_storage.get_height_best_block()) @@ -558,7 +558,7 @@ def test_block_sync_new_blocks_and_txs(self): # dot2 = manager2.tx_storage.graphviz(format='pdf') # dot2.render('dot2') - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(self.manager1.tx_storage.latest_timestamp, manager2.tx_storage.latest_timestamp) self.assertEqual(node_sync.peer_height, node_sync.synced_height) self.assertEqual(node_sync.peer_height, self.manager1.tx_storage.get_height_best_block()) @@ -580,7 +580,7 @@ def test_block_sync_many_new_blocks(self): conn.run_one_step(debug=True) self.clock.advance(1) - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(node_sync.peer_height, node_sync.synced_height) self.assertEqual(node_sync.peer_height, self.manager1.tx_storage.get_height_best_block()) self.assertConsensusEqual(self.manager1, manager2) @@ -601,7 +601,7 @@ def test_block_sync_new_blocks(self): conn.run_one_step(debug=True) self.clock.advance(1) - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(node_sync.peer_height, node_sync.synced_height) self.assertEqual(node_sync.peer_height, self.manager1.tx_storage.get_height_best_block()) self.assertConsensusEqual(self.manager1, manager2) @@ -654,7 +654,7 @@ def test_full_sync(self): self.clock.advance(0.1) conn.run_until_empty(1000) - # node_sync = conn.proto1.state.sync_manager + # node_sync = conn.proto1.state.sync_agent # self.assertEqual(node_sync.synced_timestamp, node_sync.peer_timestamp) # self.assertTipsEqual(self.manager1, manager2) common_height = 25 + len_reward_unlock @@ -662,8 +662,8 @@ def test_full_sync(self): self.assertEqual(self.manager1.tx_storage.get_height_best_block(), common_height) self.assertEqual(manager2.tx_storage.get_height_best_block(), common_height) - node_sync1 = conn.proto1.state.sync_manager - node_sync2 = conn.proto2.state.sync_manager + node_sync1 = conn.proto1.state.sync_agent + node_sync2 = conn.proto2.state.sync_agent self.assertEqual(node_sync1.peer_height, common_height) self.assertEqual(node_sync1.synced_height, common_height) self.assertEqual(node_sync2.peer_height, common_height) @@ -712,8 +712,8 @@ def test_block_sync_checkpoints(self): self.assertEqual(self.manager1.tx_storage.get_best_block().get_metadata().height, TOTAL_BLOCKS) self.assertEqual(manager2.tx_storage.get_best_block().get_metadata().height, TOTAL_BLOCKS) - node_sync1 = conn.proto1.state.sync_manager - node_sync2 = conn.proto2.state.sync_manager + node_sync1 = conn.proto1.state.sync_agent + node_sync2 = conn.proto2.state.sync_agent self.assertEqual(node_sync1.peer_height, TOTAL_BLOCKS) self.assertEqual(node_sync1.synced_height, TOTAL_BLOCKS) @@ -737,7 +737,7 @@ def test_block_sync_only_genesis(self): conn.run_one_step(debug=True) self.clock.advance(1) - node_sync = conn.proto1.state.sync_manager + node_sync = conn.proto1.state.sync_agent self.assertEqual(node_sync.synced_height, 0) self.assertEqual(node_sync.peer_height, 0) diff --git a/tests/p2p/test_sync_rate_limiter.py b/tests/p2p/test_sync_rate_limiter.py index 2bb53433c..054543f78 100644 --- a/tests/p2p/test_sync_rate_limiter.py +++ b/tests/p2p/test_sync_rate_limiter.py @@ -30,7 +30,7 @@ def test_sync_rate_limiter(self): connected_peers2 = list(manager2.connections.connected_peers.values()) self.assertEqual(1, len(connected_peers2)) protocol1 = connected_peers2[0] - sync2 = protocol1.state.sync_manager + sync2 = protocol1.state.sync_agent sync2._send_tips = MagicMock() for i in range(100): @@ -62,7 +62,7 @@ def test_sync_rate_limiter_disconnect(self): self.assertEqual(1, len(connected_peers2)) protocol1 = connected_peers2[0] - sync1 = protocol1.state.sync_manager + sync1 = protocol1.state.sync_agent sync1._send_tips = Mock(wraps=sync1._send_tips) sync1.send_tips() @@ -109,7 +109,7 @@ def test_sync_rate_limiter_delayed_calls_draining(self): self.assertEqual(1, len(connected_peers2)) protocol1 = connected_peers2[0] - sync1 = protocol1.state.sync_manager + sync1 = protocol1.state.sync_agent sync1.send_tips() self.assertEqual(len(sync1._send_tips_call_later), 0) @@ -147,7 +147,7 @@ def test_sync_rate_limiter_delayed_calls_stop(self): self.assertEqual(1, len(connected_peers2)) protocol1 = connected_peers2[0] - sync1 = protocol1.state.sync_manager + sync1 = protocol1.state.sync_agent sync1.send_tips() self.assertEqual(len(sync1._send_tips_call_later), 0) diff --git a/tests/p2p/test_sync_v2.py b/tests/p2p/test_sync_v2.py index 234ca2306..0a9ef50bc 100644 --- a/tests/p2p/test_sync_v2.py +++ b/tests/p2p/test_sync_v2.py @@ -116,7 +116,7 @@ def _run_restart_test(self, *, full_verification: bool, use_tx_storage_cache: bo self.simulator.run(60) # Run until it's synced (time out of 1h) - sync3 = conn13.proto2.state.sync_manager + sync3 = conn13.proto2.state.sync_agent self.simulator.run(600) sync3._breakpoint = True @@ -221,14 +221,14 @@ def test_exceeds_streaming_and_mempool_limits(self) -> None: self.simulator.run(1) # Change manager1 default streaming and mempool limits. - sync1 = conn12.proto1.state.sync_manager + sync1 = conn12.proto1.state.sync_agent sync1.DEFAULT_STREAMING_LIMIT = 30 sync1.mempool_manager.MAX_STACK_LENGTH = 30 self.assertIsNone(sync1.blockchain_streaming) self.assertIsNone(sync1.transactions_streaming) # Change manager2 default streaming and mempool limits. - sync2 = conn12.proto2.state.sync_manager + sync2 = conn12.proto2.state.sync_agent sync2.DEFAULT_STREAMING_LIMIT = 50 sync2.mempool_manager.MAX_STACK_LENGTH = 50 self.assertIsNone(sync2.blockchain_streaming)