Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix archive detection #561

Merged
merged 1 commit into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading