Ignore archive labels set manually (#471)

* Ignore archive labels set manually

* not check archive if archive label set to false
This commit is contained in:
Anton
2024-05-08 14:24:35 +03:00
committed by GitHub
parent 289dae92a2
commit 72c6b9dd15
2 changed files with 8 additions and 2 deletions

View File

@@ -43,12 +43,15 @@ class EthereumUpstreamSettingsDetector(
} }
private fun detectArchiveNode(): Mono<Pair<String, String>> { private fun detectArchiveNode(): Mono<Pair<String, String>> {
if (upstream.getLabels().firstOrNull { it.getOrDefault("archive", "") == "false" } != null) {
return Mono.empty()
}
return Mono.zip( return Mono.zip(
blockNumberReader.readEarliestBlock(chain).flatMap { haveBalance(it) }, blockNumberReader.readEarliestBlock(chain).flatMap { haveBalance(it) },
blockNumberReader.readArchiveBlock().flatMap { haveBalance(it) }, blockNumberReader.readArchiveBlock().flatMap { haveBalance(it) },
) )
.map { "archive" to "true" } .map { "archive" to "true" }
.onErrorResume { Mono.empty() } .onErrorResume { Mono.just("archive" to "false") }
} }
private fun haveBalance(blockNumber: String): Mono<ByteArray> { private fun haveBalance(blockNumber: String): Mono<ByteArray> {

View File

@@ -1,6 +1,7 @@
package io.emeraldpay.dshackle.upstream.ethereum package io.emeraldpay.dshackle.upstream.ethereum
import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Chain
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.reader.Reader
import io.emeraldpay.dshackle.test.ApiReaderMock import io.emeraldpay.dshackle.test.ApiReaderMock
import io.emeraldpay.dshackle.test.TestingCommons 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" "Bor/v0.4.0/linux-amd64/go1.19.10" | "bor" | "v0.4.0"
} }
def "No any label"() { def "Only default label"() {
setup: setup:
def up = Mock(DefaultUpstream) { def up = Mock(DefaultUpstream) {
4 * getIngressReader() >> Mock(Reader) { 4 * getIngressReader() >> Mock(Reader) {
@@ -61,12 +62,14 @@ class EthereumUpstreamSettingsDetectorSpec extends Specification {
1 * read(new ChainRequest("eth_getBalance", new ListParams(["0x0000000000000000000000000000000000000000", "0x2710"]))) >> 1 * read(new ChainRequest("eth_getBalance", new ListParams(["0x0000000000000000000000000000000000000000", "0x2710"]))) >>
Mono.just(new ChainResponse("".getBytes(), null)) Mono.just(new ChainResponse("".getBytes(), null))
} }
getLabels() >> []
} }
def detector = new EthereumUpstreamSettingsDetector(up, Chain.ETHEREUM__MAINNET) def detector = new EthereumUpstreamSettingsDetector(up, Chain.ETHEREUM__MAINNET)
when: when:
def act = detector.detectLabels() def act = detector.detectLabels()
then: then:
StepVerifier.create(act) StepVerifier.create(act)
.expectNext(new Pair<String, String>("archive", "false"))
.expectComplete() .expectComplete()
.verify(Duration.ofSeconds(1)) .verify(Duration.ofSeconds(1))
} }