Improve archive detection algorithm for node (#249)

This commit is contained in:
Vyacheslav
2023-07-14 16:17:21 +03:00
committed by GitHub
parent fb91effd26
commit 2031d18199
2 changed files with 17 additions and 3 deletions

View File

@@ -6,6 +6,7 @@ import io.emeraldpay.dshackle.Global.Companion.objectMapper
import io.emeraldpay.dshackle.reader.JsonRpcReader
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest
import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse
import io.emeraldpay.etherjar.hex.HexQuantity
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
@@ -39,7 +40,17 @@ class EthereumLabelsDetector(
private fun detectArchiveNode(): Mono<Pair<String, String>> {
return reader
.read(JsonRpcRequest("eth_getBalance", listOf("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0", "0x1")))
.read(JsonRpcRequest("eth_blockNumber", listOf()))
.flatMap(JsonRpcResponse::requireResult)
.flatMap {
val blockNum = HexQuantity.from(String(it).substring(3, it.size - 1).toLong(radix = 16) - 10_000) // this is definitely archive
reader.read(
JsonRpcRequest(
"eth_getBalance",
listOf("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0", blockNum.toHex())
)
)
}
.flatMap(JsonRpcResponse::requireResult)
.map { "archive" to "true" }
.onErrorResume { Mono.empty() }