Skip to content

Instantly share code, notes, and snippets.

@ismagin
Created May 24, 2017 14:35
Show Gist options
  • Save ismagin/60aae3082ff58b8fdcc763d842736987 to your computer and use it in GitHub Desktop.
Save ismagin/60aae3082ff58b8fdcc763d842736987 to your computer and use it in GitHub Desktop.
Finds first different block betweeen two waves nodes
object LCB extends App {
def get(url: String) = scala.io.Source.fromURL(url).mkString
def blockAt(nodeHttp: String, blockHeight: Int) = get(nodeHttp + "/blocks/at/" + blockHeight)
def nodeComparator(node1: String, node2: String)(h: Int): Boolean = blockAt(node1, h) == blockAt(node2, h)
val TESTNET1 = "http://52.30.47.67:6869"
val TESTNET2 = "http://52.28.66.217:6869"
val TESTNET3 = "http://52.77.111.219:6869"
val TESTNET4 = "http://52.51.92.182:6869"
def firstDifferent(min: Int, max: Int, areSame: Int => Boolean): Int = {
println("searching [" + min + ", " + max + ")")
if (max - min <= 1)
max
else {
val split = (min + max) / 2
if (areSame(split))
firstDifferent(split, max, areSame)
else firstDifferent(min, split, areSame)
}
}
println("first different block height is " + firstDifferent(1, 87450, nodeComparator(TESTNET3, TESTNET4)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment