From 72c6b9dd151b7a53881ed32d19ba21583506e017 Mon Sep 17 00:00:00 2001 From: Anton Date: Wed, 8 May 2024 14:24:35 +0300 Subject: [PATCH] Ignore archive labels set manually (#471) * Ignore archive labels set manually * not check archive if archive label set to false --- .../upstream/ethereum/EthereumUpstreamSettingsDetector.kt | 5 ++++- .../ethereum/EthereumUpstreamSettingsDetectorSpec.groovy | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetector.kt index e99a22f5..24c93405 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetector.kt @@ -43,12 +43,15 @@ class EthereumUpstreamSettingsDetector( } private fun detectArchiveNode(): Mono> { + if (upstream.getLabels().firstOrNull { it.getOrDefault("archive", "") == "false" } != null) { + return Mono.empty() + } return Mono.zip( blockNumberReader.readEarliestBlock(chain).flatMap { haveBalance(it) }, blockNumberReader.readArchiveBlock().flatMap { haveBalance(it) }, ) .map { "archive" to "true" } - .onErrorResume { Mono.empty() } + .onErrorResume { Mono.just("archive" to "false") } } private fun haveBalance(blockNumber: String): Mono { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetectorSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetectorSpec.groovy index f10abaa3..29747187 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetectorSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetectorSpec.groovy @@ -1,6 +1,7 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.dshackle.Chain +import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.test.ApiReaderMock import io.emeraldpay.dshackle.test.TestingCommons @@ -48,7 +49,7 @@ class EthereumUpstreamSettingsDetectorSpec extends Specification { "Bor/v0.4.0/linux-amd64/go1.19.10" | "bor" | "v0.4.0" } - def "No any label"() { + def "Only default label"() { setup: def up = Mock(DefaultUpstream) { 4 * getIngressReader() >> Mock(Reader) { @@ -61,12 +62,14 @@ class EthereumUpstreamSettingsDetectorSpec extends Specification { 1 * read(new ChainRequest("eth_getBalance", new ListParams(["0x0000000000000000000000000000000000000000", "0x2710"]))) >> Mono.just(new ChainResponse("".getBytes(), null)) } + getLabels() >> [] } def detector = new EthereumUpstreamSettingsDetector(up, Chain.ETHEREUM__MAINNET) when: def act = detector.detectLabels() then: StepVerifier.create(act) + .expectNext(new Pair("archive", "false")) .expectComplete() .verify(Duration.ofSeconds(1)) }