Remove prefer-http option (#241)
This commit is contained in:
@@ -142,22 +142,19 @@ open class UpstreamsConfig {
|
|||||||
|
|
||||||
class EthereumConnection : RpcConnection() {
|
class EthereumConnection : RpcConnection() {
|
||||||
var ws: WsEndpoint? = null
|
var ws: WsEndpoint? = null
|
||||||
var preferHttp: Boolean = false
|
|
||||||
var connectorMode: String? = null
|
var connectorMode: String? = null
|
||||||
|
|
||||||
fun resolveMode(): ConnectorMode {
|
fun resolveMode(): ConnectorMode {
|
||||||
return if (preferHttp) {
|
return if (connectorMode == null) {
|
||||||
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD
|
if (ws != null && rpc != null) {
|
||||||
} else {
|
ConnectorMode.RPC_REQUESTS_WITH_WS_HEAD
|
||||||
if (connectorMode == null) {
|
} else if (ws == null) {
|
||||||
if (ws == null) {
|
ConnectorMode.RPC_ONLY
|
||||||
ConnectorMode.RPC_ONLY
|
|
||||||
} else {
|
|
||||||
ConnectorMode.WS_ONLY
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
ConnectorMode.parse(connectorMode!!)
|
ConnectorMode.WS_ONLY
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
ConnectorMode.parse(connectorMode!!)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -183,9 +183,6 @@ class UpstreamsConfigReader(
|
|||||||
val connection = UpstreamsConfig.EthereumConnection()
|
val connection = UpstreamsConfig.EthereumConnection()
|
||||||
.apply { rpc = readRpcConfig(connConfigNode) }
|
.apply { rpc = readRpcConfig(connConfigNode) }
|
||||||
|
|
||||||
getValueAsBool(connConfigNode, "prefer-http")?.let {
|
|
||||||
connection.preferHttp = it
|
|
||||||
}
|
|
||||||
getValueAsString(connConfigNode, "connector-mode")?.let {
|
getValueAsString(connConfigNode, "connector-mode")?.let {
|
||||||
connection.connectorMode = it
|
connection.connectorMode = it
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumRpcUpstream
|
|||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsConnectionFactory
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsConnectionFactory
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsConnectionPoolFactory
|
import io.emeraldpay.dshackle.upstream.ethereum.EthereumWsConnectionPoolFactory
|
||||||
import io.emeraldpay.dshackle.upstream.ethereum.connectors.EthereumConnectorFactory
|
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.ForkChoice
|
||||||
import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice
|
import io.emeraldpay.dshackle.upstream.forkchoice.MostWorkForkChoice
|
||||||
import io.emeraldpay.dshackle.upstream.forkchoice.NoChoiceWithPriorityForkChoice
|
import io.emeraldpay.dshackle.upstream.forkchoice.NoChoiceWithPriorityForkChoice
|
||||||
@@ -223,7 +224,7 @@ open class ConfiguredUpstreams(
|
|||||||
}
|
}
|
||||||
|
|
||||||
val hashUrl = conn.execution!!.let {
|
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 hash = getHash(nodeId, hashUrl!!)
|
||||||
val upstream = EthereumPosRpcUpstream(
|
val upstream = EthereumPosRpcUpstream(
|
||||||
@@ -308,7 +309,7 @@ open class ConfiguredUpstreams(
|
|||||||
return null
|
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(
|
val upstream = EthereumRpcUpstream(
|
||||||
config.id!!,
|
config.id!!,
|
||||||
getHash(nodeId, hashUrl!!),
|
getHash(nodeId, hashUrl!!),
|
||||||
|
|||||||
@@ -27,10 +27,9 @@ internal class UpstreamsConfigTest {
|
|||||||
Arguments.of(
|
Arguments.of(
|
||||||
UpstreamsConfig.EthereumConnection()
|
UpstreamsConfig.EthereumConnection()
|
||||||
.apply {
|
.apply {
|
||||||
preferHttp = true
|
|
||||||
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
|
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
|
||||||
},
|
},
|
||||||
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD
|
ConnectorMode.WS_ONLY
|
||||||
),
|
),
|
||||||
Arguments.of(
|
Arguments.of(
|
||||||
UpstreamsConfig.EthereumConnection()
|
UpstreamsConfig.EthereumConnection()
|
||||||
@@ -43,12 +42,19 @@ internal class UpstreamsConfigTest {
|
|||||||
Arguments.of(
|
Arguments.of(
|
||||||
UpstreamsConfig.EthereumConnection()
|
UpstreamsConfig.EthereumConnection()
|
||||||
.apply {
|
.apply {
|
||||||
preferHttp = true
|
connectorMode = "RPC_REQUESTS_WITH_MIXED_HEAD"
|
||||||
connectorMode = "RPC_REQUESTS_WITH_WS_HEAD"
|
|
||||||
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
|
ws = UpstreamsConfig.WsEndpoint(URI("ws://localhost:8546"))
|
||||||
},
|
},
|
||||||
ConnectorMode.RPC_REQUESTS_WITH_MIXED_HEAD
|
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
|
||||||
|
),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user