From ac1ef255eb8f703fe606cda417b503fc85c18cf3 Mon Sep 17 00:00:00 2001 From: KirillPamPam Date: Fri, 10 May 2024 18:56:56 +0400 Subject: [PATCH] Gelato head liveness (#474) --- .../upstream/ethereum/HeadLivenessValidator.kt | 6 ++++++ .../generic/connectors/GenericConnectorFactory.kt | 1 + .../generic/connectors/GenericRpcConnector.kt | 13 ++++++++++--- .../generic/connectors/RestConnectorFactory.kt | 1 + 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt index c5a3b03f0..208df55d1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt @@ -12,3 +12,9 @@ class NoHeadLivenessValidator : HeadLivenessValidator { return Flux.just(false) } } + +class AlwaysHeadLivenessValidator : HeadLivenessValidator { + override fun getFlux(): Flux { + return Flux.just(true) + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericConnectorFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericConnectorFactory.kt index 40a35a7a4..907649f7c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericConnectorFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericConnectorFactory.kt @@ -79,6 +79,7 @@ open class GenericConnectorFactory( headLivenessScheduler, expectedBlockTime, specific, + chain, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericRpcConnector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericRpcConnector.kt index dfa42cdb8..e1fa4d77f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericRpcConnector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/GenericRpcConnector.kt @@ -1,5 +1,6 @@ package io.emeraldpay.dshackle.upstream.generic.connectors +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.reader.ChainReader @@ -11,6 +12,7 @@ import io.emeraldpay.dshackle.upstream.IngressSubscription import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.MergedHead import io.emeraldpay.dshackle.upstream.NoIngressSubscription +import io.emeraldpay.dshackle.upstream.ethereum.AlwaysHeadLivenessValidator import io.emeraldpay.dshackle.upstream.ethereum.GenericWsHead import io.emeraldpay.dshackle.upstream.ethereum.HeadLivenessValidator import io.emeraldpay.dshackle.upstream.ethereum.HeadLivenessValidatorImpl @@ -45,6 +47,7 @@ class GenericRpcConnector( headLivenessScheduler: Scheduler, expectedBlockTime: Duration, private val chainSpecific: ChainSpecific, + private val chain: Chain, ) : GenericConnector, CachesEnabled { private val id = upstream.getId() private val pool: WsConnectionPool? @@ -126,9 +129,13 @@ class GenericRpcConnector( } } - liveness = when (connectorType) { - RPC_ONLY -> NoHeadLivenessValidator() - RPC_REQUESTS_WITH_MIXED_HEAD, RPC_REQUESTS_WITH_WS_HEAD, WS_ONLY -> HeadLivenessValidatorImpl(head, expectedBlockTime, headLivenessScheduler, id) + liveness = if (connectorType != RPC_ONLY && (chain == Chain.ALEPHZERO__SEPOLIA || chain == Chain.CONNEXT__SEPOLIA)) { + AlwaysHeadLivenessValidator() + } else { + when (connectorType) { + RPC_ONLY -> NoHeadLivenessValidator() + RPC_REQUESTS_WITH_MIXED_HEAD, RPC_REQUESTS_WITH_WS_HEAD, WS_ONLY -> HeadLivenessValidatorImpl(head, expectedBlockTime, headLivenessScheduler, id) + } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/RestConnectorFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/RestConnectorFactory.kt index 348206357..5b0950879 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/RestConnectorFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/generic/connectors/RestConnectorFactory.kt @@ -38,6 +38,7 @@ class RestConnectorFactory( headLivenessScheduler, expectedBlockTime, specific, + chain, ) }