Remove prefer-http option (#241)

This commit is contained in:
KirillPamPam
2023-06-30 16:06:23 +04:00
committed by GitHub
parent f94b320b79
commit fd1db8c3f3
4 changed files with 21 additions and 20 deletions

View File

@@ -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!!)
}
}
}

View File

@@ -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
}

View File

@@ -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!!),

View File

@@ -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
),
)
}
}