From 29a03f984d466ee7b512f0e1a1352b535b476a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D0=B8=D1=80=D0=B8=D0=BB=D0=BB?= Date: Wed, 4 Sep 2024 14:49:06 +0400 Subject: [PATCH] Fix archive detection --- .../kotlin/io/emeraldpay/dshackle/Defaults.kt | 2 +- .../EthereumUpstreamSettingsDetector.kt | 9 ++++--- .../generic/AggregatedUpstreamValidator.kt | 2 +- .../dshackle/test/TestingCommons.groovy | 4 ++++ ...thereumUpstreamSettingsDetectorSpec.groovy | 24 +++++++++++++++++++ 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt b/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt index 50e700345..d54f9e540 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt @@ -25,7 +25,7 @@ class Defaults { const val maxMetadataSize = 16384 val timeout: Duration = Duration.ofSeconds(60) val timeoutInternal: Duration = timeout.dividedBy(4) - val internalCallsTimeout = Duration.ofSeconds(3) + val internalCallsTimeout = Duration.ofSeconds(5) val retryConnection: Duration = Duration.ofSeconds(10) val grpcServerKeepAliveTime: Long = 15 // seconds val grpcServerKeepAliveTimeout: Long = 5 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 76d3f756e..3ee933c34 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetector.kt @@ -19,11 +19,14 @@ class EthereumUpstreamSettingsDetector( private val chain: Chain, ) : BasicEthUpstreamSettingsDetector(_upstream) { private val blockNumberReader = EthereumArchiveBlockNumberReader(upstream.getIngressReader()) + private val notArchived = upstream + .getLabels() + .find { it.getOrDefault("archive", "") == "false" } != null override fun internalDetectLabels(): Flux> { return Flux.merge( detectNodeType(), - detectArchiveNode(), + detectArchiveNode(notArchived), detectGasLabels(), ) } @@ -88,8 +91,8 @@ class EthereumUpstreamSettingsDetector( } } - private fun detectArchiveNode(): Mono> { - if (upstream.getLabels().firstOrNull { it.getOrDefault("archive", "") == "false" } != null) { + private fun detectArchiveNode(notArchived: Boolean): Mono> { + if (notArchived) { return Mono.empty() } return Mono.zip( diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/AggregatedUpstreamValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/AggregatedUpstreamValidator.kt index aa921ed0b..1cb244e9c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/AggregatedUpstreamValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/AggregatedUpstreamValidator.kt @@ -38,7 +38,7 @@ class AggregatedUpstreamValidator( .timeout(internalCallsTimeout) .onErrorResume { log.error("Error during upstream validation for {}, reason - {}", upstream.getId(), it.message) - Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_FATAL_SETTINGS_ERROR) + Mono.just(ValidateUpstreamSettingsResult.UPSTREAM_SETTINGS_ERROR) } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index cb50fa553..27c03b8f4 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -76,6 +76,10 @@ class TestingCommons { return new GenericUpstreamMock(Chain.ETHEREUM__MAINNET, api) } + static GenericUpstreamMock upstream(Reader api, Map labels) { + return new GenericUpstreamMock("test-1", Chain.ETHEREUM__MAINNET, api, labels) + } + static GenericUpstreamMock upstream(Reader api, String method) { return upstream(api, [method]) } 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 8c7b8fd72..84d9a4fcb 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetectorSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamSettingsDetectorSpec.groovy @@ -84,6 +84,29 @@ class EthereumUpstreamSettingsDetectorSpec extends Specification { .verify(Duration.ofSeconds(1)) } + def "No archive label if it is set manually"() { + setup: + def up = TestingCommons.upstream( + new ApiReaderMock().tap { + answer("web3_clientVersion", [], "Bor/v0.4.0/linux-amd64/go1.19.10") + answer("eth_blockNumber", [], "0x10df3e5") + }, + Map.of("archive", "false") + ) + def detector = new EthereumUpstreamSettingsDetector(up, Chain.ETHEREUM__MAINNET) + + when: + def act = detector.internalDetectLabels() + then: + StepVerifier.create(act) + .expectNext( + new Pair("client_type", "bor"), + new Pair("client_version", "v0.4.0"), + ) + .expectComplete() + .verify(Duration.ofSeconds(1)) + } + def "Only default label"() { setup: def up = Mock(DefaultUpstream) { @@ -128,6 +151,7 @@ class EthereumUpstreamSettingsDetectorSpec extends Specification { 1 * read(new ChainRequest("web3_clientVersion", new ListParams())) >> Mono.just(new ChainResponse('"Erigon/v1.12.0-stable-e501b3b0/linux-amd64/go1.20.3"'.getBytes(), null)) } + 1 * getLabels() >> List.of() } def detector = new EthereumUpstreamSettingsDetector(up, Chain.ETHEREUM__MAINNET) when: