From 09ff044b6739983f908d2537281f0e105d8caa20 Mon Sep 17 00:00:00 2001 From: Maxksim Fomenkov Date: Thu, 1 Sep 2022 18:10:08 +0300 Subject: [PATCH 1/3] fix array out of bound exception --- .../dshackle/upstream/ethereum/EthereumBlockValidator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt index 25a84293..3fc2ea84 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt @@ -174,7 +174,7 @@ class EthereumBlockValidator : BlockValidator { private fun BigInteger.asUint64() = this.toByteArray().let { bytes -> ByteArray(8) { val index = bytes.size - it - 1 - if (index < bytes.size) bytes[index] else 0 + if (index < bytes.size && index >= 0) bytes[index] else 0 } } From 3ad0c73d6a6d7f67ac8795c83553065b37ff0116 Mon Sep 17 00:00:00 2001 From: Maxksim Fomenkov Date: Fri, 2 Sep 2022 17:18:55 +0300 Subject: [PATCH 2/3] fixed proxy server performance --- src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt | 2 ++ .../io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt index 69a2b109..d8dd1be5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt @@ -28,6 +28,7 @@ import io.micrometer.core.instrument.Metrics import io.micrometer.core.instrument.Timer import io.netty.channel.ChannelHandler import io.netty.channel.ChannelHandlerContext +import io.netty.channel.nio.NioEventLoopGroup import org.slf4j.LoggerFactory import reactor.netty.http.server.HttpServer import reactor.netty.http.server.HttpServerRoutes @@ -107,6 +108,7 @@ class ProxyServer( serverBuilder .route(this::setupRoutes) + .runOn(NioEventLoopGroup()) .bindNow() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt index d09cda9e..25cd9104 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt @@ -119,7 +119,9 @@ open class WsConnection( .multicast() .directBestEffort() private val sendIdSeq = AtomicInteger(IDS_START) - private val sendExecutor = Executors.newSingleThreadExecutor() + private val sendExecutor = Executors.newFixedThreadPool( + 1.coerceAtLeast(Runtime.getRuntime().availableProcessors() / 2) + ) private var keepConnection = true private var connection: Disposable? = null private val reconnecting = AtomicBoolean(false) From ff684f6a72184e4ffbd8ef7cd7a29d7bce56d76a Mon Sep 17 00:00:00 2001 From: Maxksim Fomenkov Date: Fri, 2 Sep 2022 17:20:49 +0300 Subject: [PATCH 3/3] added info log --- .../io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt index 25cd9104..197fd056 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt @@ -171,6 +171,7 @@ open class WsConnection( private fun connectInternal() { log.info("Connecting to WebSocket: $uri") + log.info("Available processors: ${Runtime.getRuntime().availableProcessors()}") connection?.dispose() connection = HttpClient.create() .resolver(DefaultAddressResolverGroup.INSTANCE)