Add check we have more than 1 peer before we try to syncFromNewPeer() (#4966)

* Add check we have more than 1 peer before we try to syncFromNewPeer()

* Empty commit

* Return failed Future rather than just logging an error
This commit is contained in:
Chris Stewart 2023-02-03 15:46:24 -06:00 committed by GitHub
parent 76fc3cdc41
commit f6207b1c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 6 deletions

View File

@ -356,10 +356,15 @@ case class PeerManager(
//reconnection tries exceeding the max limit in which the client was stopped to disconnect from it, remove it
_peerData.remove(peer)
val syncPeer = node.getDataMessageHandler.syncPeer
if (syncPeer.isDefined && syncPeer.get == peer) {
if (peers.length > 1 && syncPeer.isDefined && syncPeer.get == peer) {
syncFromNewPeer().map(_ => ())
} else Future.unit
} else if (syncPeer.isEmpty) {
Future.unit
} else {
val exn = new RuntimeException(
s"No new peers to sync from, cannot start new sync. Terminated sync with syncPeer=$syncPeer")
Future.failed(exn)
}
} else if (waitingForDeletion.contains(peer)) {
//a peer we wanted to disconnect has remove has stopped the client actor, finally mark this as deleted
_waitingForDeletion.remove(peer)
@ -371,13 +376,13 @@ case class PeerManager(
}
def onVersionMessage(peer: Peer, versionMsg: VersionMessage): Unit = {
assert(!finder.hasPeer(peer) || !peerData.contains(peer),
s"$peer cannot be both a test and a persistent peer")
require(!finder.hasPeer(peer) || !peerData.contains(peer),
s"$peer cannot be both a test and a persistent peer")
if (finder.hasPeer(peer)) {
finder.getData(peer).setServiceIdentifier(versionMsg.services)
} else if (peerData.contains(peer)) {
assert(
require(
peerData(peer).serviceIdentifier.bytes == versionMsg.services.bytes)
} else {
logger.warn(s"onVersionMessage called for unknown $peer")

View File

@ -65,6 +65,7 @@
<!-- See exceptions thrown in actor-->
<logger name="org.bitcoins.node.networking.P2PClientSupervisor" level="WARN"/>
<logger name="org.bitcoins.node.PeerManager" level="WARN"/>
<!-- ╔════════════════════╗ -->
<!-- ║ Chain module ║ -->
<!-- ╚════════════════════╝ -->