Skip to content
This repository has been archived by the owner on Jul 1, 2021. It is now read-only.

Commit

Permalink
PR feedback: log peer_id
Browse files Browse the repository at this point in the history
  • Loading branch information
ChihChengLiang committed Dec 23, 2019
1 parent eb6b752 commit 560db71
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
8 changes: 8 additions & 0 deletions trinity/protocol/bcc_libp2p/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
8 changes: 2 additions & 6 deletions trinity/protocol/bcc_libp2p/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 560db71

Please sign in to comment.