From b6d2bd6be6a91f3712741f798de69da9b73a4a33 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Mon, 12 Aug 2024 17:55:24 +0300 Subject: [PATCH] always set onsyncingmode --- .../ethereum/EthereumChainSpecific.kt | 27 ++++++++++--------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt index 2292f7010..3a4012ea8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumChainSpecific.kt @@ -109,26 +109,29 @@ object EthereumChainSpecific : AbstractPollChainSpecific() { ) { data -> val raw = Global.objectMapper.readTree(data) if (raw.isBoolean) { - upstream.getHead().onSyncingNode(raw.asBoolean()) if (raw.asBoolean()) { UpstreamAvailability.SYNCING } else { UpstreamAvailability.OK } - } else if (raw.get("currentBlock") != null && raw.get("highestBlock") != null) { - val current = - BigInteger(raw.get("currentBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) - val highest = - BigInteger(raw.get("highestBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) - - if (highest - current > config.syncingLagSize.toBigInteger()) { - UpstreamAvailability.SYNCING + } else { + if (raw.get("currentBlock") != null && raw.get("highestBlock") != null) { + val current = + BigInteger(raw.get("currentBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) + val highest = + BigInteger(raw.get("highestBlock")?.asText()?.lowercase()?.substringAfter("x"), 16) + + if (highest - current > config.syncingLagSize.toBigInteger()) { + UpstreamAvailability.SYNCING + } else { + UpstreamAvailability.OK + } } else { + log.error("Received unknown syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}") UpstreamAvailability.OK } - } else { - log.error("Received unknown syncing object ${raw.toPrettyString()} for upstream ${upstream.getId()}") - UpstreamAvailability.OK + }.also { + upstream.getHead().onSyncingNode(it == UpstreamAvailability.SYNCING) } } }