Skip to content

[Chore] Detailed logging of the handshaked peers #719

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions src/main/scala/io/iohk/ethereum/blockchain/sync/PeersClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class PeersClient(

def running(requesters: Requesters): Receive =
handleBlacklistMessages orElse handlePeerListMessages orElse {
case PrintStatus =>
log.debug("PeersClient status: requests: {}, available peers: {}", requesters.size, peersToDownloadFrom.size)
case PrintStatus => printStatus(requesters: Requesters)
case BlacklistPeer(peerId, reason) => peerById(peerId).foreach(blacklistIfHandshaked(_, reason))
case Request(message, peerSelector, toSerializable) =>
val requester = sender()
Expand Down Expand Up @@ -99,6 +98,24 @@ class PeersClient(
case _: GetBlockBodies => BlockBodies.code
case _: GetNodeData => NodeData.code
}

private def printStatus(requesters: Requesters): Unit = {
log.debug(
"Request status: requests in progress: {}, available peers: {}",
requesters.size,
peersToDownloadFrom.size
)

lazy val handshakedPeersStatus = handshakedPeers.map { case (peer, info) =>
val peerNetworkStatus = PeerNetworkStatus(
peer,
isBlacklisted = isBlacklisted(peer.id)
)
(peerNetworkStatus, info)
}

log.debug(s"Handshaked peers status (number of peers: ${handshakedPeersStatus.size}): $handshakedPeersStatus")
}
}

object PeersClient {
Expand All @@ -123,6 +140,16 @@ object PeersClient {
): Request[RequestMsg] =
Request(message, peerSelector, toSerializable)
}

case class PeerNetworkStatus(peer: Peer,
isBlacklisted: Boolean) {
override def toString: String =
s"PeerNetworkStatus {" +
s" RemotePeerAddress: ${peer.remoteAddress}," +
s" ConnectionDirection: ${if (peer.incomingConnection) "Incoming" else "Outgoing"}," +
s" Is blacklisted?: $isBlacklisted" +
s" }"
}
case object PrintStatus extends PeersClientMessage

sealed trait ResponseMessage
Expand Down
10 changes: 10 additions & 0 deletions src/main/scala/io/iohk/ethereum/network/EtcPeerManagerActor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import io.iohk.ethereum.network.p2p.{Message, MessageSerializable}
import io.iohk.ethereum.network.p2p.messages.CommonMessages.{NewBlock, Status}
import io.iohk.ethereum.network.p2p.messages.PV62.{BlockHeaders, GetBlockHeaders, NewBlockHashes}
import io.iohk.ethereum.network.p2p.messages.WireProtocol.Disconnect
import io.iohk.ethereum.utils.ByteStringUtils

/**
* EtcPeerManager actor is in charge of keeping updated information about each peer, while also being able to
Expand Down Expand Up @@ -243,6 +244,15 @@ object EtcPeerManagerActor {

def withBestBlockData(maxBlockNumber: BigInt, bestBlockHash: ByteString): PeerInfo =
copy(maxBlockNumber = maxBlockNumber, bestBlockHash = bestBlockHash)

override def toString: String =
s"PeerInfo {" +
s" totalDifficulty: $totalDifficulty," +
s" forkAccepted: $forkAccepted," +
s" maxBlockNumber: $maxBlockNumber," +
s" bestBlockHash: ${ByteStringUtils.hash2string(bestBlockHash)}," +
s" handshakeStatus: $remoteStatus" +
s" }"
}

object PeerInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class PeerManagerActor(
log.debug("Trying to connect to {} nodes", nodesToConnect.size)
nodesToConnect.foreach(n => self ! ConnectToPeer(n.node.toUri))
} else {
log.debug("The nodes list is empty")
log.debug("The nodes list is empty, no new nodes to connect to")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ object CommonMessages {
override def code: Int = Status.code

override def toString: String = {
s"""Status {
|protocolVersion: $protocolVersion
|networkId: $networkId
|totalDifficulty: $totalDifficulty
|bestHash: ${Hex.toHexString(bestHash.toArray[Byte])}
|genesisHash: ${Hex.toHexString(genesisHash.toArray[Byte])}
|}""".stripMargin
s"Status {" +
s" protocolVersion: $protocolVersion," +
s" networkId: $networkId," +
s" totalDifficulty: $totalDifficulty," +
s" bestHash: ${Hex.toHexString(bestHash.toArray[Byte])}," +
s" genesisHash: ${Hex.toHexString(genesisHash.toArray[Byte])}" +
s" }"
}
}

Expand Down