fix formatting

This commit is contained in:
terminal
2022-07-29 19:24:32 +04:00
parent bdd1281458
commit 38958a6296
29 changed files with 61 additions and 62 deletions

View File

@@ -116,8 +116,8 @@ open class UpstreamsConfig {
}
class EthereumPosConnection : UpstreamConnection() {
var execution : EthereumConnection? = null
var blockPriority : Int = 0
var execution: EthereumConnection? = null
var blockPriority: Int = 0
}
data class BitcoinZeroMq(

View File

@@ -165,7 +165,7 @@ class UpstreamsConfigReader(
return connection
}
private fun readEthereumPosConnection(connConfigNode: MappingNode) : UpstreamsConfig.EthereumPosConnection {
private fun readEthereumPosConnection(connConfigNode: MappingNode): UpstreamsConfig.EthereumPosConnection {
val connection = UpstreamsConfig.EthereumPosConnection()
getMapping(connConfigNode, "execution")?.let {
connection.execution = readEthereumConnection(it)
@@ -175,7 +175,7 @@ class UpstreamsConfigReader(
}
return connection
}
private fun readEthereumConnection(connConfigNode : MappingNode) : UpstreamsConfig.EthereumConnection {
private fun readEthereumConnection(connConfigNode: MappingNode): UpstreamsConfig.EthereumConnection {
val connection = UpstreamsConfig.EthereumConnection()
getMapping(connConfigNode, "rpc")?.let { node ->
getValueAsString(node, "url")?.let { url ->
@@ -211,7 +211,7 @@ class UpstreamsConfigReader(
return connection
}
private fun <T : UpstreamsConfig.UpstreamConnection>readUpstream(config: UpstreamsConfig, upNode: MappingNode, connFactory: () -> T) {
private fun <T : UpstreamsConfig.UpstreamConnection> readUpstream(config: UpstreamsConfig, upNode: MappingNode, connFactory: () -> T) {
val upstream = UpstreamsConfig.Upstream<T>()
readUpstreamCommon(upNode, upstream)
readUpstreamStandard(upNode, upstream)

View File

@@ -4,7 +4,7 @@ import java.util.concurrent.atomic.AtomicReference
class RingSet<T>(
private val maxSize: Int
): Set<T> {
) : Set<T> {
private var seqValues: AtomicReference<List<T>> = AtomicReference(emptyList())
private var set: Set<T> = emptySet()
override val size: Int
@@ -41,4 +41,4 @@ class RingSet<T>(
override fun containsAll(elements: Collection<@UnsafeVariance T>): Boolean {
return set.containsAll(elements)
}
}
}

View File

@@ -21,7 +21,6 @@ import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.SilentException
import io.emeraldpay.dshackle.upstream.MultistreamHolder
import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
import io.emeraldpay.grpc.BlockchainType
import io.emeraldpay.grpc.Chain
import io.grpc.Status

View File

@@ -20,7 +20,11 @@ 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.*
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.Upstream
import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinRpcHead
import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinRpcUpstream
import io.emeraldpay.dshackle.upstream.bitcoin.BitcoinZMQHead
@@ -147,7 +151,7 @@ open class ConfiguredUpstreams(
config: UpstreamsConfig.Upstream<UpstreamsConfig.EthereumPosConnection>,
chain: Chain,
options: UpstreamsConfig.Options
) : Upstream? {
): Upstream? {
val conn = config.connection!!
val execution = conn.execution
if (execution == null) {
@@ -176,7 +180,7 @@ open class ConfiguredUpstreams(
config: UpstreamsConfig.Upstream<UpstreamsConfig.BitcoinConnection>,
chain: Chain,
options: UpstreamsConfig.Options
) : Upstream? {
): Upstream? {
val conn = config.connection!!
val httpFactory = buildHttpFactory(conn)
if (httpFactory == null) {
@@ -218,7 +222,7 @@ open class ConfiguredUpstreams(
config: UpstreamsConfig.Upstream<UpstreamsConfig.EthereumConnection>,
chain: Chain,
options: UpstreamsConfig.Options
) : EthereumRpcUpstream? {
): EthereumRpcUpstream? {
val conn = config.connection!!
val urls = ArrayList<URI>()
@@ -291,7 +295,7 @@ open class ConfiguredUpstreams(
}
}
private fun buildEthereumConnectorFactory(conn: UpstreamsConfig.EthereumConnection, chain: Chain, urls: ArrayList<URI>, forkChoice: ForkChoice): EthereumConnectorFactory? {
private fun buildEthereumConnectorFactory(conn: UpstreamsConfig.EthereumConnection, chain: Chain, urls: ArrayList<URI>, forkChoice: ForkChoice): EthereumConnectorFactory? {
val wsFactoryApi = buildWsFactory(conn, urls)
val httpFactory = buildHttpFactory(conn, urls)
log.info("Using ${chain.chainName} upstream, at ${urls.joinToString()}")

View File

@@ -20,11 +20,9 @@ import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice
import org.slf4j.LoggerFactory
import reactor.core.Disposable
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.core.publisher.Sinks
import reactor.core.scheduler.Schedulers
import reactor.kotlin.core.publisher.toMono
import java.util.concurrent.atomic.AtomicReference
abstract class AbstractHead(
private val forkChoice: ForkChoice

View File

@@ -4,8 +4,8 @@ import io.emeraldpay.dshackle.data.BlockContainer
class DistanceExtractor {
sealed class ChainDistance {
data class Distance(val dist: Long): ChainDistance()
object Fork: ChainDistance()
data class Distance(val dist: Long) : ChainDistance()
object Fork : ChainDistance()
}
companion object {
@@ -25,4 +25,4 @@ class DistanceExtractor {
}
}
}
}
}

View File

@@ -7,4 +7,4 @@ import io.emeraldpay.grpc.Chain
interface HttpFactory {
fun create(id: String?, chain: Chain): Reader<JsonRpcRequest, JsonRpcResponse>
}
}

View File

@@ -42,4 +42,4 @@ open class HttpRpcFactory(
tls
)
}
}
}

View File

@@ -86,8 +86,8 @@ open class BitcoinMultistream(
}
} else {
val newHead = MergedHead(upstreams.map { it.getHead() }, MostWorkForkChoice()).apply {
this.start()
}
this.start()
}
val lagObserver = BitcoinHeadLagObserver(newHead, upstreams)
this.lagObserver = lagObserver
lagObserver.start()

View File

@@ -21,7 +21,9 @@ 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.Head
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.connectors.ConnectorFactory
import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector
@@ -42,8 +44,8 @@ open class EthereumRpcUpstream(
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 val validator: EthereumUpstreamValidator = EthereumUpstreamValidator(this, getOptions())
private val connector: EthereumConnector = connectorFactory.create(this, validator, chain)
private var validatorSubscription: Disposable? = null

View File

@@ -43,4 +43,4 @@ abstract class EthereumUpstream(
override fun getLabels(): Collection<UpstreamsConfig.Labels> {
return node?.let { listOf(it.labels) } ?: emptyList()
}
}
}

View File

@@ -22,7 +22,6 @@ import io.emeraldpay.dshackle.Global
import io.emeraldpay.dshackle.config.UpstreamsConfig
import io.emeraldpay.dshackle.upstream.Upstream
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
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.etherjar.rpc.json.SyncingJson

View File

@@ -7,4 +7,4 @@ import io.emeraldpay.grpc.Chain
interface ConnectorFactory {
fun create(upstream: DefaultUpstream, validator: EthereumUpstreamValidator, chain: Chain): EthereumConnector
fun isValid(): Boolean
}
}

View File

@@ -10,4 +10,4 @@ interface EthereumConnector : Lifecycle {
fun getHead(): Head
fun getApi(): Reader<JsonRpcRequest, JsonRpcResponse>
}
}

View File

@@ -2,7 +2,6 @@ package io.emeraldpay.dshackle.upstream.ethereum.connectors
import io.emeraldpay.dshackle.upstream.DefaultUpstream
import io.emeraldpay.dshackle.upstream.HttpFactory
import io.emeraldpay.dshackle.upstream.HttpRpcFactory
import io.emeraldpay.dshackle.upstream.ethereum.EthereumUpstreamValidator
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsFactory
import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice
@@ -14,18 +13,18 @@ open class EthereumConnectorFactory(
private val wsFactory: EthereumWsFactory?,
private val httpFactory: HttpFactory?,
private val forkChoice: ForkChoice
): ConnectorFactory {
) : ConnectorFactory {
private val log = LoggerFactory.getLogger(EthereumConnectorFactory::class.java)
override fun isValid(): Boolean {
if (preferHttp && httpFactory == null) {
return false;
return false
}
return true
}
override fun create(upstream: DefaultUpstream, validator: EthereumUpstreamValidator, chain: Chain): EthereumConnector {
if (wsFactory!= null && !preferHttp) {
if (wsFactory != null && !preferHttp) {
return EthereumWsConnector(wsFactory, upstream, validator, chain, forkChoice)
}
if (httpFactory == null) {
@@ -33,4 +32,4 @@ open class EthereumConnectorFactory(
}
return EthereumRpcConnector(httpFactory.create(upstream.getId(), chain), wsFactory, upstream.getId(), forkChoice)
}
}
}

View File

@@ -5,9 +5,11 @@ import io.emeraldpay.dshackle.cache.CachesEnabled
import io.emeraldpay.dshackle.reader.Reader
import io.emeraldpay.dshackle.upstream.Head
import io.emeraldpay.dshackle.upstream.MergedHead
import io.emeraldpay.dshackle.upstream.ethereum.*
import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcHead
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsFactory
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsHead
import io.emeraldpay.dshackle.upstream.ethereum.WsConnection
import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice
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
@@ -15,13 +17,13 @@ import org.springframework.context.Lifecycle
import java.time.Duration
class EthereumRpcConnector(
private val directReader : Reader<JsonRpcRequest, JsonRpcResponse>,
private val directReader: Reader<JsonRpcRequest, JsonRpcResponse>,
wsFactory: EthereumWsFactory?,
id : String,
id: String,
forkChoice: ForkChoice
) : EthereumConnector, CachesEnabled {
private val conn : WsConnection?
private val head : Head
private val conn: WsConnection?
private val head: Head
companion object {
private val log = LoggerFactory.getLogger(EthereumRpcConnector::class.java)
@@ -76,4 +78,4 @@ class EthereumRpcConnector(
override fun getHead(): Head {
return head
}
}
}

View File

@@ -58,7 +58,7 @@ class EthereumWsConnector(
}
override fun isRunning(): Boolean {
return head.isRunning
return head.isRunning
}
override fun stop() {
@@ -73,4 +73,4 @@ class EthereumWsConnector(
override fun getHead(): Head {
return head
}
}
}

View File

@@ -20,7 +20,6 @@ import io.emeraldpay.dshackle.data.BlockId
import io.emeraldpay.dshackle.data.TxId
import io.emeraldpay.dshackle.upstream.Head
import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
import org.slf4j.LoggerFactory
import reactor.core.publisher.Flux
import reactor.core.scheduler.Schedulers

View File

@@ -16,7 +16,6 @@
package io.emeraldpay.dshackle.upstream.ethereum.subscribe
import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage
import io.emeraldpay.etherjar.domain.Address
import io.emeraldpay.etherjar.hex.Hex32

View File

@@ -16,7 +16,6 @@
package io.emeraldpay.dshackle.upstream.ethereum.subscribe
import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.NewHeadMessage
import org.slf4j.LoggerFactory
import reactor.core.publisher.Flux

View File

@@ -17,7 +17,6 @@ package io.emeraldpay.dshackle.upstream.ethereum.subscribe
import io.emeraldpay.dshackle.upstream.UpstreamAvailability
import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
import org.slf4j.LoggerFactory
import reactor.core.publisher.Flux
import java.time.Duration

View File

@@ -21,7 +21,6 @@ import io.emeraldpay.dshackle.data.BlockId
import io.emeraldpay.dshackle.data.TxId
import io.emeraldpay.dshackle.reader.Reader
import io.emeraldpay.dshackle.upstream.ethereum.EthereumLikeMultistream
import io.emeraldpay.dshackle.upstream.ethereum.EthereumMultistream
import io.emeraldpay.dshackle.upstream.ethereum.subscribe.json.LogMessage
import io.emeraldpay.etherjar.hex.HexData
import io.emeraldpay.etherjar.rpc.json.TransactionReceiptJson

View File

@@ -21,7 +21,9 @@ 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.Head
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.connectors.ConnectorFactory
import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnector
@@ -42,8 +44,8 @@ open class EthereumPosRpcUpstream(
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 val validator: EthereumUpstreamValidator = EthereumUpstreamValidator(this, getOptions())
private val connector: EthereumConnector = connectorFactory.create(this, validator, chain)
private var validatorSubscription: Disposable? = null

View File

@@ -43,4 +43,4 @@ abstract class EthereumPosUpstream(
override fun getLabels(): Collection<UpstreamsConfig.Labels> {
return node?.let { listOf(it.labels) } ?: emptyList()
}
}
}

View File

@@ -5,8 +5,8 @@ import io.emeraldpay.dshackle.data.BlockContainer
interface ForkChoice {
sealed class ChoiceResult {
data class Updated(val nwhead: BlockContainer): ChoiceResult()
data class Same(val head: BlockContainer?): ChoiceResult()
data class Updated(val nwhead: BlockContainer) : ChoiceResult()
data class Same(val head: BlockContainer?) : ChoiceResult()
}
fun getHead(): BlockContainer?
@@ -14,4 +14,4 @@ interface ForkChoice {
fun filter(block: BlockContainer): Boolean
fun choose(block: BlockContainer): ChoiceResult
}
}

View File

@@ -6,7 +6,7 @@ import java.util.concurrent.atomic.AtomicReference
class MostWorkForkChoice : ForkChoice {
private val head = AtomicReference<BlockContainer>(null)
override fun getHead() : BlockContainer? {
override fun getHead(): BlockContainer? {
return head.get()
}
@@ -28,5 +28,4 @@ class MostWorkForkChoice : ForkChoice {
}
return ForkChoice.ChoiceResult.Same(nwhead)
}
}
}

View File

@@ -7,7 +7,7 @@ import java.util.concurrent.atomic.AtomicReference
class NoChoiceWithPriorityForkChoice(
private val nodeRating: Int
): ForkChoice {
) : ForkChoice {
private val head = AtomicReference<BlockContainer>(null)
private val seenBlocks = RingSet<BlockId>(10)
@@ -33,4 +33,4 @@ class NoChoiceWithPriorityForkChoice(
}
return ForkChoice.ChoiceResult.Same(nwhead)
}
}
}

View File

@@ -5,7 +5,7 @@ import io.emeraldpay.dshackle.data.BlockId
import io.emeraldpay.dshackle.data.RingSet
import java.util.concurrent.atomic.AtomicReference
class PriorityForkChoice: ForkChoice {
class PriorityForkChoice : ForkChoice {
private val head = AtomicReference<BlockContainer>(null)
private val seenBlocks = RingSet<BlockId>(10)
@@ -32,4 +32,4 @@ class PriorityForkChoice: ForkChoice {
}
return ForkChoice.ChoiceResult.Same(nwhead)
}
}
}