diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt index 7fcbb683..b4b9a62b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt @@ -142,22 +142,19 @@ open class UpstreamsConfig { class EthereumConnection : RpcConnection() { var ws: WsEndpoint? = null - var preferHttp: Boolean = false var connectorMode: String? = null fun resolveMode(): ConnectorMode { - return if (preferHttp) { - ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD - } else { - if (connectorMode == null) { - if (ws == null) { - ConnectorMode.RPC_ONLY - } else { - ConnectorMode.WS_ONLY - } + return if (connectorMode == null) { + if (ws != null && rpc != null) { + ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD + } else if (ws == null) { + ConnectorMode.RPC_ONLY } else { - ConnectorMode.parse(connectorMode!!) + ConnectorMode.WS_ONLY } + } else { + ConnectorMode.parse(connectorMode!!) } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt index f5ee5da6..82752f7e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigReader.kt @@ -183,9 +183,6 @@ class UpstreamsConfigReader( val connection = UpstreamsConfig.EthereumConnection() .apply { rpc = readRpcConfig(connConfigNode) } - getValueAsBool(connConfigNode, "prefer-http")?.let { - connection.preferHttp = it - } getValueAsString(connConfigNode, "connector-mode")?.let { connection.connectorMode = it } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt index d613d3fb..309f8544 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/ConfiguredUpstreams.kt @@ -47,6 +47,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsConnectionFactory import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsConnectionPoolFactory import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory +import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory.ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD import io.emeraldpay.dshackle.upstream.forkchoice.ForkChoice import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice import io.emeraldpay.dshackle.upstream.forkchoice.NoChoiceWithPriorityForkChoice @@ -223,7 +224,7 @@ open class ConfiguredUpstreams( } val hashUrl = conn.execution!!.let { - if (it.preferHttp == true) it.rpc?.url ?: it.ws?.url else it.ws?.url ?: it.rpc?.url + if (it.connectorMode == RPC_REQUESTS_WITH_MIXED_HEAD.name) it.rpc?.url ?: it.ws?.url else it.ws?.url ?: it.rpc?.url } val hash = getHash(nodeId, hashUrl!!) val upstream = EthereumPosRpcUpstream( @@ -308,7 +309,7 @@ open class ConfiguredUpstreams( return null } - val hashUrl = if (conn.preferHttp == true) conn.rpc?.url ?: conn.ws?.url else conn.ws?.url ?: conn.rpc?.url + val hashUrl = if (conn.connectorMode == RPC_REQUESTS_WITH_MIXED_HEAD.name) conn.rpc?.url ?: conn.ws?.url else conn.ws?.url ?: conn.rpc?.url val upstream = EthereumRpcUpstream( config.id!!, getHash(nodeId, hashUrl!!), diff --git a/src/test/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigTest.kt index 5b7affd8..a339e98d 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfigTest.kt @@ -27,10 +27,9 @@ internal class UpstreamsConfigTest { Arguments.of( UpstreamsConfig.EthereumConnection() .apply { - preferHttp = true ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546")) }, - ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD + ConnectorMode.WS_ONLY ), Arguments.of( UpstreamsConfig.EthereumConnection() @@ -43,12 +42,19 @@ internal class UpstreamsConfigTest { Arguments.of( UpstreamsConfig.EthereumConnection() .apply { - preferHttp = true - connectorMode = "RPC_REQUESTS_WITH_WS_HEAD" + connectorMode = "RPC_REQUESTS_WITH_MIXED_HEAD" ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546")) }, ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD ), + Arguments.of( + UpstreamsConfig.EthereumConnection() + .apply { + rpc = UpstreamsConfig.HttpEndpoint(URI("http://localhost:8546")) + ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546")) + }, + ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD + ), ) } }