From 560db71e95d61409715f4c16fd74263152c77360 Mon Sep 17 00:00:00 2001 From: Chih Cheng Liang Date: Mon, 23 Dec 2019 23:21:27 +0800 Subject: [PATCH] PR feedback: log peer_id --- trinity/protocol/bcc_libp2p/node.py | 8 ++++++++ trinity/protocol/bcc_libp2p/utils.py | 8 ++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/trinity/protocol/bcc_libp2p/node.py b/trinity/protocol/bcc_libp2p/node.py index 72cbd6f81f..da1b96e5ff 100644 --- a/trinity/protocol/bcc_libp2p/node.py +++ b/trinity/protocol/bcc_libp2p/node.py @@ -611,6 +611,10 @@ async def _handle_status(self, stream: INetStream) -> None: self._add_peer_from_status(peer_id, peer_status) if peer_is_ahead(self.chain, peer_status): + logger.debug( + "Peer's chain is ahead of us, start syncing with the peer(%s)", + str(peer_id), + ) await self._event_bus.broadcast(SyncRequest()) async def request_status(self, peer_id: ID) -> None: @@ -631,6 +635,10 @@ async def request_status(self, peer_id: ID) -> None: self._add_peer_from_status(peer_id, peer_status) if peer_is_ahead(self.chain, peer_status): + logger.debug( + "Peer's chain is ahead of us, start syncing with the peer(%s)", + str(peer_id), + ) await self._event_bus.broadcast(SyncRequest()) async def _handle_goodbye(self, stream: INetStream) -> None: diff --git a/trinity/protocol/bcc_libp2p/utils.py b/trinity/protocol/bcc_libp2p/utils.py index cc4f8b5abe..2300d01e28 100644 --- a/trinity/protocol/bcc_libp2p/utils.py +++ b/trinity/protocol/bcc_libp2p/utils.py @@ -170,14 +170,10 @@ def peer_is_ahead(chain: BaseBeaconChain, peer_status: Status) -> bool: peer_has_higher_finalized_epoch = peer_status.finalized_epoch > checkpoint.epoch peer_has_equal_finalized_epoch = peer_status.finalized_epoch == checkpoint.epoch peer_has_higher_head_slot = peer_status.head_slot > head_block.slot - if ( + return ( peer_has_higher_finalized_epoch or (peer_has_equal_finalized_epoch and peer_has_higher_head_slot) - ): - logger.debug("Peer's chain is ahead of us, start syncing with the peer.") - return True - else: - return False + ) def validate_start_slot(chain: BaseBeaconChain, start_slot: Slot) -> None: