Skip to content

Commit

Permalink
Fix archive detection (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillPamPam authored Sep 5, 2024
1 parent 6942cc6 commit eb72a43
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/io/emeraldpay/dshackle/Defaults.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<String, String>> {
return Flux.merge(
detectNodeType(),
detectArchiveNode(),
detectArchiveNode(notArchived),
detectGasLabels(),
)
}
Expand Down Expand Up @@ -88,8 +91,8 @@ class EthereumUpstreamSettingsDetector(
}
}

private fun detectArchiveNode(): Mono<Pair<String, String>> {
if (upstream.getLabels().firstOrNull { it.getOrDefault("archive", "") == "false" } != null) {
private fun detectArchiveNode(notArchived: Boolean): Mono<Pair<String, String>> {
if (notArchived) {
return Mono.empty()
}
return Mono.zip(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ class TestingCommons {
return new GenericUpstreamMock(Chain.ETHEREUM__MAINNET, api)
}

static GenericUpstreamMock upstream(Reader<ChainRequest, ChainResponse> api, Map<String, String> labels) {
return new GenericUpstreamMock("test-1", Chain.ETHEREUM__MAINNET, api, labels)
}

static GenericUpstreamMock upstream(Reader<ChainRequest, ChainResponse> api, String method) {
return upstream(api, [method])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String>("client_type", "bor"),
new Pair<String, String>("client_version", "v0.4.0"),
)
.expectComplete()
.verify(Duration.ofSeconds(1))
}

def "Only default label"() {
setup:
def up = Mock(DefaultUpstream) {
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit eb72a43

Please sign in to comment.