From b1f302aa60b3935a6445efa8eebe5a3865ef64c0 Mon Sep 17 00:00:00 2001 From: a10zn8 Date: Sun, 19 Mar 2023 18:59:03 +0300 Subject: [PATCH] Now grpchead have correct name (#175) --- .../dshackle/upstream/DefaultUpstream.kt | 8 ++--- .../upstream/bitcoin/BitcoinUpstream.kt | 2 +- .../upstream/grpc/BitcoinGrpcUpstream.kt | 2 +- .../upstream/grpc/EthereumGrpcUpstream.kt | 4 +-- .../upstream/grpc/EthereumPosGrpcUpstream.kt | 35 ++----------------- .../dshackle/upstream/grpc/GrpcHead.kt | 3 +- .../upstream/grpc/GrpcHeadSpec.groovy | 2 ++ 7 files changed, 15 insertions(+), 41 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt index 392ca44c..6f98065a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/DefaultUpstream.kt @@ -123,10 +123,6 @@ abstract class DefaultUpstream( return this.status.get().lag } - override fun getId(): String { - return id - } - override fun getOptions(): UpstreamsConfig.Options { return options } @@ -148,5 +144,9 @@ abstract class DefaultUpstream( return quorumByLabel } + override fun getId(): String { + return id + } + data class Status(val lag: Long, val avail: UpstreamAvailability, val status: UpstreamAvailability) } 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 c8218960..46778e58 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinUpstream.kt @@ -32,7 +32,7 @@ abstract class BitcoinUpstream( callMethods: CallMethods, node: QuorumForLabels.QuorumItem, val esploraClient: EsploraClient? = null, - private val chainConfig: ChainsConfig.ChainConfig + chainConfig: ChainsConfig.ChainConfig ) : DefaultUpstream(id, 0.toByte(), options, role, callMethods, node, chainConfig) { constructor( 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 859168b0..2b4020c7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/BitcoinGrpcUpstream.kt @@ -100,7 +100,7 @@ class BitcoinGrpcUpstream( } } private val upstreamStatus = GrpcUpstreamStatus(overrideLabels) - private val grpcHead = GrpcHead(chain, this, remote, blockConverter, reloadBlock, MostWorkForkChoice()) + private val grpcHead = GrpcHead(getId(), chain, this, remote, blockConverter, reloadBlock, MostWorkForkChoice()) private val timeout = Defaults.timeout private var capabilities: Set = emptySet() 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 2b1fbbae..02cbc7ab 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumGrpcUpstream.kt @@ -57,7 +57,7 @@ open class EthereumGrpcUpstream( role: UpstreamsConfig.UpstreamRole, private val chain: Chain, private val remote: ReactorBlockchainStub, - private val client: JsonRpcGrpcClient, + client: JsonRpcGrpcClient, overrideLabels: UpstreamsConfig.Labels?, chainConfig: ChainsConfig.ChainConfig ) : EthereumUpstream( @@ -107,7 +107,7 @@ open class EthereumGrpcUpstream( private val log = LoggerFactory.getLogger(EthereumGrpcUpstream::class.java) private val upstreamStatus = GrpcUpstreamStatus(overrideLabels) - private val grpcHead = GrpcHead(chain, this, remote, blockConverter, reloadBlock, MostWorkForkChoice()) + private val grpcHead = GrpcHead(getId(), chain, this, remote, blockConverter, reloadBlock, MostWorkForkChoice()) private var capabilities: Set = emptySet() private val defaultReader: JsonRpcReader = client.getReader() 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 6f47fc02..8f48f509 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/EthereumPosGrpcUpstream.kt @@ -30,32 +30,24 @@ 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 import io.emeraldpay.dshackle.upstream.ethereum.EthereumIngressSubscription import io.emeraldpay.dshackle.upstream.ethereum.EthereumPosUpstream import io.emeraldpay.dshackle.upstream.ethereum.subscribe.EthereumDshackleIngressSubscription 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 import io.emeraldpay.etherjar.domain.BlockHash -import io.emeraldpay.etherjar.rpc.RpcException -import org.reactivestreams.Publisher -import org.slf4j.LoggerFactory import reactor.core.publisher.Flux -import reactor.core.publisher.Mono import java.math.BigInteger import java.time.Instant import java.util.Locale -import java.util.concurrent.TimeoutException import java.util.function.Function open class EthereumPosGrpcUpstream( - private val parentId: String, + parentId: String, hash: Byte, role: UpstreamsConfig.UpstreamRole, - private val chain: Chain, + chain: Chain, private val remote: ReactorBlockchainGrpc.ReactorBlockchainStub, client: JsonRpcGrpcClient, nodeRating: Int, @@ -86,29 +78,8 @@ open class EthereumPosGrpcUpstream( block } - private val reloadBlock: Function> = Function { existingBlock -> - // head comes without transaction data - // need to download transactions for the block - defaultReader.read(JsonRpcRequest("eth_getBlockByHash", listOf(existingBlock.hash.toHexWithPrefix(), false))) - .flatMap(JsonRpcResponse::requireResult) - .map { - BlockContainer.fromEthereumJson(it, getId()) - } - .timeout(timeout, Mono.error(TimeoutException("Timeout from upstream"))) - .doOnError { t -> - setStatus(UpstreamAvailability.UNAVAILABLE) - val msg = "Failed to download block data for chain $chain on $parentId" - if (t is RpcException || t is TimeoutException) { - log.warn("$msg. Message: ${t.message}") - } else { - log.error(msg, t) - } - } - } - - private val log = LoggerFactory.getLogger(EthereumGrpcUpstream::class.java) private val upstreamStatus = GrpcUpstreamStatus(overrideLabels) - private val grpcHead = GrpcHead(chain, this, remote, blockConverter, null, NoChoiceWithPriorityForkChoice(nodeRating, parentId)) + private val grpcHead = GrpcHead(getId(), chain, this, remote, blockConverter, null, NoChoiceWithPriorityForkChoice(nodeRating, parentId)) private var capabilities: Set = emptySet() private val defaultReader: JsonRpcReader = client.getReader() 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 68b53980..9aa27722 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt @@ -35,6 +35,7 @@ import java.time.Duration import java.util.function.Function class GrpcHead( + id: String, private val chain: Chain, private val parent: DefaultUpstream, private val remote: ReactorBlockchainGrpc.ReactorBlockchainStub, @@ -47,7 +48,7 @@ class GrpcHead( */ private val enhancer: Function>?, private val forkChoice: ForkChoice -) : AbstractHead(forkChoice), Lifecycle { +) : AbstractHead(forkChoice, upstreamId = id), Lifecycle { companion object { private val log = LoggerFactory.getLogger(GrpcHead::class.java) 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 41ea4087..edcdbf94 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/GrpcHeadSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/grpc/GrpcHeadSpec.groovy @@ -58,6 +58,7 @@ class GrpcHeadSpec extends Specification { TestingCommons.blockForBitcoin(head.height) } def head = new GrpcHead( + "test", Chain.BITCOIN, Stub(DefaultUpstream), client, @@ -119,6 +120,7 @@ class GrpcHeadSpec extends Specification { TestingCommons.blockForBitcoin(head.height) } def head = new GrpcHead( + "test", Chain.BITCOIN, Stub(DefaultUpstream), client,