Skip to content

Commit

Permalink
Merge pull request #246 from wavesplatform/load_blockchain_with_max_s…
Browse files Browse the repository at this point in the history
…core

Load blockchain with max score
  • Loading branch information
alexeykiselev authored Apr 18, 2017
2 parents 7a96719 + 071d149 commit 53475b3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/scala/scorex/network/BlockchainSynchronizer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,12 @@ 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))

val max = peerScores.maxBy(_._2)
val maxPeers = peerScores.filter(_._2 == max._2)

networkControllerRef ! NetworkController.SendToNetwork(msg, SendToChosen(maxPeers.keys.toSeq))

gettingExtension(lastIds.map(InnerId), peerScores.map(peer => peer._1 -> Peer(peer._2)))
}
Expand Down Expand Up @@ -237,8 +240,8 @@ class BlockchainSynchronizer(application: Application) extends ViewSynchronizer

val sortedByScore = updatedPeers.toSeq.sortBy(_._2.score).map(_._1)

sortedByScore.filterNot(_ == active).headOption
.orElse(sortedByScore.headOption)
sortedByScore.filterNot(_ == active).lastOption
.orElse(sortedByScore.lastOption)
.map(newActive => ps.copy(active = newActive, peers = updatedPeers))
}

Expand Down

0 comments on commit 53475b3

Please sign in to comment.