From 8306ceaf63a8c7389dc4bdb69d0a37fa140c05cf Mon Sep 17 00:00:00 2001 From: Vyacheslav Date: Thu, 22 Feb 2024 18:08:43 +0200 Subject: [PATCH] add logs subscription detection fix (#426) --- .../upstream/ethereum/EthereumEgressSubscription.kt | 7 ++++++- .../ethereum/EthereumEgressSubscriptionSpec.groovy | 8 ++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt index eceda46b4..149fbd1c4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt @@ -31,7 +31,12 @@ open class EthereumEgressSubscription( open val logs = ConnectLogs(upstream, scheduler) override fun getAvailableTopics(): List { val subs = if (upstream.getCapabilities().contains(Capability.WS_HEAD)) { - listOf(METHOD_NEW_HEADS, METHOD_LOGS) + // we can't use logs without eth_getLogs method available + if (upstream.getMethods().isAvailable("eth_getLogs")) { + listOf(METHOD_NEW_HEADS, METHOD_LOGS) + } else { + listOf(METHOD_NEW_HEADS) + } } else { listOf() } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy index 78ce134bf..52e8bcb38 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscriptionSpec.groovy @@ -200,6 +200,14 @@ class EthereumEgressSubscriptionSpec extends Specification { def ethereumSubscribe3 = new EthereumEgressSubscription(TestingCommons.multistream(up3) as GenericMultistream, Schedulers.boundedElastic(), Stub(PendingTxesSource)) then: ethereumSubscribe3.getAvailableTopics().toSet() == [EthereumEgressSubscription.METHOD_LOGS, EthereumEgressSubscription.METHOD_NEW_HEADS, EthereumEgressSubscription.METHOD_PENDING_TXES].toSet() + when: + def up4 = TestingCommons.upstream(TestingCommons.api(), "eth_getBlockByNumber") + up4.getConnectorMock().setLiveness(Flux.just(true)) + up4.stop() + up4.start() + def ethereumSubscribe4 = new EthereumEgressSubscription(TestingCommons.multistream(up4) as GenericMultistream, Schedulers.boundedElastic(), null) + then: + ethereumSubscribe4.getAvailableTopics().toSet() == [EthereumEgressSubscription.METHOD_NEW_HEADS].toSet() } }