From 443839062f8306ee9d8b210fe3f4572a91facc9a Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 15 Nov 2022 20:52:15 +0400 Subject: [PATCH 01/20] multistreams as beans --- .../config/context/MultistreamsConfig.kt | 27 ++++++++ .../upstream/CurrentMultistreamHolder.kt | 69 +++++++------------ .../dshackle/test/TestingCommons.groovy | 12 ++++ .../CurrentMultistreamHolderSpec.groovy | 8 +-- 4 files changed, 69 insertions(+), 47 deletions(-) create mode 100644 src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt new file mode 100644 index 00000000..7ffdd93d --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt @@ -0,0 +1,27 @@ +package io.emeraldpay.dshackle.config.context + +import io.emeraldpay.dshackle.cache.CachesFactory +import io.emeraldpay.dshackle.upstream.Multistream +import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream +import io.emeraldpay.grpc.BlockchainType +import io.emeraldpay.grpc.Chain +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Configuration + +@Configuration +class MultistreamsConfig { + @Bean + fun allMultistreams(cachesFactory: CachesFactory): List { + return Chain.values() + .mapNotNull { chain -> + when (BlockchainType.from(chain)) { + BlockchainType.EVM_POS -> EthereumPosMultiStream(chain, ArrayList(), cachesFactory.getCaches(chain)) + BlockchainType.EVM_POW -> EthereumMultistream(chain, ArrayList(), cachesFactory.getCaches(chain)) + BlockchainType.BITCOIN -> BitcoinMultistream(chain, ArrayList(), cachesFactory.getCaches(chain)) + else -> null + } + } + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index 7587d6c2..2de935f6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -17,39 +17,35 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.cache.CachesEnabled -import io.emeraldpay.dshackle.cache.CachesFactory import io.emeraldpay.dshackle.startup.UpstreamChange -import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinUpstream import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods -import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream -import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Repository +import org.springframework.stereotype.Component import reactor.core.publisher.Flux import reactor.core.publisher.Sinks -import java.util.Collections -import java.util.concurrent.Callable +import java.util.* import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.locks.ReentrantLock import javax.annotation.PreDestroy import kotlin.concurrent.withLock -@Repository +@Component open class CurrentMultistreamHolder( - @Autowired private val cachesFactory: CachesFactory + private val multistreams: List ) : MultistreamHolder { private val log = LoggerFactory.getLogger(CurrentMultistreamHolder::class.java) - private val chainMapping = ConcurrentHashMap() + private val chainMapping = ConcurrentHashMap().apply { + multistreams.forEach { this[it.chain] = it } + } private val chainsBus = Sinks.many() .multicast() .directBestEffort() @@ -64,28 +60,22 @@ open class CurrentMultistreamHolder( when (BlockchainType.from(chain)) { BlockchainType.EVM_POW -> { val up = change.upstream.cast(EthereumUpstream::class.java) - val current = chainMapping[chain] - val factory = Callable { - EthereumMultistream(chain, ArrayList(), cachesFactory.getCaches(chain)) - } - processUpdate(change, up, current, factory) + val current = chainMapping.getValue(chain) + processUpdate(change, up, current) } + BlockchainType.EVM_POS -> { val up = change.upstream.cast(EthereumPosUpstream::class.java) - val current = chainMapping[chain] - val factory = Callable { - EthereumPosMultiStream(chain, ArrayList(), cachesFactory.getCaches(chain)) - } - processUpdate(change, up, current, factory) + val current = chainMapping.getValue(chain) + processUpdate(change, up, current) } + BlockchainType.BITCOIN -> { val up = change.upstream.cast(BitcoinUpstream::class.java) - val current = chainMapping[chain] - val factory = Callable { - BitcoinMultistream(chain, ArrayList(), cachesFactory.getCaches(chain)) - } - processUpdate(change, up, current, factory) + val current = chainMapping.getValue(chain) + processUpdate(change, up, current) } + else -> { log.error("Update for unsupported chain: $chain") } @@ -96,27 +86,17 @@ open class CurrentMultistreamHolder( } } - fun processUpdate(change: UpstreamChange, up: Upstream, current: Multistream?, factory: Callable) { + fun processUpdate(change: UpstreamChange, up: Upstream, current: Multistream) { val chain = change.chain if (change.type == UpstreamChange.ChangeType.REMOVED) { - current?.removeUpstream(up.getId()) + current.removeUpstream(up.getId()) log.info("Upstream ${change.upstream.getId()} with chain $chain has been removed") } else { - if (current == null) { - val created = factory.call() - if (up is CachesEnabled) { - up.setCaches(created.caches) - } - created.addUpstream(up) - created.start() - chainMapping[chain] = created - chainsBus.tryEmitNext(chain) - } else { - if (up is CachesEnabled) { - up.setCaches(current.caches) - } - current.addUpstream(up) + if (up is CachesEnabled) { + up.setCaches(current.caches) } + current.addUpstream(up) + if (!callTargets.containsKey(chain)) { setupDefaultMethods(chain) } @@ -129,7 +109,10 @@ open class CurrentMultistreamHolder( } override fun getAvailable(): List { - return Collections.unmodifiableList(chainMapping.keys.toList()) + return multistreams.asSequence() + .filter { it.isAvailable() } + .map { it.chain } + .toList() } override fun observeChains(): Flux { diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index fbec4d77..6ad08167 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -27,6 +27,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash @@ -90,6 +91,17 @@ class TestingCommons { return new CachesFactory(new CacheConfig()) } + static List defaultMultistreams() { + return [ + multistreamWithoutUpstreams(Chain.ETHEREUM), + multistreamWithoutUpstreams(Chain.ETHEREUM_CLASSIC) + ] + } + + static Multistream multistreamWithoutUpstreams(Chain chain) { + return new EthereumPosMultiStream(chain, [], emptyCaches().getCaches(chain)) + } + static FileResolver fileResolver() { return new FileResolver(new File("src/test/resources")) } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy index 2f38eecd..0ec23584 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy @@ -26,7 +26,7 @@ class CurrentMultistreamHolderSpec extends Specification { def "add upstream"() { setup: - def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) + def current = new CurrentMultistreamHolder(TestingCommons.defaultMultistreams()) def up = new EthereumPosRpcUpstreamMock("test", Chain.ETHEREUM, TestingCommons.api()) when: current.update(new UpstreamChange(Chain.ETHEREUM, up, UpstreamChange.ChangeType.ADDED)) @@ -37,7 +37,7 @@ class CurrentMultistreamHolderSpec extends Specification { def "add multiple upstreams"() { setup: - def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) + def current = new CurrentMultistreamHolder(TestingCommons.defaultMultistreams()) def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) def up3 = new EthereumPosRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) @@ -53,7 +53,7 @@ class CurrentMultistreamHolderSpec extends Specification { def "remove upstream"() { setup: - def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) + def current = new CurrentMultistreamHolder(TestingCommons.defaultMultistreams()) def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) def up3 = new EthereumPosRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) @@ -71,7 +71,7 @@ class CurrentMultistreamHolderSpec extends Specification { def "available after adding"() { setup: - def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) + def current = new CurrentMultistreamHolder(TestingCommons.defaultMultistreams()) def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) when: From 53e170b0af50d2366970821e826b08b8574b699b Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 16 Nov 2022 14:11:16 +0400 Subject: [PATCH 02/20] introduction of upstream update event --- build.gradle | 3 + .../config/context/MultistreamsConfig.kt | 27 ++++++- .../dshackle/startup/ConfiguredUpstreams.kt | 30 +++---- ...streamChange.kt => UpstreamChangeEvent.kt} | 2 +- .../dshackle/upstream/CallTargetsHolder.kt | 29 +++++++ .../upstream/CurrentMultistreamHolder.kt | 79 +------------------ .../dshackle/upstream/Multistream.kt | 23 +++++- .../dshackle/upstream/MultistreamHolder.kt | 2 - .../upstream/bitcoin/BitcoinMultistream.kt | 14 +--- .../upstream/ethereum/EthereumMultistream.kt | 13 +-- .../ethereum_pos/EthereumPosMultiStream.kt | 13 +-- .../dshackle/upstream/grpc/GrpcUpstreams.kt | 30 +++---- .../startup/ConfiguredUpstreamsSpec.groovy | 34 +++++--- .../test/MultistreamHolderMock.groovy | 15 +--- .../dshackle/test/TestingCommons.groovy | 14 +++- .../CurrentMultistreamHolderSpec.groovy | 21 ++--- .../dshackle/upstream/MultistreamSpec.groovy | 8 +- 17 files changed, 172 insertions(+), 185 deletions(-) rename src/main/kotlin/io/emeraldpay/dshackle/startup/{UpstreamChange.kt => UpstreamChangeEvent.kt} (98%) create mode 100644 src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt diff --git a/build.gradle b/build.gradle index 03cc3cb6..d9363198 100644 --- a/build.gradle +++ b/build.gradle @@ -289,3 +289,6 @@ detekt { tasks.withType(Detekt).configureEach { jvmTarget = "13" } + +// formats code for each build +tasks.findByName("ktlintCheck").dependsOn("ktlintFormat") diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt index 7ffdd93d..cfa80f3a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt @@ -1,6 +1,7 @@ package io.emeraldpay.dshackle.config.context import io.emeraldpay.dshackle.cache.CachesFactory +import io.emeraldpay.dshackle.upstream.CallTargetsHolder import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream @@ -13,13 +14,31 @@ import org.springframework.context.annotation.Configuration @Configuration class MultistreamsConfig { @Bean - fun allMultistreams(cachesFactory: CachesFactory): List { + fun allMultistreams( + cachesFactory: CachesFactory, + callTargetsHolder: CallTargetsHolder + ): List { return Chain.values() .mapNotNull { chain -> when (BlockchainType.from(chain)) { - BlockchainType.EVM_POS -> EthereumPosMultiStream(chain, ArrayList(), cachesFactory.getCaches(chain)) - BlockchainType.EVM_POW -> EthereumMultistream(chain, ArrayList(), cachesFactory.getCaches(chain)) - BlockchainType.BITCOIN -> BitcoinMultistream(chain, ArrayList(), cachesFactory.getCaches(chain)) + BlockchainType.EVM_POS -> EthereumPosMultiStream( + chain, + ArrayList(), + cachesFactory.getCaches(chain), + callTargetsHolder + ) + BlockchainType.EVM_POW -> EthereumMultistream( + chain, + ArrayList(), + cachesFactory.getCaches(chain), + callTargetsHolder + ) + BlockchainType.BITCOIN -> BitcoinMultistream( + chain, + ArrayList(), + cachesFactory.getCaches(chain), + callTargetsHolder + ) else -> null } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index 3a86c6ac..8fc7e036 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -21,13 +21,7 @@ import io.emeraldpay.dshackle.FileResolver import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.dshackle.upstream.BlockValidator -import io.emeraldpay.dshackle.upstream.CurrentMultistreamHolder -import io.emeraldpay.dshackle.upstream.Head -import io.emeraldpay.dshackle.upstream.HttpRpcFactory -import io.emeraldpay.dshackle.upstream.MergedHead -import io.emeraldpay.dshackle.upstream.Selector -import io.emeraldpay.dshackle.upstream.Upstream +import io.emeraldpay.dshackle.upstream.* import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinRpcHead import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinRpcUpstream import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinZMQHead @@ -50,19 +44,20 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.stereotype.Repository +import org.springframework.context.ApplicationEventPublisher +import org.springframework.stereotype.Component import java.net.URI import java.util.concurrent.atomic.AtomicInteger import java.util.function.Function import javax.annotation.PostConstruct import kotlin.math.abs -@Repository +@Component open class ConfiguredUpstreams( - @Autowired private val currentUpstreams: CurrentMultistreamHolder, - @Autowired private val fileResolver: FileResolver, - @Autowired private val config: UpstreamsConfig + private val fileResolver: FileResolver, + private val config: UpstreamsConfig, + private val callTargets: CallTargetsHolder, + private val eventPublisher: ApplicationEventPublisher ) { private val log = LoggerFactory.getLogger(ConfiguredUpstreams::class.java) @@ -115,7 +110,8 @@ open class ConfiguredUpstreams( } } upstream?.let { - currentUpstreams.update(UpstreamChange(chain, upstream, UpstreamChange.ChangeType.ADDED)) + val event = UpstreamChangeEvent(chain, upstream, UpstreamChangeEvent.ChangeType.ADDED) + eventPublisher.publishEvent(event) } } } @@ -150,7 +146,7 @@ open class ConfiguredUpstreams( fun buildMethods(config: UpstreamsConfig.Upstream<*>, chain: Chain): CallMethods { return if (config.methods != null) { ManagedCallMethods( - currentUpstreams.getDefaultMethods(chain), + callTargets.getDefaultMethods(chain), config.methods!!.enabled.map { it.name }.toSet(), config.methods!!.disabled.map { it.name }.toSet() ).also { @@ -164,7 +160,7 @@ open class ConfiguredUpstreams( } } } else { - currentUpstreams.getDefaultMethods(chain) + callTargets.getDefaultMethods(chain) } } @@ -315,7 +311,7 @@ open class ConfiguredUpstreams( .doOnNext { log.info("Chain ${it.chain} ${it.type} through gRPC at ${endpoint.host}:${endpoint.port}. With caps: ${it.upstream.getCapabilities()}") } - .subscribe(currentUpstreams::update) + .subscribe(eventPublisher::publishEvent) } private fun buildHttpFactory(conn: UpstreamsConfig.RpcConnection, urls: ArrayList? = null): HttpRpcFactory? { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChange.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt similarity index 98% rename from src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChange.kt rename to src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt index 213e55a1..34bcc8bf 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChange.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt @@ -24,7 +24,7 @@ import io.emeraldpay.grpc.Chain /** * An update event to the list of currently available upstreams. */ -class UpstreamChange( +class UpstreamChangeEvent( /** * Target blockchain */ diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt new file mode 100644 index 00000000..2ad03f39 --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt @@ -0,0 +1,29 @@ +package io.emeraldpay.dshackle.upstream + +import io.emeraldpay.dshackle.upstream.calls.CallMethods +import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods +import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods +import io.emeraldpay.grpc.BlockchainType +import io.emeraldpay.grpc.Chain +import org.springframework.stereotype.Component +import java.util.HashMap + +@Component +class CallTargetsHolder { + private val callTargets = HashMap() + + fun getDefaultMethods(chain: Chain): CallMethods { + return callTargets[chain] ?: return setupDefaultMethods(chain) + } + + private fun setupDefaultMethods(chain: Chain): CallMethods { + val created = when (BlockchainType.from(chain)) { + BlockchainType.EVM_POW -> DefaultEthereumMethods(chain) + BlockchainType.BITCOIN -> DefaultBitcoinMethods() + BlockchainType.EVM_POS -> DefaultEthereumMethods(chain) + else -> throw IllegalStateException("Unsupported chain: $chain") + } + callTargets[chain] = created + return created + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index 2de935f6..0402c727 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -16,15 +16,6 @@ */ package io.emeraldpay.dshackle.upstream -import io.emeraldpay.dshackle.cache.CachesEnabled -import io.emeraldpay.dshackle.startup.UpstreamChange -import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinUpstream -import io.emeraldpay.dshackle.upstream.calls.CallMethods -import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods -import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods -import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream -import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.stereotype.Component @@ -49,61 +40,8 @@ open class CurrentMultistreamHolder( private val chainsBus = Sinks.many() .multicast() .directBestEffort() - private val callTargets = HashMap() private val updateLock = ReentrantLock() - fun update(change: UpstreamChange) { - updateLock.withLock { - log.debug("Upstream update: ${change.type} ${change.chain} via ${change.upstream.getId()}") - val chain = change.chain - try { - when (BlockchainType.from(chain)) { - BlockchainType.EVM_POW -> { - val up = change.upstream.cast(EthereumUpstream::class.java) - val current = chainMapping.getValue(chain) - processUpdate(change, up, current) - } - - BlockchainType.EVM_POS -> { - val up = change.upstream.cast(EthereumPosUpstream::class.java) - val current = chainMapping.getValue(chain) - processUpdate(change, up, current) - } - - BlockchainType.BITCOIN -> { - val up = change.upstream.cast(BitcoinUpstream::class.java) - val current = chainMapping.getValue(chain) - processUpdate(change, up, current) - } - - else -> { - log.error("Update for unsupported chain: $chain") - } - } - } catch (e: Throwable) { - log.error("Failed to update upstream", e) - } - } - } - - fun processUpdate(change: UpstreamChange, up: Upstream, current: Multistream) { - val chain = change.chain - if (change.type == UpstreamChange.ChangeType.REMOVED) { - current.removeUpstream(up.getId()) - log.info("Upstream ${change.upstream.getId()} with chain $chain has been removed") - } else { - if (up is CachesEnabled) { - up.setCaches(current.caches) - } - current.addUpstream(up) - - if (!callTargets.containsKey(chain)) { - setupDefaultMethods(chain) - } - log.info("Upstream ${change.upstream.getId()} with chain $chain has been added") - } - } - override fun getUpstream(chain: Chain): Multistream? { return chainMapping[chain] } @@ -122,23 +60,8 @@ open class CurrentMultistreamHolder( ) } - override fun getDefaultMethods(chain: Chain): CallMethods { - return callTargets[chain] ?: return setupDefaultMethods(chain) - } - - fun setupDefaultMethods(chain: Chain): CallMethods { - val created = when (BlockchainType.from(chain)) { - BlockchainType.EVM_POW -> DefaultEthereumMethods(chain) - BlockchainType.BITCOIN -> DefaultBitcoinMethods() - BlockchainType.EVM_POS -> DefaultEthereumMethods(chain) - else -> throw IllegalStateException("Unsupported chain: $chain") - } - callTargets[chain] = created - return created - } - override fun isAvailable(chain: Chain): Boolean { - return chainMapping.containsKey(chain) && callTargets.containsKey(chain) + return chainMapping.getValue(chain).isAvailable() } @PreDestroy diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index c04dd9e0..80e19481 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -17,8 +17,10 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.cache.Caches +import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader +import io.emeraldpay.dshackle.startup.UpstreamChangeEvent import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest @@ -30,6 +32,7 @@ import org.apache.commons.collections4.Factory import org.apache.commons.collections4.FunctorException import org.slf4j.LoggerFactory import org.springframework.context.Lifecycle +import org.springframework.context.event.EventListener import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -48,7 +51,8 @@ abstract class Multistream( val chain: Chain, private val upstreams: MutableList, val caches: Caches, - val postprocessor: RequestPostprocessor + val postprocessor: RequestPostprocessor, + val callTargetsHolder: CallTargetsHolder ) : Upstream, Lifecycle { companion object { @@ -316,6 +320,23 @@ abstract class Multistream( log.info("State of ${chain.chainCode}: height=${height ?: '?'}, status=[$statuses], lag=[$lag], weak=[$weak]") } + @EventListener + fun onUpstreamChange(event: UpstreamChangeEvent) { + val chain = event.chain + if (this.chain == chain) { + if (event.type == UpstreamChangeEvent.ChangeType.REMOVED) { + removeUpstream(event.upstream.getId()) + log.info("Upstream ${event.upstream.getId()} with chain $chain has been removed") + } else { + if (event.upstream is CachesEnabled) { + event.upstream.setCaches(caches) + } + addUpstream(event.upstream) + log.info("Upstream ${event.upstream.getId()} with chain $chain has been added") + } + } + } + // -------------------------------------------------------------------------------------------------------- class UpstreamStatus(val upstream: Upstream, val status: UpstreamAvailability, val ts: Instant = Instant.now()) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt index 852ffdee..6e1c4ab0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt @@ -16,7 +16,6 @@ */ package io.emeraldpay.dshackle.upstream -import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.grpc.Chain import reactor.core.publisher.Flux @@ -27,6 +26,5 @@ interface MultistreamHolder { fun getUpstream(chain: Chain): Multistream? fun getAvailable(): List fun observeChains(): Flux - fun getDefaultMethods(chain: Chain): CallMethods fun isAvailable(chain: Chain): Boolean } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt index d72a3fb5..14ebfda0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt @@ -18,14 +18,7 @@ package io.emeraldpay.dshackle.upstream.bitcoin import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.dshackle.upstream.ChainFees -import io.emeraldpay.dshackle.upstream.EmptyHead -import io.emeraldpay.dshackle.upstream.Head -import io.emeraldpay.dshackle.upstream.MergedHead -import io.emeraldpay.dshackle.upstream.Multistream -import io.emeraldpay.dshackle.upstream.RequestPostprocessor -import io.emeraldpay.dshackle.upstream.Selector -import io.emeraldpay.dshackle.upstream.Upstream +import io.emeraldpay.dshackle.upstream.* import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest @@ -39,8 +32,9 @@ import reactor.core.publisher.Mono open class BitcoinMultistream( chain: Chain, private val sourceUpstreams: MutableList, - caches: Caches -) : Multistream(chain, sourceUpstreams as MutableList, caches, RequestPostprocessor.Empty()), Lifecycle { + caches: Caches, + callTargetsHolder: CallTargetsHolder +) : Multistream(chain, sourceUpstreams as MutableList, caches, RequestPostprocessor.Empty(), callTargetsHolder), Lifecycle { companion object { private val log = LoggerFactory.getLogger(BitcoinMultistream::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt index 259e88a6..e2fb57f5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt @@ -20,13 +20,7 @@ import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.dshackle.upstream.ChainFees -import io.emeraldpay.dshackle.upstream.EmptyHead -import io.emeraldpay.dshackle.upstream.Head -import io.emeraldpay.dshackle.upstream.MergedHead -import io.emeraldpay.dshackle.upstream.Multistream -import io.emeraldpay.dshackle.upstream.Selector -import io.emeraldpay.dshackle.upstream.Upstream +import io.emeraldpay.dshackle.upstream.* import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest @@ -42,8 +36,9 @@ import reactor.core.publisher.Mono open class EthereumMultistream( chain: Chain, val upstreams: MutableList, - caches: Caches -) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches)), EthereumLikeMultistream { + caches: Caches, + callTargetsHolder: CallTargetsHolder +) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches), callTargetsHolder), EthereumLikeMultistream { companion object { private val log = LoggerFactory.getLogger(EthereumMultistream::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt index cd872db7..3e93a81a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt @@ -20,13 +20,7 @@ import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.dshackle.upstream.ChainFees -import io.emeraldpay.dshackle.upstream.EmptyHead -import io.emeraldpay.dshackle.upstream.Head -import io.emeraldpay.dshackle.upstream.MergedHead -import io.emeraldpay.dshackle.upstream.Multistream -import io.emeraldpay.dshackle.upstream.Selector -import io.emeraldpay.dshackle.upstream.Upstream +import io.emeraldpay.dshackle.upstream.* import io.emeraldpay.dshackle.upstream.forkchoice.PriorityForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest @@ -42,8 +36,9 @@ import reactor.core.publisher.Mono open class EthereumPosMultiStream( chain: Chain, val upstreams: MutableList, - caches: Caches -) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches)), EthereumLikeMultistream { + caches: Caches, + callTargetsHolder: CallTargetsHolder +) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches), callTargetsHolder), EthereumLikeMultistream { companion object { private val log = LoggerFactory.getLogger(EthereumPosMultiStream::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt index c92fd624..f74cb62c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.FileResolver import io.emeraldpay.dshackle.config.AuthConfig import io.emeraldpay.dshackle.config.UpstreamsConfig -import io.emeraldpay.dshackle.startup.UpstreamChange +import io.emeraldpay.dshackle.startup.UpstreamChangeEvent import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient @@ -69,7 +69,7 @@ class GrpcUpstreams( private val known = HashMap() private val lock = ReentrantLock() - fun start(): Flux { + fun start(): Flux { val channel: ManagedChannelBuilder<*> = if (auth != null && StringUtils.isNotEmpty(auth.ca)) { NettyChannelBuilder.forAddress(host, port) // some messages are very large. many of them in megabytes, some even in gigabytes (ex. ETH Traces) @@ -122,7 +122,7 @@ class GrpcUpstreams( return updates } - fun processDescription(value: BlockchainOuterClass.DescribeResponse): Flux { + fun processDescription(value: BlockchainOuterClass.DescribeResponse): Flux { val current = value.chainsList.filter { Chain.byId(it.chain.number) != Chain.UNSPECIFIED }.mapNotNull { chainDetails -> @@ -138,14 +138,14 @@ class GrpcUpstreams( } val added = current.filter { - it.type == UpstreamChange.ChangeType.ADDED + it.type == UpstreamChangeEvent.ChangeType.ADDED } val removed = known.filterNot { kv -> val stillCurrent = current.any { c -> c.chain == kv.key } stillCurrent }.map { - UpstreamChange(it.key, known.remove(it.key)!!, UpstreamChange.ChangeType.REMOVED) + UpstreamChangeEvent(it.key, known.remove(it.key)!!, UpstreamChangeEvent.ChangeType.REMOVED) } return Flux.fromIterable(removed + added) } @@ -172,7 +172,7 @@ class GrpcUpstreams( return sslContext.build() } - fun getOrCreate(chain: Chain): UpstreamChange { + fun getOrCreate(chain: Chain): UpstreamChangeEvent { val metricsTags = listOf( Tag.of("upstream", id), Tag.of("chain", chain.chainCode) @@ -202,7 +202,7 @@ class GrpcUpstreams( } } - fun getOrCreateEthereum(chain: Chain, metrics: RpcMetrics): UpstreamChange { + fun getOrCreateEthereum(chain: Chain, metrics: RpcMetrics): UpstreamChangeEvent { lock.withLock { val current = known[chain] return if (current == null) { @@ -211,14 +211,14 @@ class GrpcUpstreams( created.timeout = this.timeout known[chain] = created created.start() - UpstreamChange(chain, created, UpstreamChange.ChangeType.ADDED) + UpstreamChangeEvent(chain, created, UpstreamChangeEvent.ChangeType.ADDED) } else { - UpstreamChange(chain, current, UpstreamChange.ChangeType.REVALIDATED) + UpstreamChangeEvent(chain, current, UpstreamChangeEvent.ChangeType.REVALIDATED) } } } - fun getOrCreateEthereumPos(chain: Chain, metrics: RpcMetrics): UpstreamChange { + fun getOrCreateEthereumPos(chain: Chain, metrics: RpcMetrics): UpstreamChangeEvent { lock.withLock { val current = known[chain] return if (current == null) { @@ -227,14 +227,14 @@ class GrpcUpstreams( created.timeout = this.timeout known[chain] = created created.start() - UpstreamChange(chain, created, UpstreamChange.ChangeType.ADDED) + UpstreamChangeEvent(chain, created, UpstreamChangeEvent.ChangeType.ADDED) } else { - UpstreamChange(chain, current, UpstreamChange.ChangeType.REVALIDATED) + UpstreamChangeEvent(chain, current, UpstreamChangeEvent.ChangeType.REVALIDATED) } } } - fun getOrCreateBitcoin(chain: Chain, metrics: RpcMetrics): UpstreamChange { + fun getOrCreateBitcoin(chain: Chain, metrics: RpcMetrics): UpstreamChangeEvent { lock.withLock { val current = known[chain] return if (current == null) { @@ -243,9 +243,9 @@ class GrpcUpstreams( created.timeout = this.timeout known[chain] = created created.start() - UpstreamChange(chain, created, UpstreamChange.ChangeType.ADDED) + UpstreamChangeEvent(chain, created, UpstreamChangeEvent.ChangeType.ADDED) } else { - UpstreamChange(chain, current, UpstreamChange.ChangeType.REVALIDATED) + UpstreamChangeEvent(chain, current, UpstreamChangeEvent.ChangeType.REVALIDATED) } } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy index 4e6f6eea..f799729d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy @@ -4,21 +4,24 @@ import io.emeraldpay.dshackle.FileResolver import io.emeraldpay.dshackle.cache.CachesFactory import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.quorum.NonEmptyQuorum +import io.emeraldpay.dshackle.upstream.CallTargetsHolder import io.emeraldpay.dshackle.upstream.CurrentMultistreamHolder import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods import io.emeraldpay.grpc.Chain +import org.springframework.context.ApplicationEventPublisher import spock.lang.Specification class ConfiguredUpstreamsSpec extends Specification { def "Applied quorum to extra methods"() { setup: - def currentUpstreams = Mock(CurrentMultistreamHolder) { - _ * getDefaultMethods(Chain.ETHEREUM) >> new DefaultEthereumMethods(Chain.ETHEREUM) - } + def callTargetsHolder = new CallTargetsHolder() def configurer = new ConfiguredUpstreams( - currentUpstreams, Stub(FileResolver), Stub(UpstreamsConfig) + Stub(FileResolver), + Stub(UpstreamsConfig), + callTargetsHolder, + Mock(ApplicationEventPublisher) ) def methods = new UpstreamsConfig.Methods( [ @@ -38,11 +41,12 @@ class ConfiguredUpstreamsSpec extends Specification { def "Got static response from extra methods"() { setup: - def currentUpstreams = Mock(CurrentMultistreamHolder) { - _ * getDefaultMethods(Chain.ETHEREUM) >> new DefaultEthereumMethods(Chain.ETHEREUM) - } + def callTargetsHolder = new CallTargetsHolder() def configurer = new ConfiguredUpstreams( - currentUpstreams, Stub(FileResolver), Stub(UpstreamsConfig) + Stub(FileResolver), + Stub(UpstreamsConfig), + callTargetsHolder, + Mock(ApplicationEventPublisher) ) def methods = new UpstreamsConfig.Methods( [ @@ -61,7 +65,12 @@ class ConfiguredUpstreamsSpec extends Specification { def "Calculate node-id"() { setup: - def configurer = new ConfiguredUpstreams(Stub(CurrentMultistreamHolder), Stub(FileResolver), Stub(UpstreamsConfig) + def callTargetsHolder = new CallTargetsHolder() + def configurer = new ConfiguredUpstreams( + Stub(FileResolver), + Stub(UpstreamsConfig), + callTargetsHolder, + Mock(ApplicationEventPublisher) ) expect: configurer.getHash(node, src) == expected @@ -75,7 +84,12 @@ class ConfiguredUpstreamsSpec extends Specification { def "Calculate node-id conflicting results"() { setup: - def configurer = new ConfiguredUpstreams(Stub(CurrentMultistreamHolder), Stub(FileResolver), Stub(UpstreamsConfig) + def callTargetsHolder = new CallTargetsHolder() + def configurer = new ConfiguredUpstreams( + Stub(FileResolver), + Stub(UpstreamsConfig), + callTargetsHolder, + Mock(ApplicationEventPublisher) ) when: def h1 = configurer.getHash(null, "hohoho") diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy index 660b7611..9e34c546 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy @@ -50,7 +50,7 @@ class MultistreamHolderMock implements MultistreamHolder { if (up instanceof EthereumPosMultiStream) { upstreams[chain] = up } else if (up instanceof EthereumPosRpcUpstream) { - upstreams[chain] = new EthereumPosMultiStream(chain, [up as EthereumPosRpcUpstream], Caches.default()) + upstreams[chain] = new EthereumPosMultiStream(chain, [up as EthereumPosRpcUpstream], Caches.default(), TestingCommons.callTargetsHolder) } else { throw new IllegalArgumentException("Unsupported upstream type ${up.class}") } @@ -59,7 +59,7 @@ class MultistreamHolderMock implements MultistreamHolder { if (up instanceof BitcoinMultistream) { upstreams[chain] = up } else if (up instanceof BitcoinRpcUpstream) { - upstreams[chain] = new BitcoinMultistream(chain, [up as BitcoinRpcUpstream], Caches.default()) + upstreams[chain] = new BitcoinMultistream(chain, [up as BitcoinRpcUpstream], Caches.default(), TestingCommons.callTargetsHolder) } else { throw new IllegalArgumentException("Unsupported upstream type ${up.class}") } @@ -86,15 +86,6 @@ class MultistreamHolderMock implements MultistreamHolder { return Flux.fromIterable(getAvailable()) } - @Override - DefaultEthereumMethods getDefaultMethods(@NotNull Chain chain) { - if (target[chain] == null) { - DefaultEthereumMethods targets = new DefaultEthereumMethods(chain) - target[chain] = targets - } - return target[chain] - } - @Override boolean isAvailable(@NotNull Chain chain) { return upstreams.containsKey(chain) @@ -107,7 +98,7 @@ class MultistreamHolderMock implements MultistreamHolder { Head customHead = null EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams, @NotNull Caches caches) { - super(chain, upstreams, caches) + super(chain, upstreams, caches, TestingCommons.callTargetsHolder) } EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams) { diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index 6ad08167..f2c640d7 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -24,8 +24,10 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.reader.EmptyReader import io.emeraldpay.dshackle.reader.Reader +import io.emeraldpay.dshackle.upstream.CallTargetsHolder import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods +import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest @@ -78,7 +80,7 @@ class TestingCommons { } static Multistream multistream(EthereumPosRpcUpstreamMock up) { - return new EthereumPosMultiStream(Chain.ETHEREUM, [up], Caches.default()).tap { + return new EthereumPosMultiStream(Chain.ETHEREUM, [up], Caches.default(), callTargetsHolder).tap { start() } } @@ -94,12 +96,16 @@ class TestingCommons { static List defaultMultistreams() { return [ multistreamWithoutUpstreams(Chain.ETHEREUM), - multistreamWithoutUpstreams(Chain.ETHEREUM_CLASSIC) + multistreamClassicWithoutUpstreams(Chain.ETHEREUM_CLASSIC) ] } static Multistream multistreamWithoutUpstreams(Chain chain) { - return new EthereumPosMultiStream(chain, [], emptyCaches().getCaches(chain)) + return new EthereumPosMultiStream(chain, [], emptyCaches().getCaches(chain), callTargetsHolder) + } + + static Multistream multistreamClassicWithoutUpstreams(Chain chain) { + return new EthereumMultistream(chain, [], emptyCaches().getCaches(chain), callTargetsHolder) } static FileResolver fileResolver() { @@ -138,4 +144,6 @@ class TestingCommons { } static MeterRegistry meterRegistry = new LoggingMeterRegistry() + + static CallTargetsHolder callTargetsHolder = new CallTargetsHolder() } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy index 0ec23584..4e488e9d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.upstream -import io.emeraldpay.dshackle.startup.UpstreamChange +import io.emeraldpay.dshackle.startup.UpstreamChangeEvent import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons @@ -29,7 +29,7 @@ class CurrentMultistreamHolderSpec extends Specification { def current = new CurrentMultistreamHolder(TestingCommons.defaultMultistreams()) def up = new EthereumPosRpcUpstreamMock("test", Chain.ETHEREUM, TestingCommons.api()) when: - current.update(new UpstreamChange(Chain.ETHEREUM, up, UpstreamChange.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up, UpstreamChangeEvent.ChangeType.ADDED)) then: current.getAvailable() == [Chain.ETHEREUM] current.getUpstream(Chain.ETHEREUM).getAll()[0] == up @@ -42,9 +42,10 @@ class CurrentMultistreamHolderSpec extends Specification { def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) def up3 = new EthereumPosRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) when: - current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED)) - current.update(new UpstreamChange(Chain.ETHEREUM_CLASSIC, up2, UpstreamChange.ChangeType.ADDED)) - current.update(new UpstreamChange(Chain.ETHEREUM, up3, UpstreamChange.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up1, UpstreamChangeEvent.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM_CLASSIC).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM_CLASSIC, up2, UpstreamChangeEvent.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up3, UpstreamChangeEvent.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM_CLASSIC).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up3, UpstreamChangeEvent.ChangeType.ADDED)) then: current.getAvailable().toSet() == [Chain.ETHEREUM, Chain.ETHEREUM_CLASSIC].toSet() current.getUpstream(Chain.ETHEREUM).getAll().toSet() == [up1, up3].toSet() @@ -59,10 +60,10 @@ class CurrentMultistreamHolderSpec extends Specification { def up3 = new EthereumPosRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) def up1_del = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) when: - current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED)) - current.update(new UpstreamChange(Chain.ETHEREUM_CLASSIC, up2, UpstreamChange.ChangeType.ADDED)) - current.update(new UpstreamChange(Chain.ETHEREUM, up3, UpstreamChange.ChangeType.ADDED)) - current.update(new UpstreamChange(Chain.ETHEREUM, up1_del, UpstreamChange.ChangeType.REMOVED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up1, UpstreamChangeEvent.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM_CLASSIC).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM_CLASSIC, up2, UpstreamChangeEvent.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up3, UpstreamChangeEvent.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up1_del, UpstreamChangeEvent.ChangeType.REMOVED)) then: current.getAvailable().toSet() == [Chain.ETHEREUM, Chain.ETHEREUM_CLASSIC].toSet() current.getUpstream(Chain.ETHEREUM).getAll().toSet() == [up3].toSet() @@ -80,7 +81,7 @@ class CurrentMultistreamHolderSpec extends Specification { !act when: - current.update(new UpstreamChange(Chain.ETHEREUM, up1, UpstreamChange.ChangeType.ADDED)) + current.getUpstream(Chain.ETHEREUM).onUpstreamChange(new UpstreamChangeEvent(Chain.ETHEREUM, up1, UpstreamChangeEvent.ChangeType.ADDED)) act = current.isAvailable(Chain.ETHEREUM) then: diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy index 8a28f4b3..b432bcb8 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy @@ -50,7 +50,7 @@ class MultistreamSpec extends Specification { setup: def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test1", "eth_test2"])) def up2 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test2", "eth_test3"])) - def aggr = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2], Caches.default()) + def aggr = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2], Caches.default(), TestingCommons.callTargetsHolder) when: aggr.onUpstreamsUpdated() def act = aggr.getMethods() @@ -206,7 +206,7 @@ class MultistreamSpec extends Specification { def up1 = TestingCommons.upstream("test-1", "internal") def up2 = TestingCommons.upstream("test-2", "external") def up3 = TestingCommons.upstream("test-3", "external") - def multistream = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2, up3], Caches.default()) + def multistream = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2, up3], Caches.default(), TestingCommons.callTargetsHolder) expect: multistream.getHead(new Selector.LabelMatcher("provider", ["internal"])).is(up1.ethereumHeadMock) @@ -345,7 +345,7 @@ class MultistreamSpec extends Specification { class TestMultistream extends Multistream { TestMultistream(List upstreams, @NotNull RequestPostprocessor postprocessor) { - super(Chain.ETHEREUM, upstreams, Caches.default(), postprocessor) + super(Chain.ETHEREUM, upstreams, Caches.default(), postprocessor, TestingCommons.callTargetsHolder) } @Override @@ -386,7 +386,7 @@ class MultistreamSpec extends Specification { class TestEthereumPosMultistream extends EthereumPosMultiStream { TestEthereumPosMultistream(@NotNull Chain chain, @NotNull List upstreams, @NotNull Caches caches) { - super(chain, upstreams, caches) + super(chain, upstreams, caches, TestingCommons.callTargetsHolder) } @Override From eaa68d606bca0f0f3ea9734e647041afa65d0214 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 16 Nov 2022 15:26:02 +0400 Subject: [PATCH 03/20] fix after tests --- .../emeraldpay/dshackle/config/context/MultistreamsConfig.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt index cfa80f3a..d8204b87 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt @@ -12,13 +12,14 @@ import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @Configuration -class MultistreamsConfig { +open class MultistreamsConfig { @Bean - fun allMultistreams( + open fun allMultistreams( cachesFactory: CachesFactory, callTargetsHolder: CallTargetsHolder ): List { return Chain.values() + .filterNot { it == Chain.UNSPECIFIED } .mapNotNull { chain -> when (BlockchainType.from(chain)) { BlockchainType.EVM_POS -> EthereumPosMultiStream( From d997d148c4dbb8bba04fcac706c02ff65cc66afe Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 16 Nov 2022 17:00:07 +0400 Subject: [PATCH 04/20] fixing startup --- .../kotlin/io/emeraldpay/dshackle/Starter.kt | 2 - .../config/context/MultistreamsConfig.kt | 69 ++++++++++++++----- .../io/emeraldpay/dshackle/rpc/NativeCall.kt | 34 ++++----- .../dshackle/rpc/TrackBitcoinAddress.kt | 17 +++-- .../dshackle/startup/ConfiguredUpstreams.kt | 9 +-- .../upstream/CurrentMultistreamHolder.kt | 11 --- .../emeraldpay/dshackle/upstream/Lifecycle.kt | 7 ++ .../dshackle/upstream/MergedHead.kt | 5 +- .../dshackle/upstream/Multistream.kt | 20 ++++-- .../dshackle/upstream/MultistreamHolder.kt | 2 - .../upstream/bitcoin/BitcoinMultistream.kt | 9 ++- .../upstream/bitcoin/BitcoinReader.kt | 4 +- .../upstream/bitcoin/BitcoinRpcHead.kt | 2 +- .../upstream/bitcoin/BitcoinRpcUpstream.kt | 6 +- .../upstream/bitcoin/BitcoinZMQHead.kt | 4 +- .../upstream/bitcoin/CachingMempoolData.kt | 2 +- .../dshackle/upstream/bitcoin/ZMQServer.kt | 2 +- .../upstream/ethereum/EthereumMultistream.kt | 9 ++- .../upstream/ethereum/EthereumReader.kt | 4 +- .../upstream/ethereum/EthereumRpcHead.kt | 2 +- .../upstream/ethereum/EthereumRpcUpstream.kt | 2 +- .../upstream/ethereum/EthereumWsHead.kt | 2 +- .../ethereum/connectors/EthereumConnector.kt | 2 +- .../connectors/EthereumRpcConnector.kt | 4 +- .../connectors/EthereumWsConnector.kt | 2 +- .../ethereum_pos/EthereumPosMultiStream.kt | 9 ++- .../ethereum_pos/EthereumPosRpcUpstream.kt | 4 +- .../upstream/grpc/BitcoinGrpcUpstream.kt | 2 +- .../upstream/grpc/EthereumGrpcUpstream.kt | 2 +- .../upstream/grpc/EthereumPosGrpcUpstream.kt | 2 +- .../dshackle/upstream/grpc/GrpcHead.kt | 4 +- src/main/resources/log4j2.xml | 2 +- .../dshackle/rpc/NativeCallSpec.groovy | 4 +- .../test/MultistreamHolderMock.groovy | 11 +-- .../dshackle/test/TestingCommons.groovy | 7 +- .../dshackle/upstream/MergedHeadSpec.groovy | 2 +- .../dshackle/upstream/MultistreamSpec.groovy | 8 +-- 37 files changed, 154 insertions(+), 135 deletions(-) create mode 100644 src/main/kotlin/io/emeraldpay/dshackle/upstream/Lifecycle.kt diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt b/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt index 807b399b..525eda35 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Starter.kt @@ -20,12 +20,10 @@ import org.slf4j.LoggerFactory import org.springframework.boot.ResourceBanner import org.springframework.boot.SpringApplication import org.springframework.boot.autoconfigure.SpringBootApplication -import org.springframework.context.annotation.Import import org.springframework.core.io.ClassPathResource import org.springframework.core.io.support.ResourcePropertySource @SpringBootApplication(scanBasePackages = ["io.emeraldpay.dshackle"]) -@Import(Config::class) open class Starter private val log = LoggerFactory.getLogger(Starter::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt index d8204b87..3329f93e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt @@ -8,11 +8,12 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain +import org.springframework.beans.factory.config.ConfigurableListableBeanFactory import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration @Configuration -open class MultistreamsConfig { +open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) { @Bean open fun allMultistreams( cachesFactory: CachesFactory, @@ -22,26 +23,56 @@ open class MultistreamsConfig { .filterNot { it == Chain.UNSPECIFIED } .mapNotNull { chain -> when (BlockchainType.from(chain)) { - BlockchainType.EVM_POS -> EthereumPosMultiStream( - chain, - ArrayList(), - cachesFactory.getCaches(chain), - callTargetsHolder - ) - BlockchainType.EVM_POW -> EthereumMultistream( - chain, - ArrayList(), - cachesFactory.getCaches(chain), - callTargetsHolder - ) - BlockchainType.BITCOIN -> BitcoinMultistream( - chain, - ArrayList(), - cachesFactory.getCaches(chain), - callTargetsHolder - ) + BlockchainType.EVM_POS -> ethereumPosMultistream(chain, cachesFactory) + BlockchainType.EVM_POW -> ethereumMultistream(chain, cachesFactory) + BlockchainType.BITCOIN -> bitcoinMultistream(chain, cachesFactory) else -> null } } } + + private fun ethereumMultistream( + chain: Chain, + cachesFactory: CachesFactory + ): EthereumMultistream { + val name = "multi-ethereum-$chain" + + return EthereumMultistream( + chain, + ArrayList(), + cachesFactory.getCaches(chain) + ).also { register(it, name) } + } + + open fun ethereumPosMultistream( + chain: Chain, + cachesFactory: CachesFactory + ): EthereumPosMultiStream { + val name = "multi-ethereum-pos-$chain" + + return EthereumPosMultiStream( + chain, + ArrayList(), + cachesFactory.getCaches(chain) + ).also { register(it, name) } + } + + open fun bitcoinMultistream( + chain: Chain, + cachesFactory: CachesFactory + ): BitcoinMultistream { + val name = "multi-bitcoin-$chain" + + return BitcoinMultistream( + chain, + ArrayList(), + cachesFactory.getCaches(chain) + ).also { register(it, name) } + } + + private fun register(bean: Any, name: String) { + beanFactory.initializeBean(bean, name) + beanFactory.autowireBean(bean) + this.beanFactory.registerSingleton(name, bean) + } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 956b187d..93926399 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -26,11 +26,10 @@ import io.emeraldpay.dshackle.quorum.NotLaggingQuorum import io.emeraldpay.dshackle.quorum.QuorumReaderFactory import io.emeraldpay.dshackle.quorum.QuorumRpcReader import io.emeraldpay.dshackle.startup.ConfiguredUpstreams -import io.emeraldpay.dshackle.upstream.ApiSource -import io.emeraldpay.dshackle.upstream.Multistream -import io.emeraldpay.dshackle.upstream.MultistreamHolder -import io.emeraldpay.dshackle.upstream.Selector +import io.emeraldpay.dshackle.startup.UpstreamChangeEvent +import io.emeraldpay.dshackle.upstream.* import io.emeraldpay.dshackle.upstream.calls.EthereumCallSelector +import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcError @@ -45,7 +44,7 @@ import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Metrics import org.apache.commons.lang3.StringUtils import org.slf4j.LoggerFactory -import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.event.EventListener import org.springframework.stereotype.Service import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -55,9 +54,9 @@ import java.util.concurrent.atomic.AtomicInteger @Service open class NativeCall( - @Autowired private val multistreamHolder: MultistreamHolder, - @Autowired private val configuredUpstreams: ConfiguredUpstreams, - @Autowired private val signer: ResponseSigner + private val multistreamHolder: MultistreamHolder, + private val configuredUpstreams: ConfiguredUpstreams, + private val signer: ResponseSigner ) { private val log = LoggerFactory.getLogger(NativeCall::class.java) @@ -66,18 +65,19 @@ open class NativeCall( var quorumReaderFactory: QuorumReaderFactory = QuorumReaderFactory.default() private val ethereumCallSelectors = EnumMap(Chain::class.java) - init { - val casting = mapOf( + companion object { + val casting: Map> = mapOf( BlockchainType.EVM_POS to EthereumPosMultiStream::class.java, - BlockchainType.EVM_POW to EthereumMultistream::class.java, + BlockchainType.EVM_POW to EthereumMultistream::class.java ) + } - multistreamHolder.observeChains().subscribe { chain -> - casting[BlockchainType.from(chain)]?.let { cast -> - multistreamHolder.getUpstream(chain)?.let { up -> - val reader = up.cast(cast).getReader() - ethereumCallSelectors.putIfAbsent(chain, EthereumCallSelector(reader.heightByHash())) - } + @EventListener + fun onUpstreamChangeEvent(event: UpstreamChangeEvent) { + casting[BlockchainType.from(event.chain)]?.let { cast -> + multistreamHolder.getUpstream(event.chain)?.let { up -> + val reader = up.cast(cast).getReader() + ethereumCallSelectors.putIfAbsent(event.chain, EthereumCallSelector(reader.heightByHash())) } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt index 0536d655..d64b493c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt @@ -20,6 +20,7 @@ import io.emeraldpay.api.proto.Common import io.emeraldpay.api.proto.ReactorBlockchainGrpc import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.SilentException +import io.emeraldpay.dshackle.startup.UpstreamChangeEvent import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.Selector @@ -33,12 +34,12 @@ import org.bitcoinj.params.MainNetParams import org.bitcoinj.params.TestNet3Params import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired +import org.springframework.context.event.EventListener import org.springframework.stereotype.Service import reactor.core.publisher.Flux import reactor.core.publisher.Mono import java.math.BigInteger import java.util.concurrent.ConcurrentHashMap -import javax.annotation.PostConstruct @Service class TrackBitcoinAddress( @@ -67,15 +68,13 @@ class TrackBitcoinAddress( Selector.CapabilityMatcher(Capability.BALANCE) ) - @PostConstruct - fun listenChains() { - multistreamHolder.observeChains().subscribe { chain -> - multistreamHolder.getUpstream(chain)?.let { mup -> - val available = mup.getAll().any { up -> - !up.isGrpc() && up.getCapabilities().contains(Capability.BALANCE) - } - setBalanceAvailability(chain, available) + @EventListener + fun onUpstreamChangeEvent(event: UpstreamChangeEvent) { + multistreamHolder.getUpstream(event.chain)?.let { mup -> + val available = mup.getAll().any { up -> + !up.isGrpc() && up.getCapabilities().contains(Capability.BALANCE) } + setBalanceAvailability(event.chain, available) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index 8fc7e036..b66a125a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -44,12 +44,13 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory +import org.springframework.boot.ApplicationArguments +import org.springframework.boot.ApplicationRunner import org.springframework.context.ApplicationEventPublisher import org.springframework.stereotype.Component import java.net.URI import java.util.concurrent.atomic.AtomicInteger import java.util.function.Function -import javax.annotation.PostConstruct import kotlin.math.abs @Component @@ -58,15 +59,14 @@ open class ConfiguredUpstreams( private val config: UpstreamsConfig, private val callTargets: CallTargetsHolder, private val eventPublisher: ApplicationEventPublisher -) { +) : ApplicationRunner { private val log = LoggerFactory.getLogger(ConfiguredUpstreams::class.java) private var seq = AtomicInteger(0) private val hashes: MutableMap = HashMap() - @PostConstruct - fun start() { + override fun run(args: ApplicationArguments) { log.debug("Starting upstreams") val defaultOptions = buildDefaultOptions(config) config.upstreams.forEach { up -> @@ -111,6 +111,7 @@ open class ConfiguredUpstreams( } upstream?.let { val event = UpstreamChangeEvent(chain, upstream, UpstreamChangeEvent.ChangeType.ADDED) + log.error("first !!!! Upstream ${event.upstream.getId()} with chain $chain has been added") eventPublisher.publishEvent(event) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index 0402c727..b4865951 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -19,7 +19,6 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.stereotype.Component -import reactor.core.publisher.Flux import reactor.core.publisher.Sinks import java.util.* import java.util.concurrent.ConcurrentHashMap @@ -37,9 +36,6 @@ open class CurrentMultistreamHolder( private val chainMapping = ConcurrentHashMap().apply { multistreams.forEach { this[it.chain] = it } } - private val chainsBus = Sinks.many() - .multicast() - .directBestEffort() private val updateLock = ReentrantLock() override fun getUpstream(chain: Chain): Multistream? { @@ -53,13 +49,6 @@ open class CurrentMultistreamHolder( .toList() } - override fun observeChains(): Flux { - return Flux.concat( - Flux.fromIterable(getAvailable()), - chainsBus.asFlux() - ) - } - override fun isAvailable(chain: Chain): Boolean { return chainMapping.getValue(chain).isAvailable() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Lifecycle.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Lifecycle.kt new file mode 100644 index 00000000..ff7eb41d --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Lifecycle.kt @@ -0,0 +1,7 @@ +package io.emeraldpay.dshackle.upstream + +interface Lifecycle { + fun start() + fun stop() + fun isRunning(): Boolean +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt index 42e654e0..7ea7d7f8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt @@ -21,7 +21,6 @@ import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable import reactor.core.publisher.Flux @@ -43,7 +42,7 @@ class MergedHead( override fun start() { super.start() sources.forEach { head -> - if (head is Lifecycle && !head.isRunning) { + if (head is Lifecycle && !head.isRunning()) { head.start() } } @@ -56,7 +55,7 @@ class MergedHead( override fun stop() { super.stop() sources.forEach { head -> - if (head is Lifecycle && head.isRunning) { + if (head is Lifecycle && head.isRunning()) { head.stop() } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index 80e19481..54fb2dfd 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -31,14 +31,15 @@ import io.micrometer.core.instrument.Tag import org.apache.commons.collections4.Factory import org.apache.commons.collections4.FunctorException import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import org.springframework.context.event.EventListener +import org.springframework.core.Ordered +import org.springframework.core.annotation.Order import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.publisher.Mono import java.time.Duration import java.time.Instant -import java.util.Locale +import java.util.* import java.util.concurrent.atomic.AtomicReference import java.util.concurrent.locks.ReentrantLock import java.util.function.Predicate @@ -51,8 +52,7 @@ abstract class Multistream( val chain: Chain, private val upstreams: MutableList, val caches: Caches, - val postprocessor: RequestPostprocessor, - val callTargetsHolder: CallTargetsHolder + val postprocessor: RequestPostprocessor ) : Upstream, Lifecycle { companion object { @@ -60,6 +60,8 @@ abstract class Multistream( private const val metrics = "upstreams" } + private var started = false + private var cacheSubscription: Disposable? = null private val reconfigLock = ReentrantLock() private var callMethods: CallMethods? = null @@ -235,6 +237,7 @@ abstract class Multistream( // print status _change_ every 15 seconds, at most; otherwise prints it on interval of 30 seconds .sample(Duration.ofSeconds(15)) .subscribe { printStatus() } + started = true } override fun stop() { @@ -248,6 +251,7 @@ abstract class Multistream( } } lagObserver?.stop() + started = false } fun onHeadUpdated(head: Head) { @@ -321,18 +325,22 @@ abstract class Multistream( } @EventListener + @Order(Ordered.HIGHEST_PRECEDENCE) fun onUpstreamChange(event: UpstreamChangeEvent) { val chain = event.chain if (this.chain == chain) { if (event.type == UpstreamChangeEvent.ChangeType.REMOVED) { removeUpstream(event.upstream.getId()) - log.info("Upstream ${event.upstream.getId()} with chain $chain has been removed") + log.error("Upstream ${event.upstream.getId()} with chain $chain has been removed") } else { if (event.upstream is CachesEnabled) { event.upstream.setCaches(caches) } addUpstream(event.upstream) - log.info("Upstream ${event.upstream.getId()} with chain $chain has been added") + if (!started) { + start() + } + log.error("Upstream ${event.upstream.getId()} with chain $chain has been added") } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt index 6e1c4ab0..80b4e564 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt @@ -17,7 +17,6 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.grpc.Chain -import reactor.core.publisher.Flux /** * Holds Multistreams configured for a chain. @@ -25,6 +24,5 @@ import reactor.core.publisher.Flux interface MultistreamHolder { fun getUpstream(chain: Chain): Multistream? fun getAvailable(): List - fun observeChains(): Flux fun isAvailable(chain: Chain): Boolean } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt index 14ebfda0..aca3d567 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt @@ -19,22 +19,21 @@ import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.publisher.Mono @Suppress("UNCHECKED_CAST") open class BitcoinMultistream( chain: Chain, private val sourceUpstreams: MutableList, - caches: Caches, - callTargetsHolder: CallTargetsHolder -) : Multistream(chain, sourceUpstreams as MutableList, caches, RequestPostprocessor.Empty(), callTargetsHolder), Lifecycle { + caches: Caches +) : Multistream(chain, sourceUpstreams as MutableList, caches, RequestPostprocessor.Empty()), Lifecycle { companion object { private val log = LoggerFactory.getLogger(BitcoinMultistream::class.java) @@ -136,7 +135,7 @@ open class BitcoinMultistream( } override fun isRunning(): Boolean { - return super.isRunning() || reader.isRunning + return super.isRunning() || reader.isRunning() } override fun start() { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt index f9f0496c..8ae68e9f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt @@ -19,13 +19,13 @@ import com.fasterxml.jackson.databind.ObjectMapper import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import org.bitcoinj.core.Address import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.cast @@ -72,7 +72,7 @@ open class BitcoinReader( } override fun isRunning(): Boolean { - return mempool.isRunning + return mempool.isRunning() } override fun start() { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt index 72f500bc..5c018104 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt @@ -19,11 +19,11 @@ import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.AbstractHead import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import org.springframework.scheduling.concurrent.CustomizableThreadFactory import reactor.core.Disposable import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt index e5ab2d29..23b82f35 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt @@ -20,6 +20,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.calls.CallMethods @@ -27,7 +28,6 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable open class BitcoinRpcUpstream( @@ -92,7 +92,7 @@ open class BitcoinRpcUpstream( override fun isRunning(): Boolean { var runningAny = validatorSubscription != null if (head is Lifecycle) { - runningAny = runningAny || head.isRunning + runningAny = runningAny || head.isRunning() } return runningAny } @@ -100,7 +100,7 @@ open class BitcoinRpcUpstream( override fun start() { log.info("Configured for ${chain.chainName}") if (head is Lifecycle) { - if (!head.isRunning) { + if (!head.isRunning()) { head.start() } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinZMQHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinZMQHead.kt index 4ce4bcc1..07ed5837 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinZMQHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinZMQHead.kt @@ -5,12 +5,12 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.AbstractHead import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import org.apache.commons.codec.binary.Hex import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -65,6 +65,6 @@ class BitcoinZMQHead( } override fun isRunning(): Boolean { - return server.isRunning || refreshSubscription != null + return server.isRunning() || refreshSubscription != null } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt index 3e26e5a5..f4df9af9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt @@ -18,11 +18,11 @@ package io.emeraldpay.dshackle.upstream.bitcoin import com.fasterxml.jackson.databind.ObjectMapper import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable import reactor.core.publisher.Mono import java.time.Duration diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ZMQServer.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ZMQServer.kt index 1358f568..fb208deb 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ZMQServer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ZMQServer.kt @@ -1,7 +1,7 @@ package io.emeraldpay.dshackle.upstream.bitcoin +import io.emeraldpay.dshackle.upstream.Lifecycle import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import org.zeromq.SocketType import org.zeromq.ZContext import org.zeromq.ZMQ diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt index e2fb57f5..fd7f4cf3 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt @@ -21,13 +21,13 @@ import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import org.springframework.util.ConcurrentReferenceHashMap import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -36,9 +36,8 @@ import reactor.core.publisher.Mono open class EthereumMultistream( chain: Chain, val upstreams: MutableList, - caches: Caches, - callTargetsHolder: CallTargetsHolder -) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches), callTargetsHolder), EthereumLikeMultistream { + caches: Caches +) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches)), EthereumLikeMultistream { companion object { private val log = LoggerFactory.getLogger(EthereumMultistream::class.java) @@ -80,7 +79,7 @@ open class EthereumMultistream( } override fun isRunning(): Boolean { - return super.isRunning() || reader.isRunning + return super.isRunning() || reader.isRunning() } override fun getReader(): EthereumReader { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumReader.kt index 8501a99b..6f3ea506 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumReader.kt @@ -30,6 +30,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.reader.RekeyingReader import io.emeraldpay.dshackle.reader.RpcReader import io.emeraldpay.dshackle.reader.TransformingReader +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.etherjar.domain.Address @@ -41,7 +42,6 @@ import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson import org.apache.commons.collections4.Factory import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import java.util.function.Function /** @@ -174,7 +174,7 @@ open class EthereumReader( override fun isRunning(): Boolean { // TODO should be always running? - return up.isRunning + return true // up.isRunning } override fun start() { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcHead.kt index 00637d54..16331153 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcHead.kt @@ -18,11 +18,11 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.BlockValidator +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import org.springframework.scheduling.concurrent.CustomizableThreadFactory import reactor.core.Disposable import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt index 3bbe468f..bb2479df 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt @@ -80,7 +80,7 @@ open class EthereumRpcUpstream( } override fun isRunning(): Boolean { - return connector.isRunning + return connector.isRunning() } override fun getApi(): Reader { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt index 1532d5d8..2ed626f6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt @@ -17,10 +17,10 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.dshackle.upstream.BlockValidator +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcWsClient import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnector.kt index 85ecf596..c9b2b69d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnector.kt @@ -2,9 +2,9 @@ package io.emeraldpay.dshackle.upstream.ethereum.connectors import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import org.springframework.context.Lifecycle interface EthereumConnector : Lifecycle { fun getHead(): Head diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt index 2b46a499..21fefba1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt @@ -5,6 +5,7 @@ import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.BlockValidator import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.MergedHead import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcHead import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsFactory @@ -14,7 +15,6 @@ import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import java.time.Duration class EthereumRpcConnector( @@ -61,7 +61,7 @@ class EthereumRpcConnector( override fun isRunning(): Boolean { if (head is Lifecycle) { - return head.isRunning + return head.isRunning() } return true } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt index 0a248e2c..609e88cf 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt @@ -36,7 +36,7 @@ class EthereumWsConnector( } override fun isRunning(): Boolean { - return head.isRunning + return head.isRunning() } override fun stop() { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt index 3e93a81a..71477c37 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt @@ -21,13 +21,13 @@ import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.forkchoice.PriorityForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import org.springframework.util.ConcurrentReferenceHashMap import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -36,9 +36,8 @@ import reactor.core.publisher.Mono open class EthereumPosMultiStream( chain: Chain, val upstreams: MutableList, - caches: Caches, - callTargetsHolder: CallTargetsHolder -) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches), callTargetsHolder), EthereumLikeMultistream { + caches: Caches +) : Multistream(chain, upstreams as MutableList, caches, CacheRequested(caches)), EthereumLikeMultistream { companion object { private val log = LoggerFactory.getLogger(EthereumPosMultiStream::class.java) @@ -75,7 +74,7 @@ open class EthereumPosMultiStream( } override fun isRunning(): Boolean { - return super.isRunning() || reader.isRunning + return super.isRunning() || reader.isRunning() } override fun getReader(): EthereumReader { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt index 50f201c2..78ce2c24 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt @@ -22,6 +22,7 @@ import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.calls.CallMethods @@ -31,7 +32,6 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable open class EthereumPosRpcUpstream( @@ -80,7 +80,7 @@ open class EthereumPosRpcUpstream( } override fun isRunning(): Boolean { - return connector.isRunning + return connector.isRunning() } override fun getApi(): Reader { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt index a539a21a..35397e43 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt @@ -24,6 +24,7 @@ import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability @@ -37,7 +38,6 @@ import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.publisher.Flux import reactor.core.publisher.Mono import java.math.BigInteger diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt index d407d3b5..c0427a06 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt @@ -26,6 +26,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability @@ -40,7 +41,6 @@ import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.publisher.Flux import reactor.core.publisher.Mono import java.math.BigInteger diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt index 10a005cc..72c03c28 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt @@ -26,6 +26,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.Head +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability @@ -40,7 +41,6 @@ import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.publisher.Flux import reactor.core.publisher.Mono import java.math.BigInteger diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt index ac2db057..78883e1c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt @@ -22,12 +22,12 @@ import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.upstream.AbstractHead import io.emeraldpay.dshackle.upstream.DefaultUpstream +import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory -import org.springframework.context.Lifecycle import reactor.core.Disposable import reactor.core.publisher.Flux import reactor.core.publisher.Mono @@ -60,7 +60,7 @@ class GrpcHead( * Initiate a new head subscription with connection to the remote */ private fun internalStart(remote: ReactorBlockchainGrpc.ReactorBlockchainStub) { - if (this.isRunning) { + if (this.isRunning()) { stop() } log.debug("Start Head subscription to ${parent.getId()}") diff --git a/src/main/resources/log4j2.xml b/src/main/resources/log4j2.xml index 08e5d92d..807a731a 100644 --- a/src/main/resources/log4j2.xml +++ b/src/main/resources/log4j2.xml @@ -41,4 +41,4 @@ - \ No newline at end of file + diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 43352b51..93cc1fbc 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -246,9 +246,7 @@ class NativeCallSpec extends Specification { def "Returns error for unsupported chain"() { setup: - def upstreams = Mock(MultistreamHolder) { - _ * it.observeChains() >> Flux.empty() - } + def upstreams = Mock(MultistreamHolder) def nativeCall = nativeCall(upstreams) def req = BlockchainOuterClass.NativeCallRequest.newBuilder() diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy index 9e34c546..e26cc9f7 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy @@ -50,7 +50,7 @@ class MultistreamHolderMock implements MultistreamHolder { if (up instanceof EthereumPosMultiStream) { upstreams[chain] = up } else if (up instanceof EthereumPosRpcUpstream) { - upstreams[chain] = new EthereumPosMultiStream(chain, [up as EthereumPosRpcUpstream], Caches.default(), TestingCommons.callTargetsHolder) + upstreams[chain] = new EthereumPosMultiStream(chain, [up as EthereumPosRpcUpstream], Caches.default()) } else { throw new IllegalArgumentException("Unsupported upstream type ${up.class}") } @@ -59,7 +59,7 @@ class MultistreamHolderMock implements MultistreamHolder { if (up instanceof BitcoinMultistream) { upstreams[chain] = up } else if (up instanceof BitcoinRpcUpstream) { - upstreams[chain] = new BitcoinMultistream(chain, [up as BitcoinRpcUpstream], Caches.default(), TestingCommons.callTargetsHolder) + upstreams[chain] = new BitcoinMultistream(chain, [up as BitcoinRpcUpstream], Caches.default()) } else { throw new IllegalArgumentException("Unsupported upstream type ${up.class}") } @@ -81,11 +81,6 @@ class MultistreamHolderMock implements MultistreamHolder { return upstreams.keySet().toList() } - @Override - Flux observeChains() { - return Flux.fromIterable(getAvailable()) - } - @Override boolean isAvailable(@NotNull Chain chain) { return upstreams.containsKey(chain) @@ -98,7 +93,7 @@ class MultistreamHolderMock implements MultistreamHolder { Head customHead = null EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams, @NotNull Caches caches) { - super(chain, upstreams, caches, TestingCommons.callTargetsHolder) + super(chain, upstreams, caches) } EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams) { diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index f2c640d7..7bfab88c 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -29,7 +29,6 @@ import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream -import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash @@ -80,7 +79,7 @@ class TestingCommons { } static Multistream multistream(EthereumPosRpcUpstreamMock up) { - return new EthereumPosMultiStream(Chain.ETHEREUM, [up], Caches.default(), callTargetsHolder).tap { + return new EthereumPosMultiStream(Chain.ETHEREUM, [up], Caches.default()).tap { start() } } @@ -101,11 +100,11 @@ class TestingCommons { } static Multistream multistreamWithoutUpstreams(Chain chain) { - return new EthereumPosMultiStream(chain, [], emptyCaches().getCaches(chain), callTargetsHolder) + return new EthereumPosMultiStream(chain, [], emptyCaches().getCaches(chain)) } static Multistream multistreamClassicWithoutUpstreams(Chain chain) { - return new EthereumMultistream(chain, [], emptyCaches().getCaches(chain), callTargetsHolder) + return new EthereumMultistream(chain, [], emptyCaches().getCaches(chain)) } static FileResolver fileResolver() { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/MergedHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/MergedHeadSpec.groovy index e1b72360..a6e08be3 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/MergedHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/MergedHeadSpec.groovy @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice -import org.springframework.context.Lifecycle +import io.emeraldpay.dshackle.upstream.Lifecycle import reactor.core.publisher.Flux import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy index b432bcb8..8a28f4b3 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy @@ -50,7 +50,7 @@ class MultistreamSpec extends Specification { setup: def up1 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test1", "eth_test2"])) def up2 = new EthereumPosRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test2", "eth_test3"])) - def aggr = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2], Caches.default(), TestingCommons.callTargetsHolder) + def aggr = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2], Caches.default()) when: aggr.onUpstreamsUpdated() def act = aggr.getMethods() @@ -206,7 +206,7 @@ class MultistreamSpec extends Specification { def up1 = TestingCommons.upstream("test-1", "internal") def up2 = TestingCommons.upstream("test-2", "external") def up3 = TestingCommons.upstream("test-3", "external") - def multistream = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2, up3], Caches.default(), TestingCommons.callTargetsHolder) + def multistream = new EthereumPosMultiStream(Chain.ETHEREUM, [up1, up2, up3], Caches.default()) expect: multistream.getHead(new Selector.LabelMatcher("provider", ["internal"])).is(up1.ethereumHeadMock) @@ -345,7 +345,7 @@ class MultistreamSpec extends Specification { class TestMultistream extends Multistream { TestMultistream(List upstreams, @NotNull RequestPostprocessor postprocessor) { - super(Chain.ETHEREUM, upstreams, Caches.default(), postprocessor, TestingCommons.callTargetsHolder) + super(Chain.ETHEREUM, upstreams, Caches.default(), postprocessor) } @Override @@ -386,7 +386,7 @@ class MultistreamSpec extends Specification { class TestEthereumPosMultistream extends EthereumPosMultiStream { TestEthereumPosMultistream(@NotNull Chain chain, @NotNull List upstreams, @NotNull Caches caches) { - super(chain, upstreams, caches, TestingCommons.callTargetsHolder) + super(chain, upstreams, caches) } @Override From b450cc9a9407742e0cae62f2b5c197d4978205b5 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Thu, 17 Nov 2022 13:52:36 +0400 Subject: [PATCH 05/20] use only chain map --- .../upstream/CurrentMultistreamHolder.kt | 21 +++++-------------- .../dshackle/upstream/Multistream.kt | 4 ++++ 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index b4865951..e4f6029d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -19,31 +19,23 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.stereotype.Component -import reactor.core.publisher.Sinks -import java.util.* -import java.util.concurrent.ConcurrentHashMap -import java.util.concurrent.locks.ReentrantLock import javax.annotation.PreDestroy -import kotlin.concurrent.withLock @Component open class CurrentMultistreamHolder( - private val multistreams: List + multistreams: List ) : MultistreamHolder { private val log = LoggerFactory.getLogger(CurrentMultistreamHolder::class.java) - private val chainMapping = ConcurrentHashMap().apply { - multistreams.forEach { this[it.chain] = it } - } - private val updateLock = ReentrantLock() + private val chainMapping = multistreams.associateBy { it.chain } override fun getUpstream(chain: Chain): Multistream? { return chainMapping[chain] } override fun getAvailable(): List { - return multistreams.asSequence() + return chainMapping.values.asSequence() .filter { it.isAvailable() } .map { it.chain } .toList() @@ -56,11 +48,8 @@ open class CurrentMultistreamHolder( @PreDestroy fun shutdown() { log.info("Closing upstream connections...") - updateLock.withLock { - chainMapping.values.forEach { - it.stop() - } - chainMapping.clear() + chainMapping.values.forEach { + it.stop() } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index 54fb2dfd..30fa4f24 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -324,6 +324,10 @@ abstract class Multistream( log.info("State of ${chain.chainCode}: height=${height ?: '?'}, status=[$statuses], lag=[$lag], weak=[$weak]") } + fun test(event: UpstreamChangeEvent): Boolean { + return event.chain == this.chain + } + @EventListener @Order(Ordered.HIGHEST_PRECEDENCE) fun onUpstreamChange(event: UpstreamChangeEvent) { From e66bb772ad06d02f5996770ddbc94f48906088c4 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Fri, 18 Nov 2022 19:20:41 +0400 Subject: [PATCH 06/20] small fixes for integration tests --- .../dshackle/startup/ConfiguredUpstreams.kt | 1 - testing/dshackle/dshackle-basic.yaml | 17 +++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index b66a125a..51aed124 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -111,7 +111,6 @@ open class ConfiguredUpstreams( } upstream?.let { val event = UpstreamChangeEvent(chain, upstream, UpstreamChangeEvent.ChangeType.ADDED) - log.error("first !!!! Upstream ${event.upstream.getId()} with chain $chain has been added") eventPublisher.publishEvent(event) } } diff --git a/testing/dshackle/dshackle-basic.yaml b/testing/dshackle/dshackle-basic.yaml index 51318221..56515c78 100644 --- a/testing/dshackle/dshackle-basic.yaml +++ b/testing/dshackle/dshackle-basic.yaml @@ -7,6 +7,7 @@ tls: cluster: upstreams: - id: test-1 + node-id: 1 chain: ethereum methods: enabled: @@ -15,17 +16,21 @@ cluster: options: disable-validation: true connection: - ethereum: - rpc: - url: "http://localhost:18545" + ethereum-pos: + execution: + rpc: + url: "http://localhost:18545" + - id: test-2 + node-id: 2 chain: ethereum options: disable-validation: true connection: - ethereum: - rpc: - url: "http://localhost:18546" + execution: + ethereum-pos: + rpc: + url: "http://localhost:18546" cache: redis: From 5aefa7ea22b9ebc285b1441dc319516e5983dbce Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Fri, 18 Nov 2022 19:47:35 +0400 Subject: [PATCH 07/20] describe should return all chains with upstream, not only available --- .../emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt | 2 +- src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index e4f6029d..54a152b3 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -36,7 +36,7 @@ open class CurrentMultistreamHolder( override fun getAvailable(): List { return chainMapping.values.asSequence() - .filter { it.isAvailable() } + .filter { it.haveUpstreams() } .map { it.chain } .toList() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index 30fa4f24..b6de244c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -349,6 +349,9 @@ abstract class Multistream( } } + fun haveUpstreams(): Boolean = + upstreams.isNotEmpty() + // -------------------------------------------------------------------------------------------------------- class UpstreamStatus(val upstream: Upstream, val status: UpstreamAvailability, val ts: Instant = Instant.now()) From 16a336c9686efc8fab299162423cf1174d5584ec Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 14:55:11 +0400 Subject: [PATCH 08/20] Return current block height in DescribeChain response --- emerald-java-client | 2 +- src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/emerald-java-client b/emerald-java-client index 35196f35..130e1908 160000 --- a/emerald-java-client +++ b/emerald-java-client @@ -1 +1 @@ -Subproject commit 35196f35f3d0546d59b51acfeb895174eac170f9 +Subproject commit 130e1908937e72f1bb1d256afd51af6e46a368d3 diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt index 2d4cccf6..775d16fc 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt @@ -44,6 +44,7 @@ class Describe( .setChain(Common.ChainRef.forNumber(chain.id)) .addAllSupportedMethods(targets) .setStatus(status) + .setCurrentHeight(chainUpstreams.getHead().getCurrentHeight() ?: 0) chainUpstreams.getAll().let { ups -> ups.forEach { up -> val nodes = QuorumForLabels() From 4c8a5638c45765541f2524fba0022c0b0c1187ee Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 15:43:38 +0400 Subject: [PATCH 09/20] update submodule api --- emerald-java-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/emerald-java-client b/emerald-java-client index 130e1908..6efc63d1 160000 --- a/emerald-java-client +++ b/emerald-java-client @@ -1 +1 @@ -Subproject commit 130e1908937e72f1bb1d256afd51af6e46a368d3 +Subproject commit 6efc63d11f502bba6f756db5f23349016a1a3a74 From e5ebd85c7e0814e396792e340790cd85448d76e8 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 17:20:15 +0400 Subject: [PATCH 10/20] remove submodule --- .gitmodules | 3 --- emerald-java-client | 1 - settings.gradle | 6 ------ 3 files changed, 10 deletions(-) delete mode 160000 emerald-java-client diff --git a/.gitmodules b/.gitmodules index 152400db..041a1d48 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "emerald-java-client"] - path = emerald-java-client - url = https://github.com/p2p-org/emerald-java-client.git [submodule "dshackle-cli/grpc"] path = dshackle-cli/grpc url = https://github.com/p2p-org/emerald-grpc.git diff --git a/emerald-java-client b/emerald-java-client deleted file mode 160000 index 6efc63d1..00000000 --- a/emerald-java-client +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 6efc63d11f502bba6f756db5f23349016a1a3a74 diff --git a/settings.gradle b/settings.gradle index 470d0974..0778dbab 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,2 @@ enableFeaturePreview("VERSION_CATALOGS") enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS") - -includeBuild('./emerald-java-client') { - dependencySubstitution { - substitute module('io.emeraldpay:emerald-api:0.12-alpha.3') using project(':') - } -} \ No newline at end of file From c1b0e758eaeb3c5779beaef8a45cd629bdb66874 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 18:14:04 +0400 Subject: [PATCH 11/20] added proto as submodule and proto generation configured --- .gitmodules | 3 + build.gradle | 27 +- dshackle-cli/src/grpc-clent.js | 2 +- emerald-grpc | 1 + gradle.properties | 3 + gradle/libs.versions.toml | 4 +- proto/README.adoc | 7 - proto/blockchain.proto | 284 ------------------ proto/common.proto | 74 ----- .../io/emeraldpay/dshackle/BlockchainType.kt | 36 +++ .../kotlin/io/emeraldpay/dshackle/Chain.kt | 64 ++++ .../io/emeraldpay/dshackle/ChainValue.kt | 1 - .../kotlin/io/emeraldpay/dshackle/Global.kt | 1 - .../io/emeraldpay/dshackle/SilentException.kt | 1 - .../dshackle/cache/BlocksRedisCache.kt | 2 +- .../dshackle/cache/CachesFactory.kt | 4 +- .../dshackle/cache/HeightByHashRedisCache.kt | 2 +- .../dshackle/cache/OnBlockRedisCache.kt | 2 +- .../dshackle/cache/OnTxRedisCache.kt | 2 +- .../dshackle/cache/ReceiptRedisCache.kt | 2 +- .../emeraldpay/dshackle/cache/TxRedisCache.kt | 2 +- .../dshackle/config/HealthConfig.kt | 2 +- .../dshackle/config/HealthConfigReader.kt | 2 +- .../emeraldpay/dshackle/config/ProxyConfig.kt | 2 +- .../dshackle/config/ProxyConfigReader.kt | 2 +- .../dshackle/config/TokensConfig.kt | 4 +- .../config/context/MultistreamsConfig.kt | 4 +- .../monitoring/accesslog/AccessHandlerHttp.kt | 2 +- .../dshackle/monitoring/accesslog/Events.kt | 2 +- .../monitoring/accesslog/EventsBuilder.kt | 2 +- .../emeraldpay/dshackle/proxy/BaseHandler.kt | 2 +- .../emeraldpay/dshackle/proxy/HttpHandler.kt | 2 +- .../emeraldpay/dshackle/proxy/ProxyServer.kt | 2 +- .../dshackle/proxy/WebsocketHandler.kt | 2 +- .../emeraldpay/dshackle/rpc/BlockchainRpc.kt | 2 +- .../io/emeraldpay/dshackle/rpc/EstimateFee.kt | 2 +- .../io/emeraldpay/dshackle/rpc/NativeCall.kt | 4 +- .../dshackle/rpc/NativeSubscribe.kt | 4 +- .../io/emeraldpay/dshackle/rpc/StreamHead.kt | 2 +- .../dshackle/rpc/SubscribeStatus.kt | 2 +- .../emeraldpay/dshackle/rpc/TrackAddress.kt | 2 +- .../dshackle/rpc/TrackBitcoinAddress.kt | 4 +- .../emeraldpay/dshackle/rpc/TrackBitcoinTx.kt | 4 +- .../dshackle/rpc/TrackERC20Address.kt | 4 +- .../dshackle/rpc/TrackEthereumAddress.kt | 4 +- .../dshackle/rpc/TrackEthereumTx.kt | 4 +- .../io/emeraldpay/dshackle/rpc/TrackTx.kt | 2 +- .../dshackle/startup/ConfiguredUpstreams.kt | 4 +- .../dshackle/startup/UpstreamChangeEvent.kt | 2 +- .../dshackle/upstream/CallTargetsHolder.kt | 4 +- .../upstream/CurrentMultistreamHolder.kt | 2 +- .../dshackle/upstream/FilteredApis.kt | 2 +- .../dshackle/upstream/HttpFactory.kt | 2 +- .../dshackle/upstream/HttpRpcFactory.kt | 2 +- .../dshackle/upstream/Multistream.kt | 2 +- .../dshackle/upstream/MultistreamHolder.kt | 2 +- .../upstream/bitcoin/BitcoinMultistream.kt | 2 +- .../upstream/bitcoin/BitcoinRpcUpstream.kt | 2 +- .../upstream/bitcoin/BitcoinUpstream.kt | 2 +- .../upstream/calls/DefaultEthereumMethods.kt | 2 +- .../upstream/ethereum/EthereumMultistream.kt | 2 +- .../upstream/ethereum/EthereumRpcUpstream.kt | 2 +- .../upstream/ethereum/EthereumWsFactory.kt | 2 +- .../ethereum/connectors/ConnectorFactory.kt | 2 +- .../connectors/EthereumConnectorFactory.kt | 2 +- .../ethereum_pos/EthereumPosMultiStream.kt | 2 +- .../ethereum_pos/EthereumPosRpcUpstream.kt | 2 +- .../upstream/grpc/BitcoinGrpcUpstream.kt | 2 +- .../upstream/grpc/EthereumGrpcUpstream.kt | 2 +- .../upstream/grpc/EthereumPosGrpcUpstream.kt | 2 +- .../dshackle/upstream/grpc/GrpcHead.kt | 2 +- .../dshackle/upstream/grpc/GrpcUpstreams.kt | 4 +- .../upstream/rpcclient/JsonRpcGrpcClient.kt | 2 +- .../cache/BlocksRedisCacheSpec.groovy | 2 +- .../cache/HeightByHashRedisCacheSpec.groovy | 2 +- .../cache/ReceiptRedisCacheSpec.groovy | 2 +- .../dshackle/cache/TxRedisCacheSpec.groovy | 2 +- .../config/HealthConfigReaderSpec.groovy | 2 +- .../config/MainConfigReaderSpec.groovy | 2 +- .../config/ProxyConfigReaderSpec.groovy | 2 +- .../config/TokensConfigReaderSpec.groovy | 2 +- .../monitoring/HealthCheckSetupSpec.groovy | 2 +- .../accesslog/AccessLogWriterSpec.groovy | 2 +- .../accesslog/EventsBaseBuilderSpec.groovy | 2 +- .../EventsBuilderSubscribeBalanceSpec.groovy | 2 +- .../dshackle/proxy/BaseHandlerSpec.groovy | 2 +- .../dshackle/proxy/HttpHandlerSpec.groovy | 2 +- .../dshackle/proxy/ProxyServerSpec.groovy | 2 +- .../proxy/WebsocketHandlerSpec.groovy | 2 +- .../quorum/QuorumRpcReaderSpec.groovy | 2 +- .../dshackle/rpc/NativeCallSpec.groovy | 2 +- .../dshackle/rpc/NativeSubscribeSpec.groovy | 2 +- .../dshackle/rpc/StreamHeadSpec.groovy | 2 +- .../dshackle/rpc/SubscribeStatusSpec.groovy | 2 +- .../rpc/TrackBitcoinAddressSpec.groovy | 2 +- .../dshackle/rpc/TrackBitcoinTxSpec.groovy | 2 +- .../dshackle/rpc/TrackERC20AddressSpec.groovy | 2 +- .../rpc/TrackEthereumAddressSpec.groovy | 2 +- .../dshackle/rpc/TrackEthereumTxSpec.groovy | 2 +- .../startup/ConfiguredUpstreamsSpec.groovy | 2 +- .../dshackle/test/ConnectorFactoryMock.groovy | 2 +- .../test/EthereumPosRpcUpstreamMock.groovy | 2 +- .../test/EthereumRpcUpstreamMock.groovy | 2 +- .../test/MultistreamHolderMock.groovy | 5 +- .../dshackle/test/TestingCommons.groovy | 2 +- .../CurrentMultistreamHolderSpec.groovy | 2 +- .../dshackle/upstream/FilteredApisSpec.groovy | 2 +- .../dshackle/upstream/MultistreamSpec.groovy | 2 +- .../calls/DefaultEthereumMethodsSpec.groovy | 2 +- .../calls/ManagedCallMethodsSpec.groovy | 2 +- .../upstream/ethereum/ERC20BalanceSpec.groovy | 2 +- .../ethereum/EthereumDirectReaderSpec.groovy | 2 +- .../ethereum/EthereumReaderSpec.groovy | 2 +- .../ethereum/LocalCallRouterSpec.groovy | 2 +- .../ethereum/WsConnectionRealSpec.groovy | 2 +- .../upstream/ethereum/WsConnectionSpec.groovy | 2 +- .../grpc/EthereumGrpcUpstreamSpec.groovy | 2 +- .../upstream/grpc/GrpcHeadSpec.groovy | 2 +- 118 files changed, 249 insertions(+), 496 deletions(-) create mode 160000 emerald-grpc delete mode 100644 proto/README.adoc delete mode 100644 proto/blockchain.proto delete mode 100644 proto/common.proto create mode 100644 src/main/kotlin/io/emeraldpay/dshackle/BlockchainType.kt create mode 100644 src/main/kotlin/io/emeraldpay/dshackle/Chain.kt diff --git a/.gitmodules b/.gitmodules index 041a1d48..44248f44 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "dshackle-cli/grpc"] path = dshackle-cli/grpc url = https://github.com/p2p-org/emerald-grpc.git +[submodule "emerald-grpc"] + path = emerald-grpc + url = git@github.com:p2p-org/emerald-grpc.git diff --git a/build.gradle b/build.gradle index eb15c928..fe016704 100644 --- a/build.gradle +++ b/build.gradle @@ -5,6 +5,15 @@ import java.time.ZoneId import java.time.format.DateTimeFormatter import java.time.temporal.ChronoUnit +buildscript { + repositories { + gradlePluginPortal() + } + dependencies { + classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.1' + } +} + plugins { id 'java' id 'groovy' @@ -70,10 +79,6 @@ dependencies { implementation libs.bundles.etherjar - implementation(libs.emerald.api) { - exclude group: 'com.salesforce.servicelibs', module: 'reactor-grpc' - } - implementation libs.bitcoinj implementation libs.snake.yaml @@ -188,14 +193,26 @@ protobuf { artifact = System.getenv("PROTOC_PATH") == null ? "com.google.protobuf:protoc:${libs.versions.protoc.get()}" : null } plugins { + grpc { + artifact = "io.grpc:protoc-gen-grpc-java:${grpcVersion}" + } + reactor { artifact = "com.salesforce.servicelibs:reactor-grpc:${reactiveGrpcVersion}" } } generateProtoTasks { + all()*.plugins { + grpc {} + reactor {} + } } } sourceSets { main { - resources.srcDirs += project.buildDir.absolutePath + "/generated/version" + //resources.srcDirs += project.buildDir.absolutePath + "/generated/version" + + proto { + srcDir 'emerald-grpc/proto' + } } } diff --git a/dshackle-cli/src/grpc-clent.js b/dshackle-cli/src/grpc-clent.js index a4b33d92..9aeeb2a8 100644 --- a/dshackle-cli/src/grpc-clent.js +++ b/dshackle-cli/src/grpc-clent.js @@ -3,7 +3,7 @@ const path = require('path') const protoLoader = require("@grpc/proto-loader"); const fs = require('fs'); -const PROTO_PATH = path.join(__dirname, "../grpc/proto/blockchain.proto"); +const PROTO_PATH = path.join(__dirname, "../../emerald-grpc/proto/blockchain.proto"); const options = { keepCase: true, diff --git a/emerald-grpc b/emerald-grpc new file mode 160000 index 00000000..441f828e --- /dev/null +++ b/emerald-grpc @@ -0,0 +1 @@ +Subproject commit 441f828eb6d4a0d5d91d6575911eec80271a24aa diff --git a/gradle.properties b/gradle.properties index 974d2f80..fd99adb0 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,6 @@ kotlin.code.style=official +grpcVersion=1.49.2 +reactiveGrpcVersion=1.2.0 + diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 3b66bf30..4cb7d9bd 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -31,8 +31,6 @@ cglib-nodep = "cglib:cglib-nodep:3.3.0" detekt-formatting = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt" } -emerald-api = "io.emeraldpay:emerald-api:0.12-alpha.3" - equals-verifier = "nl.jqno.equalsverifier:equalsverifier:3.10.1" etherjar-domain = { module = "io.emeraldpay.etherjar:etherjar-domain", version.ref = "etherjar" } @@ -130,6 +128,6 @@ kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } jib = { id = "com.google.cloud.tools.jib", version = "2.5.0" } spring = { id = "org.springframework.boot", version = "2.3.5.RELEASE" } git = { id = "com.palantir.git-version", version = "0.12.3" } -protobuf = { id = "com.google.protobuf", version = "0.8.17" } +protobuf = { id = "com.google.protobuf", version = "0.9.1" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "10.2.0" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } \ No newline at end of file diff --git a/proto/README.adoc b/proto/README.adoc deleted file mode 100644 index bc5ea63d..00000000 --- a/proto/README.adoc +++ /dev/null @@ -1,7 +0,0 @@ -= Emerald Dshackle Protobuf definitions - -Protobuf definition for the external interface (i.e. gRPC) of the Emerald Dshackle. -This gRPC definitions are part of the general Emerald API, please see the project with whole API at https://github.com/emeraldpay/emerald-grpc - -Dshakle also has some internal Protobuf schemas, for example to serialize cached values. -You can find them in link:../src/main/proto/[]. \ No newline at end of file diff --git a/proto/blockchain.proto b/proto/blockchain.proto deleted file mode 100644 index 05d92c3c..00000000 --- a/proto/blockchain.proto +++ /dev/null @@ -1,284 +0,0 @@ -syntax = "proto3"; -package emerald; -option java_package = "io.emeraldpay.api.proto"; -import "common.proto"; - -service Blockchain { - rpc SubscribeHead (Chain) returns (stream ChainHead) {} - rpc SubscribeBalance (BalanceRequest) returns (stream AddressBalance) {} - rpc SubscribeTxStatus (TxStatusRequest) returns (stream TxStatus) {} - - rpc GetBalance (BalanceRequest) returns (stream AddressBalance) {} - - /** - * Fee Estimation service. The server tries to estimate a fair fee based on the last N blocks. - */ - rpc EstimateFee (EstimateFeeRequest) returns (EstimateFeeResponse) {} - - rpc NativeCall (NativeCallRequest) returns (stream NativeCallReplyItem) {} - rpc NativeSubscribe (NativeSubscribeRequest) returns (stream NativeSubscribeReplyItem) {} - - rpc Describe (DescribeRequest) returns (DescribeResponse) {} - rpc SubscribeStatus (StatusRequest) returns (stream ChainStatus) {} -} - -message NativeCallRequest { - ChainRef chain = 1; - repeated NativeCallItem items = 2; - Selector selector = 3; - int32 quorum = 4; - AvailabilityEnum min_availability = 5; -} - -message NativeCallItem { - uint32 id = 1; - string method = 3; - bytes payload = 4; - uint64 nonce = 5; -} - -/** - * Signature for a response - */ -message NativeCallReplySignature { - /** - * Original nonce value used for the call - */ - uint64 nonce = 1; - /** - * Signature value - */ - bytes signature = 2; - /** - * Key Id used for the signing - */ - uint64 key_id = 3; - /** - * Id of the upstream produced the response - */ - string upstream_id = 4; -} - -message NativeCallReplyItem { - uint32 id = 1; - bool succeed = 2; - bytes payload = 3; - string errorMessage = 4; - /** - * Optional signature for the response. - * Available only when it's configured at the edge dshackle and nonce is provided wit the request. - */ - NativeCallReplySignature signature = 5; -} - -message NativeSubscribeRequest { - ChainRef chain = 1; - string method = 2; - bytes payload = 3; -} - -message NativeSubscribeReplyItem { - bytes payload = 1; -} - -message ChainHead { - ChainRef chain = 1; - uint64 height = 2; - string block_id = 3; - uint64 timestamp = 4; - bytes weight = 5; - uint64 reorg = 6; -} - -message TxStatusRequest { - ChainRef chain = 1; - string tx_id = 2; - uint32 confirmation_limit = 3; -} - -message TxStatus { - string tx_id = 1; - bool broadcasted = 2; - bool mined = 3; - BlockInfo block = 4; - uint32 confirmations = 5; -} - -message BalanceRequest { - Asset asset = 1; - AnyAddress address = 2; - bool include_utxo = 3; -} - -message AddressBalance { - Asset asset = 1; - SingleAddress address = 2; - string balance = 3; - bool confirmed = 4; - repeated Utxo utxo = 5; -} - -message Utxo { - string tx_id = 1; - uint64 index = 2; - string balance = 3; - bool spent = 4; -} - -message DescribeRequest { -} - -message DescribeResponse { - repeated DescribeChain chains = 1; -} - -message DescribeChain { - ChainRef chain = 1; - ChainStatus status = 2; - repeated NodeDetails nodes = 3; - repeated string supportedMethods = 4; - repeated string excludedMethods = 5; - repeated Capabilities capabilities = 6; -} - -message StatusRequest { - repeated ChainRef chains = 1; -} - -message ChainStatus { - ChainRef chain = 1; - AvailabilityEnum availability = 2; - uint32 quorum = 3; -} - -enum AvailabilityEnum { - AVAIL_UNKNOWN = 0; - AVAIL_OK = 1; - AVAIL_LAGGING = 2; - AVAIL_IMMATURE = 3; - AVAIL_SYNCING = 4; - AVAIL_UNAVAILABLE = 5; -} - -message NodeDetails { - uint32 quorum = 1; - repeated Label labels = 2; -} - -enum Capabilities { - CAP_NONE = 0; - CAP_CALLS = 1; - CAP_BALANCE = 2; -} - -message Label { - string name = 1; - string value = 2; -} - -message Selector { - oneof selector_type { - LabelSelector labelSelector = 1; - OrSelector orSelector = 2; - AndSelector andSelector = 3; - NotSelector notSelector = 4; - ExistsSelector existsSelector = 5; - } -} - -message LabelSelector { - string name = 1; - repeated string value = 2; -} - -message OrSelector { - repeated Selector selectors = 1; -} - -message AndSelector { - repeated Selector selectors = 1; -} - -message NotSelector { - Selector selector = 1; -} - -message ExistsSelector { - string name = 1; -} - -/** - * Request for Fee Estimation Service - */ -message EstimateFeeRequest { - // Target chain - ChainRef chain = 1; - // The way how the fee should be estimated - FeeEstimationMode mode = 2; - // How many blocks the server is supposed to use to estimate current fee. Note that the server may use value, depending on configuration - uint32 blocks = 3; -} - -/** - * Responset for Fee Estimation Service - */ -message EstimateFeeResponse { - // May return different struct, depending on the blockchain - oneof fee_type { - // Standard Ethereum Fee, supported by majority of forks and by Ethereum Mainnet before EIP-1559 - EthereumStdFees ethereumStd = 1; - // Ethereum Fee for EIP-1559 compatible forks - EthereumExtFees ethereumExtended = 2; - // Standard Bitcoin Fee - BitcoinStdFees bitcoinStd = 3; - } -} - -/** - * The mode of how the fee must be estimated - */ -enum FeeEstimationMode { - INVALID = 0; - // Average over last transaction in each block - AVG_LAST = 1; - // Average over transaction 5th from the end in each block - AVG_T5 = 2; - // Average over transaction 20th from the end in each block - AVG_T20 = 3; - // Average over transaction 50th from the end in each block - AVG_T50 = 4; - // Minimal fee that would be accepted by every last block - MIN_ALWAYS = 5; - // Average over transaction in the middle of each block - AVG_MIDDLE = 6; - // Average over transaction in head of each block. Note that for Bitcoin it doesn't count COINBASE tx as top tx. - AVG_TOP = 7; -} - -/** - * Standard Ethereum Fee, supported by majority of forks and by Ethereum Mainnet before EIP-1559 - */ -message EthereumStdFees { - // Big Number encoded as string. Fee value in Wei - string fee = 1; -} - -/** - * Ethereum Fee for EIP-1559 compatible forks - */ -message EthereumExtFees { - // Big Number encoded as string. Estimated fee that expected to be actually paid. I.e. it's the Base Fee + Priority Fee - string expect = 1; - // Big Number encoded as string. Priority Fee in Wei - string priority = 2; - // Big Number encoded as string. Max Fee value in Wei. Note that it only indicates the current preference, and the actual Max may be significantly lower, depending on the usage scenario. - string max = 3; -} - -/** - * Standard Bitcoin Fee - */ -message BitcoinStdFees { - // Fee in Satoshi per Kilobyte. Note that the actual fee calculation MUST divide it by 1024 at the last step to get a fair fee. - uint64 satPerKb = 1; -} diff --git a/proto/common.proto b/proto/common.proto deleted file mode 100644 index 5d299d7e..00000000 --- a/proto/common.proto +++ /dev/null @@ -1,74 +0,0 @@ -syntax = "proto3"; -package emerald; -option java_package = "io.emeraldpay.api.proto"; - -message Chain { - ChainRef type = 1; -} - -enum ChainRef { - CHAIN_UNSPECIFIED = 0; - - CHAIN_BITCOIN = 1; - // CHAIN_GRIN = 2; - - CHAIN_ETHEREUM = 100; - CHAIN_ETHEREUM_CLASSIC = 101; - CHAIN_FANTOM = 102; // Fantom, https://fantom.foundation/ - - // Sidechains and state channels start with 1_000 - // CHAIN_LIGHTNING = 1001; - CHAIN_MATIC = 1002; // Matic PoS Ethereum sidechain based on Polygon - CHAIN_RSK = 1003; // RSK sidechain, https://www.rsk.co/ - - // Testnets start with 10_000 - CHAIN_MORDEN = 10001; - CHAIN_KOVAN = 10002; - CHAIN_TESTNET_BITCOIN = 10003; - // CHAIN_FLOONET = 10004; - CHAIN_GOERLI = 10005; - CHAIN_ROPSTEN = 10006; - CHAIN_RINKEBY = 10007; - - // Non-standard starts from 20_000 -} - -message SingleAddress { - string address = 1; -} - -message XpubAddress { - bytes xpub = 1; - string path = 2; - uint64 start = 3; - uint64 limit = 4; -} - -message MultiAddress { - repeated SingleAddress addresses = 1; -} - -message ReferenceAddress { - uint64 refid = 1; -} - -message AnyAddress { - oneof addr_type { - SingleAddress address_single = 1; - MultiAddress address_multi = 2; - XpubAddress address_xpub = 3; - ReferenceAddress address_ref = 4; - } -} - -message Asset { - ChainRef chain = 1; - string code = 2; -} - -message BlockInfo { - uint64 height = 1; - string block_id = 2; - uint64 timestamp = 3; - bytes weight = 4; -} \ No newline at end of file diff --git a/src/main/kotlin/io/emeraldpay/dshackle/BlockchainType.kt b/src/main/kotlin/io/emeraldpay/dshackle/BlockchainType.kt new file mode 100644 index 00000000..c4993d76 --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/BlockchainType.kt @@ -0,0 +1,36 @@ +package io.emeraldpay.dshackle + +enum class BlockchainType { + BITCOIN, EVM_POW, EVM_POS; + + companion object { + @JvmStatic + fun from(chain: Chain): BlockchainType { + if (chain == Chain.TESTNET_ROPSTEN || + chain == Chain.POLYGON || + chain == Chain.OPTIMISM || + chain == Chain.BSC || + chain == Chain.TESTNET_GOERLI || + chain == Chain.ETHEREUM + ) { + return EVM_POS + } + if (chain == Chain.ETHEREUM_CLASSIC || + chain == Chain.ARBITRUM || + chain == Chain.FANTOM || + chain == Chain.RSK || + chain == Chain.TESTNET_KOVAN || + chain == Chain.TESTNET_MORDEN || + chain == Chain.TESTNET_RINKEBY + ) { + return EVM_POW + } + if (chain == Chain.BITCOIN || + chain == Chain.TESTNET_BITCOIN + ) { + return BITCOIN + } + throw IllegalArgumentException("Unknown type of blockchain: $chain") + } + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Chain.kt b/src/main/kotlin/io/emeraldpay/dshackle/Chain.kt new file mode 100644 index 00000000..c714d97e --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/Chain.kt @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2016-2019 ETCDEV GmbH, All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.emeraldpay.dshackle + +enum class Chain(val id: Int, val chainCode: String, val chainName: String) { + UNSPECIFIED(0, "UNSPECIFIED", "Unknown"), + BITCOIN(1, "BTC", "Bitcoin"), // GRIN(2, "GRIN", "Grin"), + + // Networks with tokens + ETHEREUM(100, "ETH", "Ethereum"), + ETHEREUM_CLASSIC(101, "ETC", "Ethereum Classic"), + FANTOM( + 102, + "FTM", + "Fantom" + ), // LIGHTNING(1001, "BTC_LN", "Bitcoin Lightning"), + POLYGON(1002, "POLYGON", "Polygon Matic"), + RSK(1003, "RSK", "Bitcoin RSK"), + ARBITRUM( + 1004, + "ARBITRUM", + "Arbitrum" + ), + OPTIMISM(1005, "OPTIMISM", "Optimism"), + BSC(1006, "BSC", "Binance Smart Chain"), // Testnets + TESTNET_MORDEN(10001, "MORDEN", "Morden Testnet"), + TESTNET_KOVAN(10002, "KOVAN", "Kovan Testnet"), + TESTNET_BITCOIN( + 10003, + "TESTNET_BITCOIN", + "Bitcoin Testnet" + ), // TESTNET_FLOONET(10004, "FLOONET", "Floonet Testnet"), + TESTNET_GOERLI(10005, "GOERLI", "Goerli Testnet"), + TESTNET_ROPSTEN( + 10006, + "ROPSTEN", + "Ropsten Testnet" + ), + TESTNET_RINKEBY(10007, "RINKEBY", "Rinkeby Testnet"); + + companion object { + fun byId(id: Int): Chain { + for (chain in values()) { + if (chain.id == id) { + return chain + } + } + return UNSPECIFIED + } + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt b/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt index ce947786..a4ea2665 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt @@ -16,7 +16,6 @@ package io.emeraldpay.dshackle import io.emeraldpay.api.proto.Common -import io.emeraldpay.grpc.Chain import java.util.EnumMap import java.util.concurrent.locks.ReentrantLock import kotlin.concurrent.withLock diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt index 29ff88cc..7be3c202 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Global.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Global.kt @@ -27,7 +27,6 @@ import io.emeraldpay.dshackle.upstream.bitcoin.data.RpcUnspent import io.emeraldpay.dshackle.upstream.bitcoin.data.RpcUnspentDeserializer import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone diff --git a/src/main/kotlin/io/emeraldpay/dshackle/SilentException.kt b/src/main/kotlin/io/emeraldpay/dshackle/SilentException.kt index e92e67f1..8c1e9ad2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/SilentException.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/SilentException.kt @@ -16,7 +16,6 @@ package io.emeraldpay.dshackle import io.emeraldpay.dshackle.upstream.Selector -import io.emeraldpay.grpc.Chain /** * Exception that should be handled/logged without a stacktrace in production diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt index c4c421e8..be7b4b17 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt @@ -16,12 +16,12 @@ package io.emeraldpay.dshackle.cache import com.google.protobuf.ByteString +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.proto.CachesProto import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain import io.lettuce.core.api.reactive.RedisReactiveCommands import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt index c37b2aca..99e1fcd6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt @@ -15,8 +15,8 @@ */ package io.emeraldpay.dshackle.cache +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.CacheConfig -import io.emeraldpay.grpc.Chain import io.lettuce.core.RedisClient import io.lettuce.core.RedisConnectionException import io.lettuce.core.RedisURI @@ -42,7 +42,7 @@ open class CachesFactory( } private var redis: StatefulRedisConnection? = null - private val all = EnumMap(io.emeraldpay.grpc.Chain::class.java) + private val all = EnumMap(Chain::class.java) @PostConstruct fun init() { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt index c9c37dca..4ccaa13b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt @@ -15,10 +15,10 @@ */ package io.emeraldpay.dshackle.cache +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain import io.lettuce.core.api.reactive.RedisReactiveCommands import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt index b4f99c8c..44006440 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt @@ -16,12 +16,12 @@ package io.emeraldpay.dshackle.cache import com.google.protobuf.ByteString +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.proto.CachesProto import io.emeraldpay.dshackle.proto.CachesProto.ValueContainer import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain import io.lettuce.core.api.reactive.RedisReactiveCommands import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt index 912ffc1d..51dc2ec9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt @@ -16,12 +16,12 @@ package io.emeraldpay.dshackle.cache import com.google.protobuf.ByteString +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.proto.CachesProto import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Head -import io.emeraldpay.grpc.Chain import io.lettuce.core.api.reactive.RedisReactiveCommands import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt index 3ffad9e7..0e648c15 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt @@ -15,10 +15,10 @@ */ package io.emeraldpay.dshackle.cache +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.DefaultContainer import io.emeraldpay.dshackle.proto.CachesProto import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson -import io.emeraldpay.grpc.Chain import io.lettuce.core.api.reactive.RedisReactiveCommands import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt index 2daae9d1..0fc40ab9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt @@ -16,13 +16,13 @@ package io.emeraldpay.dshackle.cache import com.google.protobuf.ByteString +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.data.TxContainer import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.proto.CachesProto import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain import io.lettuce.core.api.reactive.RedisReactiveCommands import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt index cf81781c..2a772390 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.config -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain class HealthConfig { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfigReader.kt index 901c443d..fb6a23f7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfigReader.kt @@ -15,8 +15,8 @@ */ package io.emeraldpay.dshackle.config +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.yaml.snakeyaml.nodes.CollectionNode import org.yaml.snakeyaml.nodes.MappingNode diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt index c5a47254..ddca3a67 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt @@ -16,7 +16,7 @@ */ package io.emeraldpay.dshackle.config -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain /** * Configure HTTP Proxy to Upstreams diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfigReader.kt index 0dc6b4a6..9c53dca1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfigReader.kt @@ -16,8 +16,8 @@ */ package io.emeraldpay.dshackle.config +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global -import io.emeraldpay.grpc.Chain import org.apache.commons.lang3.StringUtils import org.slf4j.LoggerFactory import org.yaml.snakeyaml.nodes.MappingNode diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt index d0944965..afa485e3 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt @@ -15,9 +15,9 @@ */ package io.emeraldpay.dshackle.config +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.Address -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain class TokensConfig( val tokens: List diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt index 3329f93e..c3925848 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt @@ -1,13 +1,13 @@ package io.emeraldpay.dshackle.config.context +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.CachesFactory import io.emeraldpay.dshackle.upstream.CallTargetsHolder import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.springframework.beans.factory.config.ConfigurableListableBeanFactory import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt index 4b525349..7cea5cf2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt @@ -1,9 +1,9 @@ package io.emeraldpay.dshackle.monitoring.accesslog import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.MainConfig import io.emeraldpay.dshackle.rpc.NativeCall -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt index c08aabc5..f69f9a4a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.monitoring.accesslog import com.fasterxml.jackson.annotation.JsonInclude -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.slf4j.LoggerFactory import java.time.Instant import java.util.UUID diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt index 9b588d40..4049570a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt @@ -17,8 +17,8 @@ package io.emeraldpay.dshackle.monitoring.accesslog import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.AccessLogConfig -import io.emeraldpay.grpc.Chain import io.grpc.Attributes import io.grpc.Grpc import io.grpc.Metadata diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt index 7025260e..ba31cdae 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt @@ -17,9 +17,9 @@ package io.emeraldpay.dshackle.proxy import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall -import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt index 56f52313..aff381e9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt @@ -15,13 +15,13 @@ */ package io.emeraldpay.dshackle.proxy +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.ProxyConfig import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.grpc.Chain import io.netty.buffer.ByteBuf import io.netty.buffer.Unpooled import org.reactivestreams.Publisher diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt index 9d84e9d0..4061e182 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt @@ -16,13 +16,13 @@ */ package io.emeraldpay.dshackle.proxy +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.TlsSetup import io.emeraldpay.dshackle.config.ProxyConfig import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.rpc.NativeSubscribe -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Timer diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt index e15be1ba..43928632 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt @@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.proxy import com.google.protobuf.ByteString import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.BlockchainOuterClass.Selector +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.ProxyConfig import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp @@ -25,7 +26,6 @@ import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.rpc.NativeSubscribe import io.emeraldpay.etherjar.rpc.json.RequestJson import io.emeraldpay.etherjar.rpc.json.ResponseJson -import io.emeraldpay.grpc.Chain import io.netty.buffer.ByteBufInputStream import io.netty.buffer.Unpooled import org.reactivestreams.Publisher diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt index 10e7f108..15607fae 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt @@ -19,9 +19,9 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.ChainValue import io.emeraldpay.dshackle.SilentException -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Timer diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt index 8328c45e..04c5207e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt @@ -1,9 +1,9 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.upstream.ChainFees import io.emeraldpay.dshackle.upstream.MultistreamHolder -import io.emeraldpay.grpc.Chain import io.grpc.Status import io.grpc.StatusException import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 93926399..288bfcb6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -19,6 +19,8 @@ package io.emeraldpay.dshackle.rpc import com.fasterxml.jackson.databind.ObjectMapper import com.google.protobuf.ByteString import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.quorum.CallQuorum @@ -39,8 +41,6 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.dshackle.upstream.signature.ResponseSigner import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.etherjar.rpc.RpcResponseError -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Metrics import org.apache.commons.lang3.StringUtils import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt index 6edd8027..4f7e23a9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt @@ -18,6 +18,8 @@ package io.emeraldpay.dshackle.rpc import com.google.protobuf.ByteString import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.BlockchainOuterClass.NativeSubscribeReplyItem +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.upstream.MultistreamHolder @@ -25,8 +27,6 @@ import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.HasUpstream import io.emeraldpay.dshackle.upstream.signature.ResponseSigner -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import io.grpc.Status import io.grpc.StatusException import org.reactivestreams.Publisher diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt index 9aad6002..b8384c8e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt @@ -19,9 +19,9 @@ package io.emeraldpay.dshackle.rpc import com.google.protobuf.ByteString import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.upstream.MultistreamHolder -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt index 74ed1b27..5b75f605 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt @@ -18,10 +18,10 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.UpstreamAvailability -import io.emeraldpay.grpc.Chain import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackAddress.kt index df7d0210..005aed42 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackAddress.kt @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.core.publisher.Flux /** diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt index d64b493c..9df5ed7d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt @@ -18,6 +18,8 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.startup.UpstreamChangeEvent @@ -27,8 +29,6 @@ import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent import io.emeraldpay.dshackle.upstream.grpc.BitcoinGrpcUpstream -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.apache.commons.lang3.StringUtils import org.bitcoinj.params.MainNetParams import org.bitcoinj.params.TestNet3Params diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt index 6a0e0b3d..aec22cc7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt @@ -17,12 +17,12 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.bitcoin.ExtractBlock -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt index 6de9b522..86d47329 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt @@ -17,6 +17,8 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.config.TokensConfig import io.emeraldpay.dshackle.upstream.MultistreamHolder @@ -26,8 +28,6 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.EventId import io.emeraldpay.etherjar.erc20.ERC20Token -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt index 4bef295d..28359419 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt @@ -18,14 +18,14 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.Wei -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt index 75401d78..d37af85b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt @@ -18,6 +18,8 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.SilentException import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.TxId @@ -29,8 +31,6 @@ import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackTx.kt index 4fe8b3a6..3b851152 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackTx.kt @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.core.publisher.Flux interface TrackTx { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index 51aed124..1cfc3a57 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -17,6 +17,8 @@ package io.emeraldpay.dshackle.startup import com.google.common.annotations.VisibleForTesting +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.FileResolver import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.UpstreamsConfig @@ -41,8 +43,6 @@ import io.emeraldpay.dshackle.upstream.forkchoice.NoChoiceWithPriorityForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstreams import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.boot.ApplicationArguments import org.springframework.boot.ApplicationRunner diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt index 34bcc8bf..1b8f35de 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt @@ -16,10 +16,10 @@ */ package io.emeraldpay.dshackle.startup +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.upstream.Upstream -import io.emeraldpay.grpc.Chain /** * An update event to the list of currently available upstreams. diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt index 2ad03f39..f868c8b0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CallTargetsHolder.kt @@ -1,10 +1,10 @@ package io.emeraldpay.dshackle.upstream +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import org.springframework.stereotype.Component import java.util.HashMap diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index 54a152b3..a15ead29 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -16,7 +16,7 @@ */ package io.emeraldpay.dshackle.upstream -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.slf4j.LoggerFactory import org.springframework.stereotype.Component import javax.annotation.PreDestroy diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/FilteredApis.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/FilteredApis.kt index 36ee6615..ab53deed 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/FilteredApis.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/FilteredApis.kt @@ -16,9 +16,9 @@ */ package io.emeraldpay.dshackle.upstream +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.UpstreamsConfig -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.DistributionSummary import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Tag diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpFactory.kt index 359476ed..ea6359b7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpFactory.kt @@ -1,9 +1,9 @@ package io.emeraldpay.dshackle.upstream +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain interface HttpFactory { fun create(id: String?, chain: Chain): Reader diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt index adf0aafd..a0f97c8c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt @@ -1,12 +1,12 @@ package io.emeraldpay.dshackle.upstream +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.AuthConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcHttpClient import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Tag diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index b6de244c..4e239048 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -16,6 +16,7 @@ */ package io.emeraldpay.dshackle.upstream +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.config.UpstreamsConfig @@ -25,7 +26,6 @@ import io.emeraldpay.dshackle.upstream.calls.AggregatedCallMethods import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Tag import org.apache.commons.collections4.Factory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt index 80b4e564..b2c0a753 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt @@ -16,7 +16,7 @@ */ package io.emeraldpay.dshackle.upstream -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain /** * Holds Multistreams configured for a chain. diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt index aca3d567..3393fd82 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinMultistream.kt @@ -15,6 +15,7 @@ */ package io.emeraldpay.dshackle.upstream.bitcoin +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader @@ -24,7 +25,6 @@ import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt index 23b82f35..2f500bf8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcUpstream.kt @@ -15,6 +15,7 @@ */ package io.emeraldpay.dshackle.upstream.bitcoin +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.startup.QuorumForLabels @@ -26,7 +27,6 @@ import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import reactor.core.Disposable diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinUpstream.kt index b09709ff..330d645e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinUpstream.kt @@ -15,12 +15,12 @@ */ package io.emeraldpay.dshackle.upstream.bitcoin +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory abstract class BitcoinUpstream( diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index 6f78cfe0..29994819 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -16,6 +16,7 @@ */ package io.emeraldpay.dshackle.upstream.calls +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.quorum.AlwaysQuorum import io.emeraldpay.dshackle.quorum.BroadcastQuorum @@ -23,7 +24,6 @@ import io.emeraldpay.dshackle.quorum.CallQuorum import io.emeraldpay.dshackle.quorum.NonceQuorum import io.emeraldpay.dshackle.quorum.NotLaggingQuorum import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.grpc.Chain /** * Default configuration for Ethereum based RPC. Defines optimal Quorum strategies for different methods, and provides diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt index fd7f4cf3..69bb9ac7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumMultistream.kt @@ -17,6 +17,7 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader @@ -26,7 +27,6 @@ import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.util.ConcurrentReferenceHashMap import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt index bb2479df..164c60ee 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt @@ -16,6 +16,7 @@ */ package io.emeraldpay.dshackle.upstream.ethereum +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.config.UpstreamsConfig @@ -29,7 +30,6 @@ import io.emeraldpay.dshackle.upstream.ethereum.connectors.ConnectorFactory import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.context.Lifecycle import reactor.core.Disposable diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsFactory.kt index fee1674d..9d926b5b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsFactory.kt @@ -16,11 +16,11 @@ */ package io.emeraldpay.dshackle.upstream.ethereum +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.config.AuthConfig import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics -import io.emeraldpay.grpc.Chain import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Tag diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt index 0e0d21e5..5dc4100e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt @@ -1,8 +1,8 @@ package io.emeraldpay.dshackle.upstream.ethereum.connectors +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstreamValidator -import io.emeraldpay.grpc.Chain interface ConnectorFactory { fun create(upstream: DefaultUpstream, validator: EthereumUpstreamValidator, chain: Chain): EthereumConnector diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt index f23efb6f..c5393408 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt @@ -1,12 +1,12 @@ package io.emeraldpay.dshackle.upstream.ethereum.connectors +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.upstream.BlockValidator import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.HttpFactory import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstreamValidator import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsFactory import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory open class EthereumConnectorFactory( diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt index 71477c37..252ce212 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosMultiStream.kt @@ -17,6 +17,7 @@ package io.emeraldpay.dshackle.upstream.ethereum import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.reader.Reader @@ -26,7 +27,6 @@ import io.emeraldpay.dshackle.upstream.forkchoice.PriorityForkChoice import io.emeraldpay.dshackle.upstream.grpc.GrpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import org.springframework.util.ConcurrentReferenceHashMap import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt index 78ce2c24..504db013 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt @@ -16,6 +16,7 @@ */ package io.emeraldpay.dshackle.upstream.ethereum +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.cache.CachesEnabled import io.emeraldpay.dshackle.config.UpstreamsConfig @@ -30,7 +31,6 @@ import io.emeraldpay.dshackle.upstream.ethereum.connectors.ConnectorFactory import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import reactor.core.Disposable diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt index 35397e43..09ac0b5d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt @@ -17,6 +17,7 @@ package io.emeraldpay.dshackle.upstream.grpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.data.BlockContainer @@ -35,7 +36,6 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt index c0427a06..6c40e2a0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt @@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.upstream.grpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.data.BlockContainer @@ -38,7 +39,6 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt index 72c03c28..f180bb6a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt @@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.upstream.grpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.data.BlockContainer @@ -38,7 +39,6 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory import reactor.core.publisher.Flux diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt index 78883e1c..aaf16960 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt @@ -18,6 +18,7 @@ package io.emeraldpay.dshackle.upstream.grpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.upstream.AbstractHead @@ -25,7 +26,6 @@ import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice -import io.emeraldpay.grpc.Chain import org.reactivestreams.Publisher import org.slf4j.LoggerFactory import reactor.core.Disposable diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt index f74cb62c..e49a38d6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt @@ -18,6 +18,8 @@ package io.emeraldpay.dshackle.upstream.grpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Defaults import io.emeraldpay.dshackle.FileResolver import io.emeraldpay.dshackle.config.AuthConfig @@ -27,8 +29,6 @@ import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain import io.grpc.ManagedChannelBuilder import io.grpc.netty.NettyChannelBuilder import io.micrometer.core.instrument.Counter diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt index 8465f0c3..08f7e0f4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt @@ -19,13 +19,13 @@ import com.google.protobuf.ByteString import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.BlockchainOuterClass.NativeCallReplySignature import io.emeraldpay.api.proto.ReactorBlockchainGrpc +import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.signature.ResponseSigner import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.etherjar.rpc.RpcResponseError -import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory import reactor.core.publisher.Mono import java.util.concurrent.TimeUnit diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy index 31bcf2a9..ba4ef7eb 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/BlocksRedisCacheSpec.groovy @@ -21,7 +21,7 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.test.IntegrationTestingCommons -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/HeightByHashRedisCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/HeightByHashRedisCacheSpec.groovy index 632dcad2..b9b0c5cb 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/HeightByHashRedisCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/HeightByHashRedisCacheSpec.groovy @@ -18,7 +18,7 @@ package io.emeraldpay.dshackle.cache import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.test.IntegrationTestingCommons -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.lettuce.core.api.StatefulRedisConnection import spock.lang.IgnoreIf import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/ReceiptRedisCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/ReceiptRedisCacheSpec.groovy index 4aa587bf..8138052b 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/ReceiptRedisCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/ReceiptRedisCacheSpec.groovy @@ -6,7 +6,7 @@ import io.emeraldpay.dshackle.data.BlockId import io.emeraldpay.dshackle.data.DefaultContainer import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.test.IntegrationTestingCommons -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson diff --git a/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy index d0f93344..bc3401ef 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/cache/TxRedisCacheSpec.groovy @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.data.TxContainer import io.emeraldpay.dshackle.data.TxId import io.emeraldpay.dshackle.test.IntegrationTestingCommons import io.emeraldpay.dshackle.test.TestingCommons -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.domain.Wei diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/HealthConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/HealthConfigReaderSpec.groovy index 6add6d56..a340c75c 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/HealthConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/HealthConfigReaderSpec.groovy @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.config -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class HealthConfigReaderSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/MainConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/MainConfigReaderSpec.groovy index f8fbdd7a..89d48c42 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/MainConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/MainConfigReaderSpec.groovy @@ -17,7 +17,7 @@ package io.emeraldpay.dshackle.config import io.emeraldpay.dshackle.test.TestingCommons -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class MainConfigReaderSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/ProxyConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/ProxyConfigReaderSpec.groovy index 076bcdda..8d2f827d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/ProxyConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/ProxyConfigReaderSpec.groovy @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.config -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class ProxyConfigReaderSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/TokensConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/TokensConfigReaderSpec.groovy index 4ef8c3a4..2d67314e 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/TokensConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/TokensConfigReaderSpec.groovy @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.config -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class TokensConfigReaderSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy index c4772852..42579e9a 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/monitoring/HealthCheckSetupSpec.groovy @@ -20,7 +20,7 @@ import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class HealthCheckSetupSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriterSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriterSpec.groovy index 38dedfb9..2754363f 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriterSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriterSpec.groovy @@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.AccessLogConfig import io.emeraldpay.dshackle.config.MainConfig -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification import java.time.Instant diff --git a/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBaseBuilderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBaseBuilderSpec.groovy index a8375ac6..6c5c5c42 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBaseBuilderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBaseBuilderSpec.groovy @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.monitoring.accesslog import io.emeraldpay.api.proto.BlockchainOuterClass -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.grpc.Attributes import io.grpc.Grpc import io.grpc.Metadata diff --git a/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilderSubscribeBalanceSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilderSubscribeBalanceSpec.groovy index 75d78f5a..aca4439e 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilderSubscribeBalanceSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilderSubscribeBalanceSpec.groovy @@ -2,7 +2,7 @@ package io.emeraldpay.dshackle.monitoring.accesslog import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class EventsBuilderSubscribeBalanceSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/proxy/BaseHandlerSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/proxy/BaseHandlerSpec.groovy index 9fb32de3..9b052705 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/proxy/BaseHandlerSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/proxy/BaseHandlerSpec.groovy @@ -18,7 +18,7 @@ package io.emeraldpay.dshackle.proxy import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.jetbrains.annotations.NotNull import reactor.core.publisher.Flux import reactor.core.publisher.Mono diff --git a/src/test/groovy/io/emeraldpay/dshackle/proxy/HttpHandlerSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/proxy/HttpHandlerSpec.groovy index 69e5e8a7..79def24b 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/proxy/HttpHandlerSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/proxy/HttpHandlerSpec.groovy @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.rpc.RpcException -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.micrometer.core.instrument.Counter import io.micrometer.core.instrument.step.StepCounter import reactor.core.publisher.Flux diff --git a/src/test/groovy/io/emeraldpay/dshackle/proxy/ProxyServerSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/proxy/ProxyServerSpec.groovy index 3340ef2d..ba9bf779 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/proxy/ProxyServerSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/proxy/ProxyServerSpec.groovy @@ -6,7 +6,7 @@ import io.emeraldpay.dshackle.config.ProxyConfig import io.emeraldpay.dshackle.monitoring.accesslog.AccessHandlerHttp import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.rpc.NativeSubscribe -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.netty.http.server.HttpServerRoutes import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy index 235f4778..b017ac24 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/proxy/WebsocketHandlerSpec.groovy @@ -20,7 +20,7 @@ import io.emeraldpay.dshackle.rpc.NativeCall import io.emeraldpay.dshackle.rpc.NativeSubscribe import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.etherjar.rpc.json.RequestJson -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.micrometer.core.instrument.Counter import reactor.core.publisher.Flux import reactor.core.publisher.Sinks diff --git a/src/test/groovy/io/emeraldpay/dshackle/quorum/QuorumRpcReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/quorum/QuorumRpcReaderSpec.groovy index c69450ca..a3f255d2 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/quorum/QuorumRpcReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/quorum/QuorumRpcReaderSpec.groovy @@ -25,7 +25,7 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcException import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.rpc.RpcResponseError -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.rpc.RpcException import reactor.core.publisher.Mono import reactor.test.StepVerifier diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 93cc1fbc..28fa74cd 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -37,7 +37,7 @@ import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.dshackle.upstream.signature.ResponseSigner -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.rpc.RpcException import io.emeraldpay.etherjar.rpc.RpcResponseError import reactor.core.publisher.Flux diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeSubscribeSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeSubscribeSpec.groovy index 5793c17c..d589c48d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeSubscribeSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeSubscribeSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.ethereum.EthereumSubscribe import io.emeraldpay.dshackle.upstream.signature.NoSigner -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.core.publisher.Flux import reactor.test.StepVerifier import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy index b5880354..88e94cc3 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy @@ -26,7 +26,7 @@ import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.test.MultistreamHolderMock import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/SubscribeStatusSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/SubscribeStatusSpec.groovy index cb1b952d..082263c1 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/SubscribeStatusSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/SubscribeStatusSpec.groovy @@ -6,7 +6,7 @@ import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.core.publisher.Mono import reactor.test.StepVerifier import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinAddressSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinAddressSpec.groovy index b1d9f7c1..fabbf663 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinAddressSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinAddressSpec.groovy @@ -30,7 +30,7 @@ import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinReader import io.emeraldpay.dshackle.upstream.bitcoin.XpubAddresses import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.bitcoinj.core.Address import org.bitcoinj.params.MainNetParams import org.bitcoinj.params.TestNet3Params diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinTxSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinTxSpec.groovy index a4f6e5df..8e9a26ef 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinTxSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackBitcoinTxSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinMultistream import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinReader import io.emeraldpay.dshackle.upstream.bitcoin.CachingMempoolData -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.test.StepVerifier diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy index 86fc1553..4c3a90af 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy @@ -14,7 +14,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.hex.Hex32 -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.erc20.ERC20Token import io.emeraldpay.etherjar.hex.HexData diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy index 05dc3aa9..cb98adb1 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumAddressSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.data.BlockContainer import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.test.MultistreamHolderMock import io.emeraldpay.dshackle.upstream.MultistreamHolder -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson import reactor.test.StepVerifier diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy index 178b794f..e8d5c3fc 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackEthereumTxSpec.groovy @@ -28,7 +28,7 @@ import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.rpc.json.BlockJson diff --git a/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy index f799729d..286458c1 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/startup/ConfiguredUpstreamsSpec.groovy @@ -8,7 +8,7 @@ import io.emeraldpay.dshackle.upstream.CallTargetsHolder import io.emeraldpay.dshackle.upstream.CurrentMultistreamHolder import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.springframework.context.ApplicationEventPublisher import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/ConnectorFactoryMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/ConnectorFactoryMock.groovy index 34d7e3d6..25010d0d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/ConnectorFactoryMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/ConnectorFactoryMock.groovy @@ -8,7 +8,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.connectors.ConnectorFactory import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain class ConnectorFactoryMock implements ConnectorFactory { Reader api diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumPosRpcUpstreamMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumPosRpcUpstreamMock.groovy index e611b3d9..52ffe3fb 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumPosRpcUpstreamMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumPosRpcUpstreamMock.groovy @@ -31,7 +31,7 @@ import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.jetbrains.annotations.NotNull import org.reactivestreams.Publisher diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy index 369dc612..4a490d5a 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy @@ -30,7 +30,7 @@ import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.jetbrains.annotations.NotNull import org.reactivestreams.Publisher diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy index e26cc9f7..81abb838 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy @@ -30,10 +30,9 @@ import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosMultiStream import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream import io.emeraldpay.dshackle.upstream.ethereum.EthereumReader -import io.emeraldpay.grpc.BlockchainType -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.BlockchainType +import io.emeraldpay.dshackle.Chain import org.jetbrains.annotations.NotNull -import reactor.core.publisher.Flux class MultistreamHolderMock implements MultistreamHolder { diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index 7bfab88c..a6e4c114 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -33,7 +33,7 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.micrometer.core.instrument.MeterRegistry import io.micrometer.core.instrument.logging.LoggingMeterRegistry import org.apache.commons.lang3.StringUtils diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy index 4e488e9d..1a9b8179 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy @@ -19,7 +19,7 @@ import io.emeraldpay.dshackle.startup.UpstreamChangeEvent import io.emeraldpay.dshackle.test.EthereumPosRpcUpstreamMock import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class CurrentMultistreamHolderSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy index ecec9e4b..61a21bbf 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy @@ -24,7 +24,7 @@ import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.test.StepVerifier import spock.lang.Retry import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy index 8a28f4b3..2f54b1b0 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy @@ -33,7 +33,7 @@ import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import org.jetbrains.annotations.NotNull import reactor.core.publisher.Flux import reactor.core.publisher.Mono diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy index e58d3baf..4f8febda 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethodsSpec.groovy @@ -1,6 +1,6 @@ package io.emeraldpay.dshackle.upstream.calls -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class DefaultEthereumMethodsSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethodsSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethodsSpec.groovy index 580c9669..8c1d5afd 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethodsSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethodsSpec.groovy @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.quorum.NonceQuorum import io.emeraldpay.dshackle.quorum.NotLaggingQuorum import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification class ManagedCallMethodsSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceSpec.groovy index 8de66c50..6570bad1 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceSpec.groovy @@ -27,7 +27,7 @@ import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.erc20.ERC20Token import io.emeraldpay.etherjar.hex.HexData import io.emeraldpay.etherjar.rpc.json.TransactionCallJson -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import spock.lang.Specification import java.time.Duration diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReaderSpec.groovy index 78bcbe27..d4f17cd0 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReaderSpec.groovy @@ -11,7 +11,7 @@ import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumReaderSpec.groovy index 30a273d1..c824e25f 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumReaderSpec.groovy @@ -29,7 +29,7 @@ import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.Address import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/LocalCallRouterSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/LocalCallRouterSpec.groovy index fb84642b..c936b8b3 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/LocalCallRouterSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/LocalCallRouterSpec.groovy @@ -9,7 +9,7 @@ import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.rpc.json.BlockJson import org.apache.commons.collections4.functors.ConstantFactory import reactor.core.publisher.Mono diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionRealSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionRealSpec.groovy index eb3f22c0..2b9412af 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionRealSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionRealSpec.groovy @@ -4,7 +4,7 @@ import io.emeraldpay.dshackle.test.MockWSServer import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.test.StepVerifier import spock.lang.Shared import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy index b8996287..5fc78e37 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionSpec.groovy @@ -25,7 +25,7 @@ import io.emeraldpay.etherjar.rpc.RpcResponseError import io.emeraldpay.etherjar.rpc.json.BlockJson import io.emeraldpay.etherjar.rpc.json.TransactionJson import io.emeraldpay.etherjar.rpc.json.TransactionRefJson -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import reactor.core.publisher.Flux import reactor.test.StepVerifier import spock.lang.Specification diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy index af98978b..e13f355e 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstreamSpec.groovy @@ -29,7 +29,7 @@ import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient import io.emeraldpay.dshackle.upstream.rpcclient.RpcMetrics -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.grpc.stub.StreamObserver import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/GrpcHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/GrpcHeadSpec.groovy index 0f8a1e49..638e51ef 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/GrpcHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/GrpcHeadSpec.groovy @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.test.MockGrpcServer import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice -import io.emeraldpay.grpc.Chain +import io.emeraldpay.dshackle.Chain import io.grpc.stub.StreamObserver import reactor.test.StepVerifier import spock.lang.Specification From 2cb65deb907bca947fd084f8682c095e4ea38020 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 18:16:05 +0400 Subject: [PATCH 12/20] remove another copy of proto api submodule --- .gitmodules | 3 --- dshackle-cli/grpc | 1 - 2 files changed, 4 deletions(-) delete mode 160000 dshackle-cli/grpc diff --git a/.gitmodules b/.gitmodules index 44248f44..a1bffe35 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "dshackle-cli/grpc"] - path = dshackle-cli/grpc - url = https://github.com/p2p-org/emerald-grpc.git [submodule "emerald-grpc"] path = emerald-grpc url = git@github.com:p2p-org/emerald-grpc.git diff --git a/dshackle-cli/grpc b/dshackle-cli/grpc deleted file mode 160000 index 4060e539..00000000 --- a/dshackle-cli/grpc +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 4060e53997b32121670617595bad7b4276f599e8 From 6f3f9cf7b3c92cd170fa68771d981360d54581ca Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 18:16:38 +0400 Subject: [PATCH 13/20] rm nix --- nix/default.nix | 45 ------ nix/lib/force_cached.nix | 38 ----- nix/mkEnv.nix | 29 ---- nix/nixpkgs.nix | 9 -- nix/pkgs/protoc-gen-grpc-java/default.nix | 23 ---- nix/release.nix | 16 --- nix/sources.json | 14 -- nix/sources.nix | 160 ---------------------- 8 files changed, 334 deletions(-) delete mode 100644 nix/default.nix delete mode 100644 nix/lib/force_cached.nix delete mode 100644 nix/mkEnv.nix delete mode 100644 nix/nixpkgs.nix delete mode 100644 nix/pkgs/protoc-gen-grpc-java/default.nix delete mode 100644 nix/release.nix delete mode 100644 nix/sources.json delete mode 100644 nix/sources.nix diff --git a/nix/default.nix b/nix/default.nix deleted file mode 100644 index a1941c4e..00000000 --- a/nix/default.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ system ? builtins.currentSystem -, nixpkgs ? import ./nixpkgs.nix { inherit system; } -}: -let - mkEnv = nixpkgs.callPackage ./mkEnv.nix { }; -in -rec { - inherit - nixpkgs - ; - - protoc-gen-grpc-java = nixpkgs.callPackage ./pkgs/protoc-gen-grpc-java { }; - - env = mkEnv { - env = { - # Configure nix to use nixpgks - NIX_PATH = "nixpkgs=${toString nixpkgs.path}"; - # Set the env for gradle - JAVA_HOME = "@env-root@/lib/openjdk"; - }; - - paths = [ - # Development tools - nixpkgs.gitAndTools.git-absorb - nixpkgs.jq - nixpkgs.niv - nixpkgs.websocat - nixpkgs.yq - - # Protobuf stuff - nixpkgs.protobuf3_9 - protoc-gen-grpc-java - - # Code formatting - nixpkgs.treefmt - nixpkgs.nixpkgs-fmt - nixpkgs.shfmt - - nixpkgs.jdk - nixpkgs.coreutils - nixpkgs.gnugrep - nixpkgs.which - ]; - }; -} diff --git a/nix/lib/force_cached.nix b/nix/lib/force_cached.nix deleted file mode 100644 index 0e416d51..00000000 --- a/nix/lib/force_cached.nix +++ /dev/null @@ -1,38 +0,0 @@ -# Source https://github.com/Mic92/nix-build-uncached/blob/master/scripts/force_cached.nix -coreutils: attrs: -with builtins; -let - # Copied from - isDerivation = x: isAttrs x && x ? type && x.type == "derivation"; - - # Return true if `nix-build` would traverse that attribute set to look for - # more derivations to build. - hasRecurseIntoAttrs = x: isAttrs x && (x.recurseForDerivations or false); - - # Wraps derivations that disallow substitutes so that they can be cached. - toCachedDrv = drv: - if !(drv.allowSubstitutes or true) then - derivation - { - name = "${drv.name}-to-cached"; - system = drv.system; - builder = "/bin/sh"; - args = [ "-c" "${coreutils}/bin/ln -s ${drv} $out; exit 0" ]; - } - else - drv; - - op = _: val: - if isDerivation val then - toCachedDrv val - else if hasRecurseIntoAttrs val then - forceCached val - else - val - ; - - # Traverses a tree of derivation and wrap all of those that disallow - # substitutes. - forceCached = attrs: mapAttrs op attrs; -in -forceCached attrs diff --git a/nix/mkEnv.nix b/nix/mkEnv.nix deleted file mode 100644 index 12364a51..00000000 --- a/nix/mkEnv.nix +++ /dev/null @@ -1,29 +0,0 @@ -{ lib, writeText, buildEnv }: - -{ name ? "dev-env" -, # Environment variables to set - env ? { } -, # Packages to add to the path - paths ? [ ] -}: -let - envToBash = name: value: - "export ${name}=${lib.escapeShellArg (toString value)}" - ; - - exports = lib.concatStringsSep "\n" - (map (name: envToBash name env.${name}) (lib.attrNames env)); - - env-root = writeText "env-root" '' - export PATH=@env-root@/bin:$PATH - - ${exports} - ''; -in -buildEnv { - inherit name; - paths = paths; - postBuild = '' - sed "s|@env-root@|$out|g" ${env-root} > $out/.profile - ''; -} diff --git a/nix/nixpkgs.nix b/nix/nixpkgs.nix deleted file mode 100644 index 6c0edfe8..00000000 --- a/nix/nixpkgs.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ system ? builtins.currentSystem }: -let - sources = import ./sources.nix; -in -import sources.nixpkgs { - inherit system; - config = { }; - overlays = [ ]; -} diff --git a/nix/pkgs/protoc-gen-grpc-java/default.nix b/nix/pkgs/protoc-gen-grpc-java/default.nix deleted file mode 100644 index e0651159..00000000 --- a/nix/pkgs/protoc-gen-grpc-java/default.nix +++ /dev/null @@ -1,23 +0,0 @@ -{ stdenv, runCommand, fetchurl, autoPatchelfHook, lib }: - -stdenv.mkDerivation rec { - pname = "protoc-gen-grpc-java"; - version = "1.38.0"; - - src = fetchurl { - url = "https://repo1.maven.org/maven2/io/grpc/protoc-gen-grpc-java/${version}/protoc-gen-grpc-java-${version}-linux-x86_64.exe"; - sha256 = "sha256:1gy5lkxj6d4vrgalwnjp15biybcnrmp695si9878y7high39ymr3"; - }; - - nativeBuildInputs = [ autoPatchelfHook ]; - - unpackPhase = '' - cp $src ./bin - chmod +x ./bin - ''; - - installPhase = '' - mkdir -p $out/bin - mv ./bin $out/bin/$pname - ''; -} diff --git a/nix/release.nix b/nix/release.nix deleted file mode 100644 index 863f0c9c..00000000 --- a/nix/release.nix +++ /dev/null @@ -1,16 +0,0 @@ -# Use this file with nix-build-uncached on CI -{ system ? builtins.currentSystem }: -let - nixpkgs = import ./nixpkgs.nix { inherit system; }; - - # This is used to wrap all of our outputs, so they all end-up in the cache. - # - # There are two attributes ` allowSubstitutes = false;` and - # `preferLocalBuild = true;` that influence how derivations gets pulled and - # pushed. - forceCached = import ./lib/force_cached.nix nixpkgs.coreutils; - - # All the packages that we care about - ourPackages = import ./. { inherit nixpkgs system; }; -in -forceCached ourPackages diff --git a/nix/sources.json b/nix/sources.json deleted file mode 100644 index c1ec96f7..00000000 --- a/nix/sources.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "nixpkgs": { - "branch": "nixos-unstable", - "description": "Nix Packages collection", - "homepage": "", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "e4ef597edfd8a0ba5f12362932fc9b1dd01a0aef", - "sha256": "1w6y7ma2crcsfph60z8j1k3af0v2m110cbjrb62z287mn4skhqjs", - "type": "tarball", - "url": "https://github.com/NixOS/nixpkgs/archive/e4ef597edfd8a0ba5f12362932fc9b1dd01a0aef.tar.gz", - "url_template": "https://github.com///archive/.tar.gz" - } -} diff --git a/nix/sources.nix b/nix/sources.nix deleted file mode 100644 index 1fc17a6c..00000000 --- a/nix/sources.nix +++ /dev/null @@ -1,160 +0,0 @@ -# This file has been generated by Niv. -let - # - # The fetchers. fetch_ fetches specs of type . - # - - fetch_file = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchurl { inherit (spec) url sha256; name = name'; } - else - pkgs.fetchurl { inherit (spec) url sha256; name = name'; }; - - fetch_tarball = pkgs: name: spec: - let - name' = sanitizeName name + "-src"; - in - if spec.builtin or true then - builtins_fetchTarball { name = name'; inherit (spec) url sha256; } - else - pkgs.fetchzip { name = name'; inherit (spec) url sha256; }; - - fetch_git = name: spec: - let - ref = - if spec ? ref then spec.ref else - if spec ? branch then "refs/heads/${spec.branch}" else - if spec ? tag then "refs/tags/${spec.tag}" else - abort "In git source '${name}': Please specify `ref`, `tag` or `branch`!"; - in - builtins.fetchGit { url = spec.repo; inherit (spec) rev; inherit ref; }; - - fetch_local = spec: spec.path; - - fetch_builtin-tarball = name: throw - ''[${name}] The niv type "builtin-tarball" is deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=tarball -a builtin=true''; - - fetch_builtin-url = name: throw - ''[${name}] The niv type "builtin-url" will soon be deprecated. You should instead use `builtin = true`. - $ niv modify ${name} -a type=file -a builtin=true''; - - # - # Various helpers - # - - # https://github.com/NixOS/nixpkgs/pull/83241/files#diff-c6f540a4f3bfa4b0e8b6bafd4cd54e8bR695 - sanitizeName = name: - ( - concatMapStrings (s: if builtins.isList s then "-" else s) - ( - builtins.split "[^[:alnum:]+._?=-]+" - ((x: builtins.elemAt (builtins.match "\\.*(.*)" x) 0) name) - ) - ); - - # The actual fetching function. - fetch = pkgs: name: spec: - - if ! builtins.hasAttr "type" spec then - abort "ERROR: niv spec ${name} does not have a 'type' attribute" - else if spec.type == "file" then fetch_file pkgs name spec - else if spec.type == "tarball" then fetch_tarball pkgs name spec - else if spec.type == "git" then fetch_git name spec - else if spec.type == "local" then fetch_local spec - else if spec.type == "builtin-tarball" then fetch_builtin-tarball name - else if spec.type == "builtin-url" then fetch_builtin-url name - else - abort "ERROR: niv spec ${name} has unknown type ${builtins.toJSON spec.type}"; - - # If the environment variable NIV_OVERRIDE_${name} is set, then use - # the path directly as opposed to the fetched source. - replace = name: drv: - let - saneName = stringAsChars (c: if isNull (builtins.match "[a-zA-Z0-9]" c) then "_" else c) name; - ersatz = builtins.getEnv "NIV_OVERRIDE_${saneName}"; - in - if ersatz == "" then drv else - # this turns the string into an actual Nix path (for both absolute and - # relative paths) - if builtins.substring 0 1 ersatz == "/" then /. + ersatz else /. + builtins.getEnv "PWD" + "/${ersatz}"; - - # Ports of functions for older nix versions - - # a Nix version of mapAttrs if the built-in doesn't exist - mapAttrs = builtins.mapAttrs or ( - f: set: with builtins; - listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set)) - ); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/lists.nix#L295 - range = first: last: if first > last then [ ] else builtins.genList (n: first + n) (last - first + 1); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L257 - stringToCharacters = s: map (p: builtins.substring p 1 s) (range 0 (builtins.stringLength s - 1)); - - # https://github.com/NixOS/nixpkgs/blob/0258808f5744ca980b9a1f24fe0b1e6f0fecee9c/lib/strings.nix#L269 - stringAsChars = f: s: concatStrings (map f (stringToCharacters s)); - concatMapStrings = f: list: concatStrings (map f list); - concatStrings = builtins.concatStringsSep ""; - - # https://github.com/NixOS/nixpkgs/blob/8a9f58a375c401b96da862d969f66429def1d118/lib/attrsets.nix#L331 - optionalAttrs = cond: as: if cond then as else { }; - - # fetchTarball version that is compatible between all the versions of Nix - builtins_fetchTarball = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchTarball; - in - if lessThan nixVersion "1.12" then - fetchTarball ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchTarball attrs; - - # fetchurl version that is compatible between all the versions of Nix - builtins_fetchurl = { url, name ? null, sha256 }@attrs: - let - inherit (builtins) lessThan nixVersion fetchurl; - in - if lessThan nixVersion "1.12" then - fetchurl ({ inherit url; } // (optionalAttrs (!isNull name) { inherit name; })) - else - fetchurl attrs; - - # Create the final "sources" from the config - mkSources = config: - mapAttrs - ( - name: spec: - if builtins.hasAttr "outPath" spec - then - abort - "The values in sources.json should not have an 'outPath' attribute" - else - spec // { outPath = replace name (fetch config.pkgs name spec); } - ) - config.sources; - - # The "config" used by the fetchers - mkConfig = - { sourcesFile ? if builtins.pathExists ./sources.json then ./sources.json else null - , sources ? if isNull sourcesFile then { } else builtins.fromJSON (builtins.readFile sourcesFile) - , system ? builtins.currentSystem - , pkgs ? abort '' - Some source is being used outside of nixpkgs. For example using import. - - Edit the sources.json and add `"builtin": true` to that source. - '' - }: rec { - # The sources, i.e. the attribute set of spec name to spec - inherit sources; - - # The "pkgs" (evaluated nixpkgs) to use for e.g. non-builtin fetchers - inherit pkgs; - }; - -in -mkSources (mkConfig { }) // { __functor = _: settings: mkSources (mkConfig settings); } From e2e37ffae5ecce2284764293c6fec85a29e75737 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Tue, 22 Nov 2022 18:33:19 +0400 Subject: [PATCH 14/20] drop copy of tests task --- .github/workflows/test.yaml | 32 -------------------------------- 1 file changed, 32 deletions(-) diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 60994585..341379d5 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -40,35 +40,3 @@ jobs: uses: codecov/codecov-action@v1 with: file: ./build/reports/jacoco/test/jacocoTestReport.xml - - integration-test: - runs-on: ubuntu-latest - # Docker Hub image that `container-job` executes in. - # Use -buster which comes with Git 2.20, because action/checkout needs Git 2.18+ to make correct clone (needed by Gradle version plugin) - container: node:12-buster - services: - redis: - image: redis - options: >- - --health-cmd "redis-cli ping" - --health-interval 10s - --health-timeout 5s - --health-retries 5 - steps: - - uses: actions/checkout@v2 - with: - submodules: recursive - - name: Set up JDK - uses: actions/setup-java@v1 - with: - java-version: 13 - - - name: Check - uses: eskatos/gradle-command-action@v1 - with: - arguments: check - env: - CI: true - DSHACKLE_TEST_ENABLED: redis - REDIS_HOST: redis - REDIS_PORT: 6379 \ No newline at end of file From d1e05b021567466ff54186b0a6c8fa7cc230a52c Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Mon, 14 Nov 2022 14:42:36 +0400 Subject: [PATCH 15/20] ganache test --- build.gradle | 11 ++ gradle/libs.versions.toml | 11 ++ .../kotlin/io/emeraldpay/dshackle/Config.kt | 27 +++-- .../io/emeraldpay/dshackle/IntegrationTest.kt | 111 ++++++++++++++++++ src/test/resources/integration/dshackle.yaml | 21 ++++ 5 files changed, 171 insertions(+), 10 deletions(-) create mode 100644 src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt create mode 100644 src/test/resources/integration/dshackle.yaml diff --git a/build.gradle b/build.gradle index fe016704..d9c080aa 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,12 @@ configurations { compile.exclude group: "org.slf4j", module: "log4j-over-slf4j" // should be used only for generation of the stubs, the lib contains grpc classes compile.exclude group: "com.salesforce.servicelibs", module: "reactor-grpc" + + + all { + exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' + } + } dependencies { @@ -101,6 +107,11 @@ dependencies { testImplementation libs.java.websocket testImplementation libs.equals.verifier testImplementation libs.groovy + testImplementation libs.bundles.testcontainers + testImplementation libs.bundles.junit + + testImplementation libs.spring.boot.starter.test + testImplementation libs.grpc.testing detektPlugins libs.detekt.formatting } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 4cb7d9bd..b3af0d0f 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -111,6 +111,14 @@ spring-security-core = { module = "org.springframework.security:spring-security- spring-security-web = { module = "org.springframework.security:spring-security-web", version.ref = "spring-security" } spring-security-config = { module = "org.springframework.security:spring-security-config", version.ref = "spring-security" } +spring-boot-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "spring-boot" } + +testcontainers = "org.testcontainers:testcontainers:1.17.5" +testcontainers-ganache = "io.github.ganchix:testcontainers-java-module-ganache:0.0.4" + +junit-jupiter = "org.junit.jupiter:junit-jupiter:5.9.1" +assertj = "org.assertj:assertj-core:3.23.1" + [bundles] apache-commons = ["commons-io", "apache-commons-lang3", "apache-commons-collections4"] etherjar = ["etherjar-domain", "etherjar-hex", "etherjar-rpc-api", "etherjar-rpc-http", "etherjar-rpc-ws", "etherjar-tx", "etherjar-contract", "etherjar-erc20"] @@ -122,6 +130,9 @@ netty = ["netty-common", "netty-transport", "netty-handler-core", "netty-handler reactor = ["reactor-core", "reactor-netty", "reactor-extra", "reactor-kotlin"] slf4j = ["slf4j-api", "slf4j-jul", "slf4j-jcl", "log4j-slf4j"] spring-framework = ["spring-boot-starter", "spring-security-core", "spring-security-web", "spring-security-config"] +testcontainers = ["testcontainers", "testcontainers-ganache"] +junit = ["junit-jupiter", "assertj"] + [plugins] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Config.kt b/src/main/kotlin/io/emeraldpay/dshackle/Config.kt index 9d38961a..23f24a3b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Config.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Config.kt @@ -33,9 +33,11 @@ import org.springframework.boot.SpringApplication import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Bean import org.springframework.context.annotation.Configuration +import org.springframework.context.annotation.Profile import org.springframework.core.env.Environment import org.springframework.scheduling.annotation.EnableAsync import org.springframework.scheduling.annotation.EnableScheduling +import org.springframework.util.ResourceUtils import reactor.core.scheduler.Scheduler import reactor.core.scheduler.Schedulers import java.io.File @@ -47,8 +49,8 @@ import kotlin.system.exitProcess @EnableScheduling @EnableAsync open class Config( - @Autowired private val env: Environment, - @Autowired private val ctx: ApplicationContext + private val env: Environment, + private val ctx: ApplicationContext ) { companion object { @@ -61,16 +63,20 @@ open class Config( private var configFilePath: File? = null init { - configFilePath = getConfigPath() - Global.version = env.getProperty("version.app", Global.version).let { - if (it.contains("SNAPSHOT")) { - listOfNotNull(it, env.getProperty("version.commit")).joinToString("-") - } else { - it + if (!env.activeProfiles.contains("test")) { + configFilePath = getConfigPath() + Global.version = env.getProperty("version.app", Global.version).let { + if (it.contains("SNAPSHOT")) { + listOfNotNull(it, env.getProperty("version.commit")).joinToString("-") + } else { + it + } } - } - Security.addProvider(BouncyCastleProvider()) + Security.addProvider(BouncyCastleProvider()) + } else { + configFilePath = ResourceUtils.getFile("classpath:integration/dshackle.yaml") + } } fun getConfigPath(): File { @@ -95,6 +101,7 @@ open class Config( } @Bean + @Profile("!test") open fun mainConfig(@Autowired fileResolver: FileResolver): MainConfig { val f = configFilePath ?: throw IllegalStateException("Config path is not set") log.info("Using config: ${f.absolutePath}") diff --git a/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt new file mode 100644 index 00000000..8a279959 --- /dev/null +++ b/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt @@ -0,0 +1,111 @@ +package io.emeraldpay.dshackle + +import io.emeraldpay.api.proto.BlockchainGrpc +import io.emeraldpay.api.proto.BlockchainOuterClass +import io.emeraldpay.api.proto.Common.ChainRef +import io.emeraldpay.dshackle.config.MainConfig +import io.emeraldpay.dshackle.config.MainConfigReader +import io.emeraldpay.dshackle.config.UpstreamsConfig +import io.github.ganchix.ganache.Account +import io.github.ganchix.ganache.GanacheContainer +import io.grpc.BindableService +import io.grpc.inprocess.InProcessChannelBuilder +import io.grpc.inprocess.InProcessServerBuilder +import org.assertj.core.api.Assertions +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.context.SpringBootTest +import org.springframework.boot.test.context.TestConfiguration +import org.springframework.context.annotation.Bean +import org.springframework.context.annotation.Import +import org.springframework.context.annotation.Profile +import org.springframework.test.context.ActiveProfiles +import org.springframework.util.ResourceUtils +import java.math.BigInteger +import java.net.URI + +@SpringBootTest(properties = ["spring.main.allow-bean-definition-overriding=true"]) +@Import(Config::class) +@ActiveProfiles("test") +class IntegrationTest { + + @Autowired + lateinit var services: List + + lateinit var stub: BlockchainGrpc.BlockchainBlockingStub + companion object { + + val PRIVATE_KEY_0 = "ae020c8ddb6fbc24e167b011666639d2ce3d4aa0d9c13d02d726d6865618a781" + val PRIVATE_KEY_1 = "81ad1ba5c4da47feb0f0163c0c61a66c4d0e6a66bd839827444b1e3362016140" + + var ganacheContainer: GanacheContainer<*> = GanacheContainer().apply { + withAccounts( + listOf( + Account.builder().privateKey(PRIVATE_KEY_0).balance(BigInteger.valueOf(2000000000000000000)).build(), + Account.builder().privateKey(PRIVATE_KEY_1).balance(BigInteger.valueOf(2000000000000000000)).build() + ) + ) + } + + init { + ganacheContainer.start() + } + } + + @BeforeEach + fun prepare() { + val serverName = InProcessServerBuilder.generateName() + val builder = InProcessServerBuilder.forName(serverName) + .directExecutor() + services.forEach { builder.addService(it) } + + val managedChannel = InProcessChannelBuilder.forName(serverName).directExecutor().build() + val server = builder.build() + server.start() + + stub = BlockchainGrpc.newBlockingStub(managedChannel) + } + + @Test + fun test() { + val result = stub.describe(BlockchainOuterClass.DescribeRequest.newBuilder().build()) + Assertions.assertThat(result.chainsCount).isEqualTo(1) + Assertions.assertThat(result.chainsList[0].chain).isEqualTo(ChainRef.CHAIN_ETHEREUM) + Assertions.assertThat(result.chainsList[0].nodesCount).isEqualTo(1) + } + + @TestConfiguration + open class Config { + @Bean + @Profile("test") + open fun mainConfig(@Autowired fileResolver: FileResolver): MainConfig { + val reader = MainConfigReader(fileResolver) + val config = reader.read( + ResourceUtils.getFile("classpath:integration/dshackle.yaml") + .inputStream() + )!! + patch(config) + return config + } + + private fun patch(config: MainConfig) { + config.upstreams?.upstreams?.add( + UpstreamsConfig.Upstream().apply { + id = "ganache" + nodeId = 1 + chain = "ethereum" + connection = UpstreamsConfig.EthereumPosConnection().apply { + execution = UpstreamsConfig.EthereumConnection().apply { + rpc = UpstreamsConfig.HttpEndpoint( + URI.create( + "http://" + ganacheContainer.getHost() + ":" + ganacheContainer.getMappedPort(8545) + "/" + ) + ) + } + } + } + ) + } + } +} diff --git a/src/test/resources/integration/dshackle.yaml b/src/test/resources/integration/dshackle.yaml new file mode 100644 index 00000000..3938570b --- /dev/null +++ b/src/test/resources/integration/dshackle.yaml @@ -0,0 +1,21 @@ +version: v1 +host: 0.0.0.0 +port: 2450 +tls: + enabled: false +proxy: + host: 0.0.0.0 + port: 8550 + routes: + - id: eth + blockchain: ethereum + +monitoring: + enabled: false + extended: true + +signed-response: + enabled: false + +cluster: + upstreams: From 8bc1862a033feb22da02ddb813322494ffad611e Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 23 Nov 2022 16:09:16 +0400 Subject: [PATCH 16/20] rename test profile and small changes --- .../kotlin/io/emeraldpay/dshackle/Config.kt | 27 ++++++++++--------- .../io/emeraldpay/dshackle/IntegrationTest.kt | 4 +-- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/Config.kt b/src/main/kotlin/io/emeraldpay/dshackle/Config.kt index 23f24a3b..8ebd90fa 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/Config.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/Config.kt @@ -63,20 +63,21 @@ open class Config( private var configFilePath: File? = null init { - if (!env.activeProfiles.contains("test")) { - configFilePath = getConfigPath() - Global.version = env.getProperty("version.app", Global.version).let { - if (it.contains("SNAPSHOT")) { - listOfNotNull(it, env.getProperty("version.commit")).joinToString("-") - } else { - it - } - } - - Security.addProvider(BouncyCastleProvider()) + configFilePath = if (env.activeProfiles.contains("integration-test")) { + ResourceUtils.getFile("classpath:integration/dshackle.yaml") } else { - configFilePath = ResourceUtils.getFile("classpath:integration/dshackle.yaml") + getConfigPath() } + + Global.version = env.getProperty("version.app", Global.version).let { + if (it.contains("SNAPSHOT")) { + listOfNotNull(it, env.getProperty("version.commit")).joinToString("-") + } else { + it + } + } + + Security.addProvider(BouncyCastleProvider()) } fun getConfigPath(): File { @@ -101,7 +102,7 @@ open class Config( } @Bean - @Profile("!test") + @Profile("!integration-test") open fun mainConfig(@Autowired fileResolver: FileResolver): MainConfig { val f = configFilePath ?: throw IllegalStateException("Config path is not set") log.info("Using config: ${f.absolutePath}") diff --git a/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt index 8a279959..ea89bbe8 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/IntegrationTest.kt @@ -27,7 +27,7 @@ import java.net.URI @SpringBootTest(properties = ["spring.main.allow-bean-definition-overriding=true"]) @Import(Config::class) -@ActiveProfiles("test") +@ActiveProfiles("integration-test") class IntegrationTest { @Autowired @@ -78,7 +78,7 @@ class IntegrationTest { @TestConfiguration open class Config { @Bean - @Profile("test") + @Profile("integration-test") open fun mainConfig(@Autowired fileResolver: FileResolver): MainConfig { val reader = MainConfigReader(fileResolver) val config = reader.read( From 68da5eeafba73f15648835ed883f2c0c320ae02f Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Wed, 23 Nov 2022 16:26:04 +0400 Subject: [PATCH 17/20] safer way to exclude excess slf4 binding --- build.gradle | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index d9c080aa..b35c4b19 100644 --- a/build.gradle +++ b/build.gradle @@ -59,11 +59,6 @@ configurations { // should be used only for generation of the stubs, the lib contains grpc classes compile.exclude group: "com.salesforce.servicelibs", module: "reactor-grpc" - - all { - exclude group: 'org.springframework.boot', module: 'spring-boot-starter-logging' - } - } dependencies { @@ -110,7 +105,9 @@ dependencies { testImplementation libs.bundles.testcontainers testImplementation libs.bundles.junit - testImplementation libs.spring.boot.starter.test + testImplementation(libs.spring.boot.starter.test) { + exclude module: 'spring-boot-starter-logging' + } testImplementation libs.grpc.testing detektPlugins libs.detekt.formatting From 318c919d00a69e4fd7b78db8fef62af7af395e33 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Thu, 24 Nov 2022 20:07:55 +0400 Subject: [PATCH 18/20] fix generated version --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index b35c4b19..9582a062 100644 --- a/build.gradle +++ b/build.gradle @@ -216,7 +216,7 @@ protobuf { sourceSets { main { - //resources.srcDirs += project.buildDir.absolutePath + "/generated/version" + resources.srcDirs += project.buildDir.absolutePath + "/generated/version" proto { srcDir 'emerald-grpc/proto' From c72ea5db3b1ef6e3825ec71b19235f39ca263c48 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Fri, 25 Nov 2022 13:35:56 +0400 Subject: [PATCH 19/20] check all actual upstreams before call --- src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt | 4 ++-- .../io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt | 5 ----- .../emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt | 4 ++-- .../kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt | 4 ++++ .../io/emeraldpay/dshackle/upstream/MultistreamHolder.kt | 2 +- 5 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index 288bfcb6..e999a150 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -166,7 +166,8 @@ open class NativeCall( } val matcher = Selector.convertToMatcher(request.selector) - if (!configuredUpstreams.hasMatchingUpstream(chain, matcher)) { + + if (!multistreamHolder.getUpstream(chain).hasMatchingUpstream(matcher)) { if (Global.metricsExtended) { Metrics.globalRegistry .counter("no_matching_upstream", "chain", chain.chainCode, "matcher", matcher.describeInternal()) @@ -176,7 +177,6 @@ open class NativeCall( } val upstream = multistreamHolder.getUpstream(chain) - ?: return Flux.error(CallFailure(0, SilentException.UnsupportedBlockchain(chain))) return prepareCall(request, upstream) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index 1cfc3a57..97f63b74 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -117,11 +117,6 @@ open class ConfiguredUpstreams( } } - fun hasMatchingUpstream(chain: Chain, matcher: Selector.LabelSelectorMatcher): Boolean = - config.upstreams.any { up -> - (up.chain?.let { Global.chainById(it) == chain } ?: true) && matcher.matches(up.labels) - } - private fun buildDefaultOptions(config: UpstreamsConfig): HashMap { val defaultOptions = HashMap() config.defaultOptions.forEach { defaultsConfig -> diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index a15ead29..165c20fe 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -30,8 +30,8 @@ open class CurrentMultistreamHolder( private val chainMapping = multistreams.associateBy { it.chain } - override fun getUpstream(chain: Chain): Multistream? { - return chainMapping[chain] + override fun getUpstream(chain: Chain): Multistream { + return chainMapping.getValue(chain) } override fun getAvailable(): List { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt index 4e239048..6d7d64df 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Multistream.kt @@ -352,6 +352,10 @@ abstract class Multistream( fun haveUpstreams(): Boolean = upstreams.isNotEmpty() + fun hasMatchingUpstream(matcher: Selector.LabelSelectorMatcher): Boolean { + return upstreams.any { matcher.matches(it) } + } + // -------------------------------------------------------------------------------------------------------- class UpstreamStatus(val upstream: Upstream, val status: UpstreamAvailability, val ts: Instant = Instant.now()) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt index b2c0a753..da409d1c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MultistreamHolder.kt @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.Chain * Holds Multistreams configured for a chain. */ interface MultistreamHolder { - fun getUpstream(chain: Chain): Multistream? + fun getUpstream(chain: Chain): Multistream fun getAvailable(): List fun isAvailable(chain: Chain): Boolean } From 072de08f887ec40e54d27b0c5e267e671495c2a5 Mon Sep 17 00:00:00 2001 From: Maksim Fomenkov Date: Mon, 28 Nov 2022 18:21:04 +0400 Subject: [PATCH 20/20] add eth_getFilterLogs support --- .../io/emeraldpay/dshackle/rpc/NativeCall.kt | 14 +++++------- .../upstream/calls/DefaultEthereumMethods.kt | 22 +++++++++++++------ .../upstream/calls/EthereumCallSelector.kt | 2 +- .../dshackle/rpc/NativeCallSpec.groovy | 10 ++++----- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index e999a150..40a180b0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -30,6 +30,7 @@ import io.emeraldpay.dshackle.quorum.QuorumRpcReader import io.emeraldpay.dshackle.startup.ConfiguredUpstreams import io.emeraldpay.dshackle.startup.UpstreamChangeEvent import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.calls.EthereumCallSelector import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream @@ -255,13 +256,13 @@ open class NativeCall( } private fun getRequestDecorator(method: String): RequestDecorator = - if (method == "eth_getFilterChanges" || method == "eth_uninstallFilter") - GetFilterUpdatesDecorator() + if (method in DefaultEthereumMethods.withFilterIdMethods) + WithFilterIdDecorator() else NoneRequestDecorator() private fun getResultDecorator(method: String): ResultDecorator = - if (CreateFilterDecorator.createFilterMethods.contains(method)) CreateFilterDecorator() else NoneResultDecorator() + if (method in DefaultEthereumMethods.newFilterMethods) CreateFilterDecorator() else NoneResultDecorator() fun fetch(ctx: ValidCallContext): Mono { return ctx.upstream.getRoutedApi(ctx.matcher) @@ -381,11 +382,6 @@ open class NativeCall( companion object { const val quoteCode = '"'.code.toByte() - val createFilterMethods = listOf( - "eth_newFilter", - "eth_newBlockFilter", - "eth_newPendingTransactionFilter" - ) } override fun processResult(result: QuorumRpcReader.Result): ByteArray { val bytes = result.value @@ -406,7 +402,7 @@ open class NativeCall( override fun processRequest(request: List): List = request } - open class GetFilterUpdatesDecorator : RequestDecorator { + open class WithFilterIdDecorator : RequestDecorator { override fun processRequest(request: List): List { val filterId = request.first().toString() val sanitized = filterId.substring(0, filterId.lastIndex - 1) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt index 29994819..d2c3b9fb 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultEthereumMethods.kt @@ -35,6 +35,20 @@ class DefaultEthereumMethods( private val version = "\"EmeraldDshackle/${Global.version}\"" + companion object { + val withFilterIdMethods = listOf( + "eth_getFilterChanges", + "eth_getFilterLogs", + "eth_uninstallFilter" + ) + + val newFilterMethods = listOf( + "eth_newFilter", + "eth_newBlockFilter", + "eth_newPendingTransactionFilter", + ) + } + private val anyResponseMethods = listOf( "eth_gasPrice", "eth_call", @@ -70,13 +84,7 @@ class DefaultEthereumMethods( "eth_feeHistory" ) - private val filterMethods = listOf( - "eth_getFilterChanges", - "eth_newFilter", - "eth_newBlockFilter", - "eth_newPendingTransactionFilter", - "eth_uninstallFilter" - ) + private val filterMethods = withFilterIdMethods + newFilterMethods private val allowedMethods = anyResponseMethods + firstValueMethods + specialMethods + headVerifiedMethods + filterMethods diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt index abf684de..edca897e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt @@ -57,7 +57,7 @@ class EthereumCallSelector( return blockTagSelector(params, 1, head) } else if (method == "eth_getStorageAt") { return blockTagSelector(params, 2, head) - } else if (method == "eth_getFilterChanges" || method == "eth_uninstallFilter") { + } else if (method in DefaultEthereumMethods.withFilterIdMethods) { return sameUpstreamMatcher(params) } return Mono.empty() diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 28fa74cd..2bff6234 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -452,7 +452,7 @@ class NativeCallSpec extends Specification { .collectList().block(Duration.ofSeconds(1)).first() then: act instanceof NativeCall.ValidCallContext - act.requestDecorator instanceof NativeCall.GetFilterUpdatesDecorator + act.requestDecorator instanceof NativeCall.WithFilterIdDecorator } def "Prepare call adds decorator for eth_uninstallFilter"() { @@ -483,7 +483,7 @@ class NativeCallSpec extends Specification { .collectList().block(Duration.ofSeconds(1)).first() then: act instanceof NativeCall.ValidCallContext - act.requestDecorator instanceof NativeCall.GetFilterUpdatesDecorator + act.requestDecorator instanceof NativeCall.WithFilterIdDecorator } def "Parse empty params"() { @@ -543,7 +543,7 @@ class NativeCallSpec extends Specification { def nativeCall = nativeCall() def ctx = new NativeCall.ValidCallContext(1, null, Stub(Multistream), Selector.empty, new AlwaysQuorum(), new NativeCall.RawCallDetails("eth_getFilterUpdates", '["0xabcd"]'), - new NativeCall.GetFilterUpdatesDecorator(), new NativeCall.NoneResultDecorator()) + new NativeCall.WithFilterIdDecorator(), new NativeCall.NoneResultDecorator()) when: def act = nativeCall.parseParams(ctx) then: @@ -564,7 +564,7 @@ class NativeCallSpec extends Specification { } def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum, new NativeCall.ParsedCallDetails("eth_getFilterChanges", []), - new NativeCall.GetFilterUpdatesDecorator(), new NativeCall.CreateFilterDecorator()) + new NativeCall.WithFilterIdDecorator(), new NativeCall.CreateFilterDecorator()) when: def resp = nativeCall.executeOnRemote(call).block(Duration.ofSeconds(1)) @@ -586,7 +586,7 @@ class NativeCallSpec extends Specification { } def call = new NativeCall.ValidCallContext(1, 10, TestingCommons.multistream(TestingCommons.api()), Selector.empty, quorum, new NativeCall.ParsedCallDetails("eth_getFilterChanges", []), - new NativeCall.GetFilterUpdatesDecorator(), new NativeCall.CreateFilterDecorator()) + new NativeCall.WithFilterIdDecorator(), new NativeCall.CreateFilterDecorator()) when: def resp = nativeCall.executeOnRemote(call).block(Duration.ofSeconds(1))