always set onsyncingmode (#547)

This commit is contained in:
a10zn8
2024-08-21 16:45:22 +03:00
committed by GitHub
parent 0e8eca53ec
commit 3d9193e11c

View File

@@ -109,26 +109,29 @@ object EthereumChainSpecific : AbstractPollChainSpecific() {
) { data -> ) { data ->
val raw = Global.objectMapper.readTree(data) val raw = Global.objectMapper.readTree(data)
if (raw.isBoolean) { if (raw.isBoolean) {
upstream.getHead().onSyncingNode(raw.asBoolean())
if (raw.asBoolean()) { if (raw.asBoolean()) {
UpstreamAvailability.SYNCING UpstreamAvailability.SYNCING
} else { } else {
UpstreamAvailability.OK UpstreamAvailability.OK
} }
} else if (raw.get("currentBlock") != null && raw.get("highestBlock") != null) { } else {
val current = if (raw.get("currentBlock") != null && raw.get("highestBlock") != null) {
BigInteger(raw.get("currentBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) val current =
val highest = BigInteger(raw.get("currentBlock")?.asText()?.lowercase()?.substringAfter("x"), 16)
BigInteger(raw.get("highestBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) val highest =
BigInteger(raw.get("highestBlock")?.asText()?.lowercase()?.substringAfter("x"), 16)
if (highest - current > config.syncingLagSize.toBigInteger()) { if (highest - current > config.syncingLagSize.toBigInteger()) {
UpstreamAvailability.SYNCING UpstreamAvailability.SYNCING
} else {
UpstreamAvailability.OK
}
} else { } else {
log.error("Received unknown syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}")
UpstreamAvailability.OK UpstreamAvailability.OK
} }
} else { }.also {
log.error("Received unknown syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}") upstream.getHead().onSyncingNode(it == UpstreamAvailability.SYNCING)
UpstreamAvailability.OK
} }
} }
} }