From 1fdf816ca243c394d4d1b8fe1710d6f361b81923 Mon Sep 17 00:00:00 2001 From: Termina1 Date: Tue, 10 Jan 2023 20:52:43 +0200 Subject: [PATCH] passthrough mode - ignore call specific selectors --- .../io/emeraldpay/dshackle/config/MainConfig.kt | 1 + .../dshackle/config/MainConfigReader.kt | 4 ++++ .../io/emeraldpay/dshackle/rpc/NativeCall.kt | 17 ++++++++++------- .../dshackle/rpc/NativeCallSpec.groovy | 10 +++++++--- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfig.kt index 451d801e..4e228c01 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfig.kt @@ -19,6 +19,7 @@ class MainConfig { var host = "127.0.0.1" var port = 2449 var tls: AuthConfig.ServerTlsAuth? = null + var passthrough: Boolean = false var cache: CacheConfig? = null var proxy: ProxyConfig? = null var upstreams: UpstreamsConfig? = null diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfigReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfigReader.kt index d75f5cd4..e6d4dfe0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfigReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/MainConfigReader.kt @@ -52,6 +52,10 @@ class MainConfigReader( config.port = it } + getValueAsBool(input, "passthrough")?.let { + config.passthrough = it + } + authConfigReader.readServerTls(input)?.let { config.tls = it } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index d7a95981..ae52fc66 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.BlockchainType import io.emeraldpay.dshackle.Chain import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.SilentException -import io.emeraldpay.dshackle.config.CacheConfig +import io.emeraldpay.dshackle.config.MainConfig import io.emeraldpay.dshackle.quorum.CallQuorum import io.emeraldpay.dshackle.quorum.NotLaggingQuorum import io.emeraldpay.dshackle.quorum.QuorumReaderFactory @@ -57,7 +57,7 @@ import java.util.concurrent.atomic.AtomicInteger open class NativeCall( private val multistreamHolder: MultistreamHolder, private val signer: ResponseSigner, - cacheConfig: CacheConfig + config: MainConfig ) { private val log = LoggerFactory.getLogger(NativeCall::class.java) @@ -65,7 +65,8 @@ open class NativeCall( private val nullValue: ByteArray = "null".toByteArray() - private val localRouterEnabled = cacheConfig.requestsCacheEnabled + private val localRouterEnabled = config.cache?.requestsCacheEnabled ?: true + private val passthrough = config.passthrough var quorumReaderFactory: QuorumReaderFactory = QuorumReaderFactory.default() private val ethereumCallSelectors = EnumMap(Chain::class.java) @@ -79,10 +80,12 @@ open class NativeCall( @EventListener fun onUpstreamChangeEvent(event: UpstreamChangeEvent) { - casting[BlockchainType.from(event.chain)]?.let { cast -> - multistreamHolder.getUpstream(event.chain).let { up -> - val reader = up.cast(cast).getReader() - ethereumCallSelectors.putIfAbsent(event.chain, EthereumCallSelector(reader.heightByHash())) + if (!passthrough) { + casting[BlockchainType.from(event.chain)]?.let { cast -> + multistreamHolder.getUpstream(event.chain).let { up -> + val reader = up.cast(cast).getReader() + ethereumCallSelectors.putIfAbsent(event.chain, EthereumCallSelector(reader.heightByHash())) + } } } } diff --git a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy index 3c3a9768..e2b095e7 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/rpc/NativeCallSpec.groovy @@ -22,6 +22,7 @@ import io.emeraldpay.api.proto.BlockchainOuterClass import io.emeraldpay.api.proto.Common import io.emeraldpay.dshackle.Global import io.emeraldpay.dshackle.config.CacheConfig +import io.emeraldpay.dshackle.config.MainConfig import io.emeraldpay.dshackle.quorum.QuorumReaderFactory import io.emeraldpay.dshackle.quorum.QuorumRpcReader import io.emeraldpay.dshackle.reader.Reader @@ -55,7 +56,7 @@ class NativeCallSpec extends Specification { ObjectMapper objectMapper = Global.objectMapper - def nativeCall(MultistreamHolder upstreams = null, ResponseSigner signer = null, Boolean enableCache = true) { + def nativeCall(MultistreamHolder upstreams = null, ResponseSigner signer = null, Boolean enableCache = true, Boolean passthrough = false) { if (upstreams == null) { upstreams = Stub(MultistreamHolder) @@ -64,8 +65,11 @@ class NativeCallSpec extends Specification { signer = Stub(ResponseSigner) } - def config = new CacheConfig() - config.requestsCacheEnabled = enableCache + def config = new MainConfig() + def cacheConfig = new CacheConfig() + cacheConfig.requestsCacheEnabled = enableCache + config.cache = cacheConfig + config.passthrough = passthrough new NativeCall(upstreams, signer, config) }