Implement health checks for peers, first check is if we have any blockfilter peers (#5393)

* Implement health checks for peers, first check is if we have any blockfilter peers

* Actually send HealthCheck message to stream
This commit is contained in:
Chris Stewart 2024-02-11 10:37:57 -06:00 committed by GitHub
parent d4ae659887
commit 9d58c9eb89
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 36 additions and 1 deletions

View File

@ -202,7 +202,14 @@ case class NeutrinoNode(
val peers = peerManager.peers
logger.info(s"Running inactivity checks for peers=${peers}")
val resultF = if (peers.nonEmpty) {
Future.unit //do nothing?
queueOpt match {
case Some(q) =>
q.offer(NodeStreamMessage.PeerHealthCheck)
.map(_ => ())
case None =>
logger.warn(s"No queue defined for inactivity check")
Future.unit
}
} else if (isStarted.get) {
//stop and restart to get more peers
stop()

View File

@ -46,5 +46,8 @@ object NodeStreamMessage {
case object NodeShutdown extends NodeStreamMessage
/** Checks our peers are healthy, for instance checking that we are peered with compact filter peers */
case object PeerHealthCheck extends NodeStreamMessage
case class Initialized(peer: Peer)
}

View File

@ -798,6 +798,15 @@ case class PeerManager(
}
case (state, NodeStreamMessage.PeerHealthCheck) =>
state match {
case s: NodeShuttingDown =>
logger.trace(s"Ignorinng peer health check as we are shutting down")
Future.successful(s)
case r: NodeRunningState =>
PeerManager.handleHealthCheck(r)
}
}
}
@ -1345,6 +1354,22 @@ object PeerManager extends Logging {
Future.successful(None)
}
}
}
def handleHealthCheck(runningState: NodeRunningState)(implicit
ec: ExecutionContext): Future[NodeRunningState] = {
val blockFilterPeers = runningState.peerDataMap.filter(
_._2.serviceIdentifier.hasServicesOf(
ServiceIdentifier.NODE_COMPACT_FILTERS))
if (blockFilterPeers.nonEmpty) {
//do nothing
Future.successful(runningState)
} else {
val peerFinder = runningState.peerFinder
for {
_ <- peerFinder.stop()
_ <- peerFinder.start()
} yield runningState
}
}
}