From bcb2a5e24e3fc2e4239490cd3f86677f5f75272f Mon Sep 17 00:00:00 2001 From: Alexey Koloskov Date: Tue, 18 Apr 2017 17:32:11 +0300 Subject: [PATCH 1/2] Load blockchain with max score --- .../scala/scorex/network/BlockchainSynchronizer.scala | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/main/scala/scorex/network/BlockchainSynchronizer.scala b/src/main/scala/scorex/network/BlockchainSynchronizer.scala index f59027b3a6a..42849c8b68b 100755 --- a/src/main/scala/scorex/network/BlockchainSynchronizer.scala +++ b/src/main/scala/scorex/network/BlockchainSynchronizer.scala @@ -48,11 +48,14 @@ class BlockchainSynchronizer(application: Application) extends ViewSynchronizer start(GettingExtension) { _ => val lastIds = history.lastBlockIds(application.settings.synchronizationSettings.maxRollback) - val msg = Message(GetSignaturesSpec, Right(lastIds), None) - networkControllerRef ! NetworkController.SendToNetwork(msg, SendToChosen(peerScores.keys.toSeq)) - gettingExtension(lastIds.map(InnerId), peerScores.map(peer => peer._1 -> Peer(peer._2))) + val max = peerScores.maxBy(_._2) + val maxPeers = peerScores.filter(_._2 == max._2) + + networkControllerRef ! NetworkController.SendToNetwork(msg, SendToChosen(maxPeers.keys.toSeq)) + + gettingExtension(lastIds.map(InnerId), maxPeers.map(peer => peer._1 -> Peer(peer._2))) } } @@ -237,7 +240,7 @@ class BlockchainSynchronizer(application: Application) extends ViewSynchronizer val sortedByScore = updatedPeers.toSeq.sortBy(_._2.score).map(_._1) - sortedByScore.filterNot(_ == active).headOption + sortedByScore.filterNot(_ == active).lastOption .orElse(sortedByScore.headOption) .map(newActive => ps.copy(active = newActive, peers = updatedPeers)) } From 071d1497674a9b4deb4db17582f4d85635ecd0aa Mon Sep 17 00:00:00 2001 From: Alexey Koloskov Date: Tue, 18 Apr 2017 17:49:13 +0300 Subject: [PATCH 2/2] Load blockchain with max score --- src/main/scala/scorex/network/BlockchainSynchronizer.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scala/scorex/network/BlockchainSynchronizer.scala b/src/main/scala/scorex/network/BlockchainSynchronizer.scala index 42849c8b68b..137fba11045 100755 --- a/src/main/scala/scorex/network/BlockchainSynchronizer.scala +++ b/src/main/scala/scorex/network/BlockchainSynchronizer.scala @@ -55,7 +55,7 @@ class BlockchainSynchronizer(application: Application) extends ViewSynchronizer networkControllerRef ! NetworkController.SendToNetwork(msg, SendToChosen(maxPeers.keys.toSeq)) - gettingExtension(lastIds.map(InnerId), maxPeers.map(peer => peer._1 -> Peer(peer._2))) + gettingExtension(lastIds.map(InnerId), peerScores.map(peer => peer._1 -> Peer(peer._2))) } } @@ -241,7 +241,7 @@ class BlockchainSynchronizer(application: Application) extends ViewSynchronizer val sortedByScore = updatedPeers.toSeq.sortBy(_._2.score).map(_._1) sortedByScore.filterNot(_ == active).lastOption - .orElse(sortedByScore.headOption) + .orElse(sortedByScore.lastOption) .map(newActive => ps.copy(active = newActive, peers = updatedPeers)) }