diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt index 662105b0..f8cf5dd7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt @@ -102,6 +102,7 @@ open class UpstreamsConfig { var host: String? = null var port: Int = 0 var auth: AuthConfig.ClientTlsAuth? = null + var nodeRating: Int = 0 } class EthereumConnection : RpcConnection() { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt index f280ec64..9ab5be40 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt @@ -106,6 +106,9 @@ class UpstreamsConfigReader( config.upstreams.add(upstream) val connection = UpstreamsConfig.GrpcConnection() upstream.connection = connection + getValueAsInt(connConfigNode, "node-rating")?.let { + connection.nodeRating = it + } getValueAsString(connConfigNode, "host")?.let { connection.host = it } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index 10e320ff..0eba3a3b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -29,8 +29,8 @@ import io.emeraldpay.dshackle.upstream.bitcoin.ExtractBlock import io.emeraldpay.dshackle.upstream.bitcoin.ZMQServer import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.calls.ManagedCallMethods -import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosRpcUpstream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsFactory import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice @@ -160,7 +160,7 @@ open class ConfiguredUpstreams( if (connectorFactory == null) { return null } - val upstream = EthereumPosUpstream( + val upstream = EthereumPosRpcUpstream( config.id!!, chain, options, config.role, @@ -218,7 +218,7 @@ open class ConfiguredUpstreams( config: UpstreamsConfig.Upstream, chain: Chain, options: UpstreamsConfig.Options - ) : EthereumUpstream? { + ) : EthereumRpcUpstream? { val conn = config.connection!! val urls = ArrayList() @@ -228,7 +228,7 @@ open class ConfiguredUpstreams( if (connectorFactory == null) { return null } - val upstream = EthereumUpstream( + val upstream = EthereumRpcUpstream( config.id!!, chain, options, config.role, @@ -251,7 +251,8 @@ open class ConfiguredUpstreams( endpoint.host!!, endpoint.port, endpoint.auth, - fileResolver + fileResolver, + endpoint.nodeRating ).apply { timeout = options.timeout } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index 4de9bbef..d18ff731 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -24,10 +24,7 @@ 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.dshackle.upstream.ethereum.* import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.slf4j.LoggerFactory diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20Balance.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20Balance.kt index c5250488..05d99b8d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20Balance.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/ERC20Balance.kt @@ -49,7 +49,7 @@ open class ERC20Balance { apis.request(1) return Flux.from(apis) .flatMap { - getBalance(it.cast(EthereumUpstream::class.java), token, address) + getBalance(it.cast(EthereumRpcUpstream::class.java), token, address) } .doOnNext { apis.resolve() @@ -57,7 +57,7 @@ open class ERC20Balance { .next() } - open fun getBalance(upstream: EthereumUpstream, token: ERC20Token, address: Address): Mono { + open fun getBalance(upstream: EthereumRpcUpstream, token: ERC20Token, address: Address): Mono { return upstream .getApi() .read(prepareEthCall(token, address, upstream.getHead())) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt new file mode 100644 index 00000000..e4b104cd --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumRpcUpstream.kt @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2020 EmeraldPay, Inc + * Copyright (c) 2019 ETCDEV GmbH + * + * 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.upstream.ethereum + +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.QuorumForLabels +import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.calls.CallMethods +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 + +open class EthereumRpcUpstream( + id: String, + val chain: Chain, + options: UpstreamsConfig.Options, + role: UpstreamsConfig.UpstreamRole, + targets: CallMethods?, + private val node: QuorumForLabels.QuorumItem?, + connectorFactory: ConnectorFactory +) : EthereumUpstream(id, options, role, targets, node), Lifecycle, Upstream, CachesEnabled { + private val log = LoggerFactory.getLogger(EthereumRpcUpstream::class.java) + private val validator : EthereumUpstreamValidator = EthereumUpstreamValidator(this, getOptions()) + private val connector : EthereumConnector = connectorFactory.create(this, validator, chain) + + private var validatorSubscription: Disposable? = null + + override fun setCaches(caches: Caches) { + if (connector is CachesEnabled) { + connector.setCaches(caches) + } + } + + override fun start() { + log.info("Configured for ${chain.chainName}") + connector.start() + if (getOptions().disableValidation != null && getOptions().disableValidation!!) { + log.warn("Disable validation for upstream ${this.getId()}") + this.setLag(0) + this.setStatus(UpstreamAvailability.OK) + } else { + log.debug("Start validation for upstream ${this.getId()}") + validatorSubscription = validator.start() + .subscribe(this::setStatus) + } + } + override fun getHead(): Head { + return connector.getHead() + } + + override fun stop() { + validatorSubscription?.dispose() + validatorSubscription = null + connector.stop() + } + + override fun isRunning(): Boolean { + return connector.isRunning + } + + override fun getApi(): Reader { + return connector.getApi() + } + + override fun isGrpc(): Boolean { + return false + } + + @Suppress("UNCHECKED_CAST") + override fun cast(selfType: Class): T { + if (!selfType.isAssignableFrom(this.javaClass)) { + throw ClassCastException("Cannot cast ${this.javaClass} to $selfType") + } + return this as T + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstream.kt index ef226380..0b50610e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstream.kt @@ -16,78 +16,19 @@ */ package io.emeraldpay.dshackle.upstream.ethereum -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.QuorumForLabels -import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.Capability +import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.calls.CallMethods -import io.emeraldpay.dshackle.upstream.ethereum.connectors.ConnectorFactory -import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector -import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory -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 EthereumUpstream( +abstract class EthereumUpstream( id: String, - val chain: Chain, options: UpstreamsConfig.Options, role: UpstreamsConfig.UpstreamRole, targets: CallMethods?, - private val node: QuorumForLabels.QuorumItem?, - connectorFactory: ConnectorFactory -) : DefaultUpstream(id, options, role, targets, node), Lifecycle, Upstream, CachesEnabled { - private val log = LoggerFactory.getLogger(EthereumUpstream::class.java) - private val validator : EthereumUpstreamValidator = EthereumUpstreamValidator(this, getOptions()) - private val connector : EthereumConnector = connectorFactory.create(this, validator, chain) - - private var validatorSubscription: Disposable? = null - - override fun setCaches(caches: Caches) { - if (connector is CachesEnabled) { - connector.setCaches(caches) - } - } - - override fun start() { - log.info("Configured for ${chain.chainName}") - connector.start() - if (getOptions().disableValidation != null && getOptions().disableValidation!!) { - log.warn("Disable validation for upstream ${this.getId()}") - this.setLag(0) - this.setStatus(UpstreamAvailability.OK) - } else { - log.debug("Start validation for upstream ${this.getId()}") - validatorSubscription = validator.start() - .subscribe(this::setStatus) - } - } - override fun getHead(): Head { - return connector.getHead() - } - - override fun stop() { - validatorSubscription?.dispose() - validatorSubscription = null - connector.stop() - } - - override fun isRunning(): Boolean { - return connector.isRunning - } - - override fun getApi(): Reader { - return connector.getApi() - } - - override fun isGrpc(): Boolean { - return false - } + private val node: QuorumForLabels.QuorumItem? +) : DefaultUpstream(id, options, role, targets, node) { private val capabilities = if (options.providesBalance != false) { setOf(Capability.RPC, Capability.BALANCE) @@ -102,12 +43,4 @@ open class EthereumUpstream( override fun getLabels(): Collection { return node?.let { listOf(it.labels) } ?: emptyList() } - - @Suppress("UNCHECKED_CAST") - override fun cast(selfType: Class): T { - if (!selfType.isAssignableFrom(this.javaClass)) { - throw ClassCastException("Cannot cast ${this.javaClass} to $selfType") - } - return this as T - } -} +} \ No newline at end of file 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 aab4ba37..e81b28e2 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 @@ -25,7 +25,6 @@ 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.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.forkchoice.PriorityForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse 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 new file mode 100644 index 00000000..7838c08e --- /dev/null +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosRpcUpstream.kt @@ -0,0 +1,98 @@ +/** + * Copyright (c) 2020 EmeraldPay, Inc + * Copyright (c) 2019 ETCDEV GmbH + * + * 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.upstream.ethereum + +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.QuorumForLabels +import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.calls.CallMethods +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 + +open class EthereumPosRpcUpstream( + id: String, + val chain: Chain, + options: UpstreamsConfig.Options, + role: UpstreamsConfig.UpstreamRole, + targets: CallMethods?, + private val node: QuorumForLabels.QuorumItem?, + connectorFactory: ConnectorFactory +) : EthereumPosUpstream(id, options, role, targets, node), Lifecycle, Upstream, CachesEnabled { + private val log = LoggerFactory.getLogger(EthereumPosRpcUpstream::class.java) + private val validator : EthereumUpstreamValidator = EthereumUpstreamValidator(this, getOptions()) + private val connector : EthereumConnector = connectorFactory.create(this, validator, chain) + + private var validatorSubscription: Disposable? = null + + override fun setCaches(caches: Caches) { + if (connector is CachesEnabled) { + connector.setCaches(caches) + } + } + + override fun start() { + log.info("Configured for ${chain.chainName}") + connector.start() + if (getOptions().disableValidation != null && getOptions().disableValidation!!) { + log.warn("Disable validation for upstream ${this.getId()}") + this.setLag(0) + this.setStatus(UpstreamAvailability.OK) + } else { + log.debug("Start validation for upstream ${this.getId()}") + validatorSubscription = validator.start() + .subscribe(this::setStatus) + } + } + override fun getHead(): Head { + return connector.getHead() + } + + override fun stop() { + validatorSubscription?.dispose() + validatorSubscription = null + connector.stop() + } + + override fun isRunning(): Boolean { + return connector.isRunning + } + + override fun getApi(): Reader { + return connector.getApi() + } + + override fun isGrpc(): Boolean { + return false + } + + @Suppress("UNCHECKED_CAST") + override fun cast(selfType: Class): T { + if (!selfType.isAssignableFrom(this.javaClass)) { + throw ClassCastException("Cannot cast ${this.javaClass} to $selfType") + } + return this as T + } +} diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosUpstream.kt index 1a75cf21..f98aa936 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosUpstream.kt @@ -16,78 +16,19 @@ */ package io.emeraldpay.dshackle.upstream.ethereum -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.QuorumForLabels -import io.emeraldpay.dshackle.upstream.* +import io.emeraldpay.dshackle.upstream.Capability +import io.emeraldpay.dshackle.upstream.DefaultUpstream import io.emeraldpay.dshackle.upstream.calls.CallMethods -import io.emeraldpay.dshackle.upstream.ethereum.connectors.ConnectorFactory -import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector -import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory -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 EthereumPosUpstream( +abstract class EthereumPosUpstream( id: String, - val chain: Chain, options: UpstreamsConfig.Options, role: UpstreamsConfig.UpstreamRole, targets: CallMethods?, - private val node: QuorumForLabels.QuorumItem?, - connectorFactory: ConnectorFactory -) : DefaultUpstream(id, options, role, targets, node), Lifecycle, Upstream, CachesEnabled { - private val log = LoggerFactory.getLogger(EthereumPosUpstream::class.java) - private val validator : EthereumUpstreamValidator = EthereumUpstreamValidator(this, getOptions()) - private val connector : EthereumConnector = connectorFactory.create(this, validator, chain) - - private var validatorSubscription: Disposable? = null - - override fun setCaches(caches: Caches) { - if (connector is CachesEnabled) { - connector.setCaches(caches) - } - } - - override fun start() { - log.info("Configured for ${chain.chainName}") - connector.start() - if (getOptions().disableValidation != null && getOptions().disableValidation!!) { - log.warn("Disable validation for upstream ${this.getId()}") - this.setLag(0) - this.setStatus(UpstreamAvailability.OK) - } else { - log.debug("Start validation for upstream ${this.getId()}") - validatorSubscription = validator.start() - .subscribe(this::setStatus) - } - } - override fun getHead(): Head { - return connector.getHead() - } - - override fun stop() { - validatorSubscription?.dispose() - validatorSubscription = null - connector.stop() - } - - override fun isRunning(): Boolean { - return connector.isRunning - } - - override fun getApi(): Reader { - return connector.getApi() - } - - override fun isGrpc(): Boolean { - return false - } + private val node: QuorumForLabels.QuorumItem? +) : DefaultUpstream(id, options, role, targets, node) { private val capabilities = if (options.providesBalance != false) { setOf(Capability.RPC, Capability.BALANCE) @@ -102,12 +43,4 @@ open class EthereumPosUpstream( override fun getLabels(): Collection { return node?.let { listOf(it.labels) } ?: emptyList() } - - @Suppress("UNCHECKED_CAST") - override fun cast(selfType: Class): T { - if (!selfType.isAssignableFrom(this.javaClass)) { - throw ClassCastException("Cannot cast ${this.javaClass} to $selfType") - } - return this as T - } -} +} \ No newline at end of file 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 b7824b01..0d594594 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt @@ -50,7 +50,7 @@ open class EthereumGrpcUpstream( private val chain: Chain, private val remote: ReactorBlockchainGrpc.ReactorBlockchainStub, private val client: JsonRpcGrpcClient -) : DefaultUpstream( +) : EthereumUpstream( "${parentId}_${chain.chainCode.lowercase(Locale.getDefault())}", UpstreamsConfig.Options.getDefaults(), role, 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 ffa5ae06..3735c98a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt @@ -26,8 +26,8 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.* import io.emeraldpay.dshackle.upstream.calls.CallMethods -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream -import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice +import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream +import io.emeraldpay.dshackle.upstream.forkchoice.NoChoiceWithPriorityForkChoice import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcGrpcClient import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse @@ -48,9 +48,10 @@ open class EthereumPosGrpcUpstream( private val parentId: String, role: UpstreamsConfig.UpstreamRole, private val chain: Chain, - private val remote: ReactorBlockchainGrpc.ReactorBlockchainStub, - private val client: JsonRpcGrpcClient -) : DefaultUpstream( + remote: ReactorBlockchainGrpc.ReactorBlockchainStub, + client: JsonRpcGrpcClient, + nodeRating: Int +) : EthereumPosUpstream( "${parentId}_${chain.chainCode.lowercase(Locale.getDefault())}", UpstreamsConfig.Options.getDefaults(), role, @@ -94,7 +95,7 @@ open class EthereumPosGrpcUpstream( private val log = LoggerFactory.getLogger(EthereumGrpcUpstream::class.java) private val upstreamStatus = GrpcUpstreamStatus() - private val grpcHead = GrpcHead(chain, this, remote, blockConverter, reloadBlock, MostWorkForkChoice()) + private val grpcHead = GrpcHead(chain, this, remote, blockConverter, reloadBlock, NoChoiceWithPriorityForkChoice(nodeRating)) private var capabilities: Set = emptySet() private val defaultReader: Reader = client.forSelector(Selector.empty) 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 c55fcb5a..20fe2a64 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcUpstreams.kt @@ -56,7 +56,8 @@ class GrpcUpstreams( private val host: String, private val port: Int, private val auth: AuthConfig.ClientTlsAuth? = null, - private val fileResolver: FileResolver + private val fileResolver: FileResolver, + private val nodeRating: Int ) { private val log = LoggerFactory.getLogger(GrpcUpstreams::class.java) @@ -192,6 +193,8 @@ class GrpcUpstreams( return getOrCreateEthereum(chain, metrics) } else if (blockchainType == BlockchainType.BITCOIN) { return getOrCreateBitcoin(chain, metrics) + } else if (blockchainType == BlockchainType.ETHEREUM_POS) { + return getOrCreateEthereumPos(chain, metrics) } else { throw IllegalArgumentException("Unsupported blockchain: $chain") } @@ -213,6 +216,22 @@ class GrpcUpstreams( } } + fun getOrCreateEthereumPos(chain: Chain, metrics: RpcMetrics): UpstreamChange { + lock.withLock { + val current = known[chain] + return if (current == null) { + val rpcClient = JsonRpcGrpcClient(client!!, chain, metrics) + val created = EthereumPosGrpcUpstream(id, role, chain, client!!, rpcClient, nodeRating) + created.timeout = this.timeout + known[chain] = created + created.start() + UpstreamChange(chain, created, UpstreamChange.ChangeType.ADDED) + } else { + UpstreamChange(chain, current, UpstreamChange.ChangeType.REVALIDATED) + } + } + } + fun getOrCreateBitcoin(chain: Chain, metrics: RpcMetrics): UpstreamChange { lock.withLock { val current = known[chain] diff --git a/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy index d69c22b6..2244dddc 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/config/UpstreamsConfigReaderSpec.groovy @@ -17,9 +17,6 @@ package io.emeraldpay.dshackle.config import io.emeraldpay.dshackle.test.TestingCommons -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream -import io.emeraldpay.grpc.Chain -import io.emeraldpay.etherjar.rpc.RpcClient import spock.lang.Specification class UpstreamsConfigReaderSpec extends Specification { diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy index 068d4240..160becb9 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/StreamHeadSpec.groovy @@ -22,10 +22,10 @@ import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.data.BlockContainer -import io.emeraldpay.dshackle.test.EthereumUpstreamMock +import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.test.MultistreamHolderMock -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.grpc.Chain import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.rpc.json.BlockJson @@ -43,7 +43,7 @@ class StreamHeadSpec extends Specification { def "Errors on unavailable chain"() { setup: - def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, Stub(EthereumUpstream)) + def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, Stub(EthereumRpcUpstream)) def streamHead = new StreamHead(upstreams) when: def flux = streamHead.add( @@ -78,7 +78,7 @@ class StreamHeadSpec extends Specification { .build() } - def upstream = new EthereumUpstreamMock(Chain.ETHEREUM, TestingCommons.api()) + def upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, TestingCommons.api()) def upstreams = new MultistreamHolderMock(Chain.ETHEREUM, upstream) def streamHead = new StreamHead(upstreams) when: diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy index 062820ed..de15a93e 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/TrackERC20AddressSpec.groovy @@ -3,18 +3,12 @@ package io.emeraldpay.dshackle.rpc import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.dshackle.config.TokensConfig -import io.emeraldpay.dshackle.test.EthereumUpstreamMock -import io.emeraldpay.dshackle.test.MultistreamHolderMock -import io.emeraldpay.dshackle.test.ReaderMock import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.ERC20Balance import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumSubscribe -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream import io.emeraldpay.dshackle.upstream.ethereum.subscribe.ConnectLogs import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage -import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest -import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.etherjar.domain.BlockHash import io.emeraldpay.etherjar.domain.TransactionId import io.emeraldpay.etherjar.hex.Hex32 @@ -22,11 +16,9 @@ import io.emeraldpay.grpc.Chain 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 reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.test.StepVerifier -import spock.lang.Ignore import spock.lang.Specification import java.time.Duration diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumUpstreamMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy similarity index 80% rename from src/test/groovy/io/emeraldpay/dshackle/test/EthereumUpstreamMock.groovy rename to src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy index 43caf2ee..89bfa684 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/EthereumUpstreamMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/EthereumRpcUpstreamMock.groovy @@ -25,7 +25,7 @@ import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.upstream.calls.DefaultBitcoinMethods import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.dshackle.upstream.UpstreamAvailability import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse @@ -35,7 +35,7 @@ import org.jetbrains.annotations.NotNull import org.reactivestreams.Publisher -class EthereumUpstreamMock extends EthereumUpstream { +class EthereumRpcUpstreamMock extends EthereumRpcUpstream { EthereumHeadMock ethereumHeadMock @@ -47,19 +47,19 @@ class EthereumUpstreamMock extends EthereumUpstream { ]) } - EthereumUpstreamMock(@NotNull Chain chain, @NotNull Reader api) { + EthereumRpcUpstreamMock(@NotNull Chain chain, @NotNull Reader api) { this(chain, api, allMethods()) } - EthereumUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader api) { + EthereumRpcUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader api) { this(id, chain, api, allMethods()) } - EthereumUpstreamMock(@NotNull Chain chain, @NotNull Reader api, CallMethods methods) { + EthereumRpcUpstreamMock(@NotNull Chain chain, @NotNull Reader api, CallMethods methods) { this("test", chain, api, methods) } - EthereumUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader api, CallMethods methods) { + EthereumRpcUpstreamMock(@NotNull String id, @NotNull Chain chain, @NotNull Reader api, CallMethods methods) { super(id, chain, UpstreamsConfig.Options.getDefaults(), UpstreamsConfig.UpstreamRole.PRIMARY, diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy index 994c995c..26275da6 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/MultistreamHolderMock.groovy @@ -28,7 +28,7 @@ import io.emeraldpay.dshackle.upstream.Upstream import io.emeraldpay.dshackle.upstream.MultistreamHolder import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream import io.emeraldpay.dshackle.upstream.ethereum.EthereumReader -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.grpc.BlockchainType import io.emeraldpay.grpc.Chain import org.jetbrains.annotations.NotNull @@ -48,8 +48,8 @@ class MultistreamHolderMock implements MultistreamHolder { if (BlockchainType.from(chain) == BlockchainType.ETHEREUM) { if (up instanceof EthereumMultistream) { upstreams[chain] = up - } else if (up instanceof EthereumUpstream) { - upstreams[chain] = new EthereumMultistreamMock(chain, [up as EthereumUpstream], Caches.default()) + } else if (up instanceof EthereumRpcUpstream) { + upstreams[chain] = new EthereumMultistreamMock(chain, [up as EthereumRpcUpstream], Caches.default()) } else { throw new IllegalArgumentException("Unsupported upstream type ${up.class}") } @@ -105,15 +105,15 @@ class MultistreamHolderMock implements MultistreamHolder { CallMethods customMethods = null Head customHead = null - EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams, @NotNull Caches caches) { + EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams, @NotNull Caches caches) { super(chain, upstreams, caches) } - EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams) { + EthereumMultistreamMock(@NotNull Chain chain, @NotNull List upstreams) { this(chain, upstreams, Caches.default()) } - EthereumMultistreamMock(@NotNull Chain chain, @NotNull EthereumUpstream upstream) { + EthereumMultistreamMock(@NotNull Chain chain, @NotNull EthereumRpcUpstream upstream) { this(chain, [upstream]) } diff --git a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy index 795995db..5f4662c4 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/test/TestingCommons.groovy @@ -28,7 +28,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.EthereumMultistream -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream +import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcRequest import io.emeraldpay.dshackle.upstream.rpcclient.JsonRpcResponse import io.emeraldpay.grpc.Chain @@ -46,35 +46,35 @@ class TestingCommons { return new ApiReaderMock() } - static EthereumUpstreamMock upstream() { - return new EthereumUpstreamMock(Chain.ETHEREUM, api()) + static EthereumRpcUpstreamMock upstream() { + return new EthereumRpcUpstreamMock(Chain.ETHEREUM, api()) } - static EthereumUpstreamMock upstream(String id) { - return new EthereumUpstreamMock(id, Chain.ETHEREUM, api()) + static EthereumRpcUpstreamMock upstream(String id) { + return new EthereumRpcUpstreamMock(id, Chain.ETHEREUM, api()) } - static EthereumUpstreamMock upstream(String id, Reader api) { - return new EthereumUpstreamMock(id, Chain.ETHEREUM, api) + static EthereumRpcUpstreamMock upstream(String id, Reader api) { + return new EthereumRpcUpstreamMock(id, Chain.ETHEREUM, api) } - static EthereumUpstreamMock upstream(Reader api) { - return new EthereumUpstreamMock(Chain.ETHEREUM, api) + static EthereumRpcUpstreamMock upstream(Reader api) { + return new EthereumRpcUpstreamMock(Chain.ETHEREUM, api) } - static EthereumUpstreamMock upstream(Reader api, String method) { + static EthereumRpcUpstreamMock upstream(Reader api, String method) { return upstream(api, [method]) } - static EthereumUpstreamMock upstream(Reader api, List methods) { - return new EthereumUpstreamMock(Chain.ETHEREUM, api, new DirectCallMethods(methods)) + static EthereumRpcUpstreamMock upstream(Reader api, List methods) { + return new EthereumRpcUpstreamMock(Chain.ETHEREUM, api, new DirectCallMethods(methods)) } static Multistream multistream(Reader api) { return multistream(upstream(api)) } - static Multistream multistream(EthereumUpstream up) { + static Multistream multistream(EthereumRpcUpstream up) { return new EthereumMultistream(Chain.ETHEREUM, [up], Caches.default()).tap { start() } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy index 3fa6ea32..a3b3952b 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolderSpec.groovy @@ -16,7 +16,7 @@ package io.emeraldpay.dshackle.upstream import io.emeraldpay.dshackle.startup.UpstreamChange -import io.emeraldpay.dshackle.test.EthereumUpstreamMock +import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.grpc.Chain import spock.lang.Specification @@ -26,7 +26,7 @@ class CurrentMultistreamHolderSpec extends Specification { def "add upstream"() { setup: def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) - def up = new EthereumUpstreamMock("test", Chain.ETHEREUM, TestingCommons.api()) + def up = new EthereumRpcUpstreamMock("test", Chain.ETHEREUM, TestingCommons.api()) when: current.update(new UpstreamChange(Chain.ETHEREUM, up, UpstreamChange.ChangeType.ADDED)) then: @@ -37,9 +37,9 @@ class CurrentMultistreamHolderSpec extends Specification { def "add multiple upstreams"() { setup: def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) - def up1 = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) - def up2 = new EthereumUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) - def up3 = new EthereumUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) + def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) + def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) + def up3 = new EthereumRpcUpstreamMock("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)) @@ -53,10 +53,10 @@ class CurrentMultistreamHolderSpec extends Specification { def "remove upstream"() { setup: def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) - def up1 = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) - def up2 = new EthereumUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) - def up3 = new EthereumUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) - def up1_del = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) + def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) + def up2 = new EthereumRpcUpstreamMock("test2", Chain.ETHEREUM_CLASSIC, TestingCommons.api()) + def up3 = new EthereumRpcUpstreamMock("test3", Chain.ETHEREUM, TestingCommons.api()) + def up1_del = new EthereumRpcUpstreamMock("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)) @@ -71,7 +71,7 @@ class CurrentMultistreamHolderSpec extends Specification { def "available after adding"() { setup: def current = new CurrentMultistreamHolder(TestingCommons.emptyCaches()) - def up1 = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) + def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api()) when: def act = current.isAvailable(Chain.ETHEREUM) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy index 371fb461..b5760836 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/FilteredApisSpec.groovy @@ -21,7 +21,7 @@ import io.emeraldpay.dshackle.startup.QuorumForLabels import io.emeraldpay.dshackle.test.EthereumApiStub import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.calls.DefaultEthereumMethods -import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstream +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 @@ -38,7 +38,7 @@ class FilteredApisSpec extends Specification { def "Verifies labels"() { setup: def i = 0 - List upstreams = [ + List upstreams = [ [test: "foo"], [test: "bar"], [test: "foo", test2: "baz"], @@ -49,7 +49,7 @@ class FilteredApisSpec extends Specification { create(_, _) >> TestingCommons.api().tap { it.id = "${i++}" } } def connectorFactory = new EthereumConnectorFactory(false, null, httpFactory, new MostWorkForkChoice()) - new EthereumUpstream( + new EthereumRpcUpstream( "test", Chain.ETHEREUM, new UpstreamsConfig.Options(), diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy index 10a036ac..5a97148f 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/MultistreamSpec.groovy @@ -20,7 +20,7 @@ import io.emeraldpay.dshackle.cache.Caches import io.emeraldpay.dshackle.config.UpstreamsConfig import io.emeraldpay.dshackle.quorum.AlwaysQuorum import io.emeraldpay.dshackle.reader.Reader -import io.emeraldpay.dshackle.test.EthereumUpstreamMock +import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.calls.DirectCallMethods import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream @@ -38,8 +38,8 @@ class MultistreamSpec extends Specification { def "Aggregates methods"() { setup: - def up1 = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test1", "eth_test2"])) - def up2 = new EthereumUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test2", "eth_test3"])) + def up1 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test1", "eth_test2"])) + def up2 = new EthereumRpcUpstreamMock("test1", Chain.ETHEREUM, TestingCommons.api(), new DirectCallMethods(["eth_test2", "eth_test3"])) def aggr = new EthereumMultistream(Chain.ETHEREUM, [up1, up2], Caches.default()) when: aggr.onUpstreamsUpdated() 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 d1f6cfa1..11235509 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/ERC20BalanceSpec.groovy @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.upstream.ethereum -import io.emeraldpay.dshackle.test.EthereumUpstreamMock +import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.ReaderMock import io.emeraldpay.dshackle.upstream.ApiSource import io.emeraldpay.dshackle.upstream.FilteredApis @@ -47,7 +47,7 @@ class ERC20BalanceSpec extends Specification { JsonRpcResponse.ok('"0x0000000000000000000000000000000000000000000000000000001f28d72868"') ) - EthereumUpstream upstream = new EthereumUpstreamMock(Chain.ETHEREUM, api) + EthereumRpcUpstream upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api) ERC20Token token = new ERC20Token(Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9")) ERC20Balance query = new ERC20Balance() @@ -73,7 +73,7 @@ class ERC20BalanceSpec extends Specification { JsonRpcResponse.ok('"0x0000000000000000000000000000000000000000000000000000001f28d72868"') ) - EthereumUpstream upstream = new EthereumUpstreamMock(Chain.ETHEREUM, api) + EthereumRpcUpstream upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api) ERC20Token token = new ERC20Token(Address.from("0x54EedeAC495271d0F6B175474E89094C44Da98b9")) ERC20Balance query = new ERC20Balance() 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 f7fd5a7c..84c29069 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/ethereum/EthereumReaderSpec.groovy @@ -23,7 +23,7 @@ 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.test.EthereumUpstreamMock +import io.emeraldpay.dshackle.test.EthereumRpcUpstreamMock import io.emeraldpay.dshackle.test.TestingCommons import io.emeraldpay.dshackle.upstream.Multistream import io.emeraldpay.dshackle.upstream.calls.CallMethods @@ -203,7 +203,7 @@ class EthereumReaderSpec extends Specification { api.answerOnce("eth_getBalance", ["0x70b91ff87a902b53dc6e2f6bda8bb9b330ccd30c", "latest"], "0x10") // height 101 + 1 => 102 => 0x66 api.answerOnce("eth_getBalance", ["0x70b91ff87a902b53dc6e2f6bda8bb9b330ccd30c", "0x66"], "0xff") - EthereumUpstreamMock upstream = new EthereumUpstreamMock(Chain.ETHEREUM, api) + EthereumRpcUpstreamMock upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api) def upstreams = TestingCommons.multistream(upstream) def reader = new EthereumReader(upstreams, Caches.default(), calls) reader.start() @@ -241,7 +241,7 @@ class EthereumReaderSpec extends Specification { api.answerOnce("eth_getTransactionReceipt", ["0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2"], [ transactionHash: "0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2" ]) - EthereumUpstreamMock upstream = new EthereumUpstreamMock(Chain.ETHEREUM, api) + EthereumRpcUpstreamMock upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api) def upstreams = TestingCommons.multistream(upstream) def reader = new EthereumReader(upstreams, Caches.default(), calls) reader.start() @@ -257,7 +257,7 @@ class EthereumReaderSpec extends Specification { def "Read receipt from cache if available"() { setup: def api = TestingCommons.api() - EthereumUpstreamMock upstream = new EthereumUpstreamMock(Chain.ETHEREUM, api) + EthereumRpcUpstreamMock upstream = new EthereumRpcUpstreamMock(Chain.ETHEREUM, api) def upstreams = TestingCommons.multistream(upstream) def receiptCache = Mock(ReceiptRedisCache) { 1 * it.read(TxId.from("0xf85b826fdf98ee0f48f7db001be00472e63ceb056846f4ecac5f0c32878b8ab2")) >>