From dbf5a219604fa9c4aa5f88eeb6ffc94de70db98e Mon Sep 17 00:00:00 2001 From: Vyacheslav Date: Fri, 29 Sep 2023 15:18:47 +0300 Subject: [PATCH] formatting with new ktlint (#312) --- .editorconfig | 4 +- .github/workflows/test.yaml | 2 + Makefile | 2 +- gradle/libs.versions.toml | 2 +- .../io/emeraldpay/dshackle/ChainValue.kt | 2 +- .../io/emeraldpay/dshackle/FileResolver.kt | 2 +- .../io/emeraldpay/dshackle/GrpcServer.kt | 11 +-- .../io/emeraldpay/dshackle/HeapDumpCreator.kt | 2 +- .../io/emeraldpay/dshackle/ProxyStarter.kt | 2 +- .../kotlin/io/emeraldpay/dshackle/TlsSetup.kt | 8 +- .../emeraldpay/dshackle/auth/AuthContext.kt | 2 +- .../dshackle/auth/AuthInterceptor.kt | 6 +- .../io/emeraldpay/dshackle/auth/AuthRpc.kt | 4 +- .../dshackle/auth/processor/AuthProcessor.kt | 7 +- .../auth/processor/AuthProcessorResolver.kt | 2 +- .../dshackle/auth/service/AuthService.kt | 4 +- .../dshackle/auth/service/KeyReader.kt | 2 +- .../dshackle/auth/service/RsaKeyReader.kt | 2 +- .../dshackle/cache/BlockByHeight.kt | 2 +- .../dshackle/cache/BlocksMemCache.kt | 2 +- .../dshackle/cache/BlocksRedisCache.kt | 4 +- .../io/emeraldpay/dshackle/cache/Caches.kt | 8 +- .../dshackle/cache/CachesFactory.kt | 2 +- .../dshackle/cache/HeightByHashAdding.kt | 8 +- .../dshackle/cache/HeightByHashMemCache.kt | 2 +- .../dshackle/cache/HeightByHashRedisCache.kt | 2 +- .../emeraldpay/dshackle/cache/HeightCache.kt | 2 +- .../dshackle/cache/OnBlockRedisCache.kt | 2 +- .../dshackle/cache/OnTxRedisCache.kt | 2 +- .../dshackle/cache/ReceiptMemCache.kt | 2 +- .../dshackle/cache/ReceiptRedisCache.kt | 2 +- .../emeraldpay/dshackle/cache/TxMemCache.kt | 2 +- .../emeraldpay/dshackle/cache/TxRedisCache.kt | 4 +- .../commons/{constatnts.kt => Constatnts.kt} | 0 .../dshackle/commons/SharedFluxHolder.kt | 4 +- .../dshackle/config/AccessLogConfig.kt | 4 +- .../emeraldpay/dshackle/config/AuthConfig.kt | 6 +- .../dshackle/config/AuthorizationConfig.kt | 9 +- .../emeraldpay/dshackle/config/CacheConfig.kt | 2 +- .../dshackle/config/CompressionConfig.kt | 4 +- .../dshackle/config/HealthConfig.kt | 2 +- .../dshackle/config/InvalidConfigException.kt | 4 +- .../dshackle/config/MonitoringConfig.kt | 4 +- .../emeraldpay/dshackle/config/ProxyConfig.kt | 2 +- .../dshackle/config/SignatureConfig.kt | 4 +- .../dshackle/config/TokensConfig.kt | 4 +- .../dshackle/config/UpstreamsConfig.kt | 1 + .../config/context/MultistreamsConfig.kt | 14 ++-- .../config/context/SchedulersConfig.kt | 7 +- .../config/spans/{export.kt => Export.kt} | 5 +- .../config/spans/ProviderSpanHandler.kt | 2 +- .../config/spans/ZipkinSSLCustomizer.kt | 2 +- .../dshackle/data/BlockContainer.kt | 5 +- .../io/emeraldpay/dshackle/data/BlockId.kt | 2 +- .../dshackle/data/DefaultContainer.kt | 2 +- .../io/emeraldpay/dshackle/data/HashId.kt | 2 +- .../dshackle/data/SourceContainer.kt | 2 +- .../emeraldpay/dshackle/data/TxContainer.kt | 6 +- .../io/emeraldpay/dshackle/data/TxId.kt | 2 +- .../dshackle/monitoring/HealthCheckSetup.kt | 22 +++-- .../dshackle/monitoring/MonitoringSetup.kt | 24 +++--- .../monitoring/accesslog/AccessHandlerGrpc.kt | 83 +++++++++++-------- .../monitoring/accesslog/AccessHandlerHttp.kt | 12 +-- .../monitoring/accesslog/AccessLogWriter.kt | 2 +- .../dshackle/monitoring/accesslog/Events.kt | 40 ++++----- .../monitoring/accesslog/EventsBuilder.kt | 66 ++++++++------- .../emeraldpay/dshackle/proxy/BaseHandler.kt | 2 +- .../emeraldpay/dshackle/proxy/HttpHandler.kt | 2 +- .../io/emeraldpay/dshackle/proxy/ProxyCall.kt | 4 +- .../emeraldpay/dshackle/proxy/ProxyServer.kt | 6 +- .../emeraldpay/dshackle/proxy/ReadRpcJson.kt | 10 +-- .../dshackle/proxy/WebsocketHandler.kt | 10 +-- .../emeraldpay/dshackle/proxy/WriteRpcJson.kt | 2 +- .../dshackle/quorum/AlwaysQuorum.kt | 4 +- .../dshackle/quorum/BroadcastQuorum.kt | 4 +- .../emeraldpay/dshackle/quorum/CallQuorum.kt | 4 +- .../dshackle/quorum/MaximumValueQuorum.kt | 4 +- .../dshackle/quorum/NotLaggingQuorum.kt | 4 +- .../dshackle/quorum/NotNullQuorum.kt | 2 +- .../dshackle/quorum/QuorumRpcReader.kt | 8 +- .../dshackle/quorum/ValueAwareQuorum.kt | 10 +-- .../dshackle/reader/BroadcastReader.kt | 17 ++-- .../dshackle/reader/CompoundReader.kt | 4 +- .../dshackle/reader/RekeyingReader.kt | 2 +- .../dshackle/reader/RpcReaderFactory.kt | 6 +- .../dshackle/reader/SpannedReader.kt | 2 +- .../dshackle/reader/TransformingReader.kt | 2 +- .../emeraldpay/dshackle/rpc/BlockchainRpc.kt | 12 +-- .../io/emeraldpay/dshackle/rpc/Describe.kt | 6 +- .../io/emeraldpay/dshackle/rpc/EstimateFee.kt | 10 +-- .../io/emeraldpay/dshackle/rpc/NativeCall.kt | 65 ++++++++------- .../dshackle/rpc/NativeCallStream.kt | 4 +- .../dshackle/rpc/NativeSubscribe.kt | 16 ++-- .../io/emeraldpay/dshackle/rpc/StreamHead.kt | 2 +- .../dshackle/rpc/SubscribeNodeStatus.kt | 28 +++---- .../dshackle/rpc/SubscribeStatus.kt | 2 +- .../dshackle/rpc/TrackBitcoinAddress.kt | 34 ++++---- .../emeraldpay/dshackle/rpc/TrackBitcoinTx.kt | 8 +- .../dshackle/rpc/TrackERC20Address.kt | 8 +- .../dshackle/rpc/TrackEthereumAddress.kt | 8 +- .../dshackle/rpc/TrackEthereumTx.kt | 40 ++++----- .../dshackle/startup/UpstreamChangeEvent.kt | 2 +- .../dshackle/upstream/AbstractChainFees.kt | 2 +- .../dshackle/upstream/AbstractHead.kt | 7 +- .../dshackle/upstream/Capability.kt | 2 +- .../emeraldpay/dshackle/upstream/ChainFees.kt | 2 +- .../upstream/CurrentMultistreamHolder.kt | 2 +- .../dshackle/upstream/DynamicMergedHead.kt | 4 +- .../dshackle/upstream/HeadLagObserver.kt | 2 +- .../dshackle/upstream/HttpRpcFactory.kt | 8 +- .../dshackle/upstream/MatchesResponse.kt | 16 ++-- .../dshackle/upstream/MergedHead.kt | 4 +- .../dshackle/upstream/UpstreamAvailability.kt | 3 +- .../upstream/UpstreamsMatchesResponse.kt | 6 +- .../upstream/bitcoin/AddressActiveCheck.kt | 2 +- .../dshackle/upstream/bitcoin/BitcoinFees.kt | 4 +- .../bitcoin/BitcoinHeadLagObserver.kt | 2 +- .../upstream/bitcoin/BitcoinReader.kt | 2 +- .../upstream/bitcoin/BitcoinRpcHead.kt | 2 +- .../upstream/bitcoin/CachingMempoolData.kt | 2 +- .../upstream/bitcoin/EsploraClient.kt | 6 +- .../upstream/bitcoin/EsploraUnspentReader.kt | 2 +- .../dshackle/upstream/bitcoin/ExtractBlock.kt | 2 +- .../upstream/bitcoin/RemoteUnspentReader.kt | 6 +- .../upstream/bitcoin/RpcUnspentReader.kt | 2 +- .../upstream/bitcoin/XpubAddresses.kt | 2 +- .../upstream/bitcoin/data/EsploraUnspent.kt | 2 +- .../data/EsploraUnspentDeserializer.kt | 2 +- .../upstream/calls/AggregatedCallMethods.kt | 2 +- .../upstream/calls/DefaultBitcoinMethods.kt | 24 ++++-- .../upstream/calls/EthereumCallSelector.kt | 9 +- .../upstream/calls/ManagedCallMethods.kt | 4 +- .../upstream/ethereum/EnrichedMergedHead.kt | 4 +- .../EthereumArchiveBlockNumberReader.kt | 4 +- .../ethereum/EthereumBlockValidator.kt | 26 +++--- .../ethereum/EthereumCachingReader.kt | 27 +++--- .../upstream/ethereum/EthereumDirectReader.kt | 32 +++---- .../ethereum/EthereumEgressSubscription.kt | 4 +- .../upstream/ethereum/EthereumFees.kt | 2 +- .../ethereum/EthereumHeadLagObserver.kt | 2 +- .../upstream/ethereum/EthereumLegacyFees.kt | 2 +- .../ethereum/EthereumLikeRpcUpstream.kt | 2 +- .../upstream/ethereum/EthereumLocalReader.kt | 2 +- .../upstream/ethereum/EthereumPriorityFees.kt | 2 +- .../EthereumWsConnectionPoolFactory.kt | 2 +- .../upstream/ethereum/EthereumWsHead.kt | 6 +- .../ethereum/HeadLivenessValidator.kt | 4 +- .../dshackle/upstream/ethereum/RLP.kt | 4 +- .../upstream/ethereum/WsConnection.kt | 2 +- .../upstream/ethereum/WsConnectionImpl.kt | 35 ++++---- .../ethereum/WsConnectionMultiPool.kt | 2 +- .../upstream/ethereum/WsSubscriptions.kt | 2 +- .../ethereum/connectors/ConnectorFactory.kt | 2 +- .../connectors/EthereumConnectorFactory.kt | 11 +-- .../connectors/EthereumRpcConnector.kt | 15 ++-- .../connectors/EthereumWsConnector.kt | 4 +- .../subscribe/AggregatedPendingTxes.kt | 4 +- .../ethereum/subscribe/ConnectBlockUpdates.kt | 10 +-- .../ethereum/subscribe/ConnectLogs.kt | 2 +- .../ethereum/subscribe/ConnectNewHeads.kt | 2 +- .../subscribe/DefaultPendingTxesSource.kt | 2 +- .../subscribe/EthereumLabelsDetector.kt | 8 +- .../EthereumWsIngressSubscription.kt | 2 +- .../ethereum/subscribe/ProduceLogs.kt | 10 +-- .../ethereum/subscribe/ProduceNewHeads.kt | 4 +- .../subscribe/WebsocketPendingTxes.kt | 2 +- .../ethereum/subscribe/json/LogMessage.kt | 2 +- .../EthereumPosHeadLagObserver.kt | 2 +- .../NoChoiceWithPriorityForkChoice.kt | 2 +- .../dshackle/upstream/grpc/GrpcHead.kt | 4 +- .../auth/ClientAuthenticationInterceptor.kt | 4 +- .../upstream/grpc/auth/GrpcUpstreamsAuth.kt | 6 +- .../upstream/rpcclient/JsonRpcError.kt | 4 +- .../upstream/rpcclient/JsonRpcException.kt | 5 +- .../upstream/rpcclient/JsonRpcGrpcClient.kt | 16 ++-- .../upstream/rpcclient/JsonRpcHttpClient.kt | 4 +- .../upstream/rpcclient/JsonRpcRequest.kt | 6 +- .../upstream/rpcclient/JsonRpcResponse.kt | 2 +- .../rpcclient/JsonRpcUpstreamException.kt | 2 +- .../upstream/rpcclient/JsonRpcWsClient.kt | 8 +- .../upstream/rpcclient/ResponseParser.kt | 14 ++-- .../upstream/rpcclient/ResponseWSParser.kt | 6 +- .../dshackle/upstream/rpcclient/RpcMetrics.kt | 2 +- .../signature/ResponseSignerFactory.kt | 2 +- .../processor/AuthProcessorResolverTest.kt | 6 +- .../auth/processor/AuthProcessorV1Test.kt | 11 +-- .../dshackle/auth/service/AuthServiceTest.kt | 33 +++++--- .../dshackle/auth/service/RsaKeyReaderTest.kt | 6 +- .../dshackle/rpc/NativeCallStreamTest.kt | 20 +++-- .../emeraldpay/dshackle/rpc/SelectorsTest.kt | 44 +++++----- .../grpc/auth/GrpcUpstreamsAuthTest.kt | 25 +++--- 191 files changed, 769 insertions(+), 662 deletions(-) rename src/main/kotlin/io/emeraldpay/dshackle/commons/{constatnts.kt => Constatnts.kt} (100%) rename src/main/kotlin/io/emeraldpay/dshackle/config/spans/{export.kt => Export.kt} (88%) diff --git a/.editorconfig b/.editorconfig index 29d1aaca6..dd82760a4 100644 --- a/.editorconfig +++ b/.editorconfig @@ -3,4 +3,6 @@ continuation_indent_size = 4 ij_kotlin_name_count_to_use_star_import = 2147483647 ij_kotlin_name_count_to_use_star_import_for_members = 2147483647 ij_kotlin_packages_to_use_import_on_demand = dummy.** -ij_groovy_names_count_to_use_import_on_demand = 2147483647 \ No newline at end of file +ij_groovy_names_count_to_use_import_on_demand = 2147483647 +ij_kotlin_allow_trailing_comma_on_call_site = true +ij_kotlin_allow_trailing_comma = true \ No newline at end of file diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 127d8d5dd..08b210216 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -36,6 +36,8 @@ jobs: repo_token: ${{ secrets.GITHUB_TOKEN }} - name: Check run: make test + env: + CI: true - name: Upload Coverage Report uses: codecov/codecov-action@v1 diff --git a/Makefile b/Makefile index 38667bc93..bdc2b0828 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,7 @@ jib: build-foundation jib-docker: build-foundation ./gradlew jibDockerBuild -Pdocker=drpcorg - + clean: ./gradlew clean; cd foundation && ../gradlew clean \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 83ae518dc..6685967c8 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -151,5 +151,5 @@ jib = { id = "com.google.cloud.tools.jib", version = "2.7.1" } spring = { id = "org.springframework.boot", version = "2.6.0" } git = { id = "com.palantir.git-version", version = "0.12.3" } protobuf = { id = "com.google.protobuf", version = "0.9.1" } -ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "10.2.0" } +ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.6.0" } detekt = { id = "io.gitlab.arturbosch.detekt", version.ref = "detekt" } \ No newline at end of file diff --git a/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt b/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt index a4ea26650..0d5ad4255 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/ChainValue.kt @@ -24,7 +24,7 @@ import kotlin.concurrent.withLock * Keeps a lazily created value associated with a Chain */ class ChainValue( - private val factory: (chain: Chain) -> V + private val factory: (chain: Chain) -> V, ) { private val values = EnumMap(Chain::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/FileResolver.kt b/src/main/kotlin/io/emeraldpay/dshackle/FileResolver.kt index d09043bf7..de1e73c90 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/FileResolver.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/FileResolver.kt @@ -19,7 +19,7 @@ package io.emeraldpay.dshackle import java.io.File open class FileResolver( - private val baseDir: File + private val baseDir: File, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt b/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt index 5f440ccc6..63ebdfd9e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/GrpcServer.kt @@ -45,7 +45,7 @@ open class GrpcServer( private val tlsSetup: TlsSetup, private val accessHandler: AccessHandlerGrpc, private val grpcServerBraveInterceptor: ServerInterceptor, - private val authInterceptor: AuthInterceptor + private val authInterceptor: AuthInterceptor, ) { @Value("\${spring.application.max-metadata-size}") private var maxMetadataSize: Int = Defaults.maxMetadataSize @@ -58,7 +58,7 @@ open class GrpcServer( override fun interceptCall( call: ServerCall, headers: io.grpc.Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { call.setCompression(Codec.Gzip().messageEncoding) return next.startCall(call, headers) @@ -102,15 +102,16 @@ open class GrpcServer( val pool = Executors.newFixedThreadPool(20, CustomizableThreadFactory("fixed-grpc-")) serverBuilder.executor( - if (mainConfig.monitoring.enableExtended) + if (mainConfig.monitoring.enableExtended) { ExecutorServiceMetrics.monitor( Metrics.globalRegistry, pool, "fixed-grpc-executor", - Tag.of("reactor_scheduler_id", "_") + Tag.of("reactor_scheduler_id", "_"), ) - else + } else { pool + }, ) val server = serverBuilder.build() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/HeapDumpCreator.kt b/src/main/kotlin/io/emeraldpay/dshackle/HeapDumpCreator.kt index 8b09d7356..bb8147a5a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/HeapDumpCreator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/HeapDumpCreator.kt @@ -48,7 +48,7 @@ class HeapDumpCreator { val bean = ManagementFactory.newPlatformMXBeanProxy( ManagementFactory.getPlatformMBeanServer(), "com.sun.management:type=HotSpotDiagnostic", - HotSpotDiagnosticMXBean::class.java + HotSpotDiagnosticMXBean::class.java, ) bean.setVMOption("HeapDumpOnOutOfMemoryError", "true") bean.setVMOption("HeapDumpPath", fileName) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/ProxyStarter.kt b/src/main/kotlin/io/emeraldpay/dshackle/ProxyStarter.kt index 8d05044fe..baa81121a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/ProxyStarter.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/ProxyStarter.kt @@ -42,7 +42,7 @@ class ProxyStarter( @Autowired private val tlsSetup: TlsSetup, @Autowired private val accessHandlerHttp: AccessHandlerHttp, // depend on Monitoring, declared here just to ensure it's properly initialized before the Proxy - @Autowired private val monitoringSetup: MonitoringSetup + @Autowired private val monitoringSetup: MonitoringSetup, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/TlsSetup.kt b/src/main/kotlin/io/emeraldpay/dshackle/TlsSetup.kt index 29a77d9eb..2a16d6cac 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/TlsSetup.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/TlsSetup.kt @@ -30,7 +30,7 @@ import java.security.cert.CertificateFactory @Service open class TlsSetup( - @Autowired val fileResolver: FileResolver + @Autowired val fileResolver: FileResolver, ) { companion object { @@ -70,12 +70,12 @@ open class TlsSetup( val sslContextBuilder = if (grpc) { GrpcSslContexts.forServer( fileResolver.resolve(config.certificate!!), - fileResolver.resolve(config.key!!) + fileResolver.resolve(config.key!!), ) } else { SslContextBuilder.forServer( fileResolver.resolve(config.certificate!!), - fileResolver.resolve(config.key!!) + fileResolver.resolve(config.key!!), ) } if (config.clientCAs.isNotEmpty()) { @@ -89,7 +89,7 @@ open class TlsSetup( file.inputStream().use { cf.generateCertificate(it) as java.security.cert.X509Certificate } - } + }, ) if (config.clientRequire != null && config.clientRequire!!) { sslContextBuilder.clientAuth(ClientAuth.REQUIRE) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthContext.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthContext.kt index 966acd470..13657bdd2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthContext.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthContext.kt @@ -22,6 +22,6 @@ class AuthContext { data class TokenWrapper( val token: String, val issuedAt: Instant, - val sessionId: String + val sessionId: String, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthInterceptor.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthInterceptor.kt index 23da5b203..758f0d216 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthInterceptor.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthInterceptor.kt @@ -14,17 +14,17 @@ const val REFLECT_METHOD_NAME = "grpc.reflection.v1alpha.ServerReflection/Server @Component class AuthInterceptor( - private val authContext: AuthContext + private val authContext: AuthContext, ) : ServerInterceptor { private val specialMethods = setOf(AUTH_METHOD_NAME, REFLECT_METHOD_NAME) override fun interceptCall( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { val sessionId = headers.get( - Metadata.Key.of(SESSION_ID, ASCII_STRING_MARSHALLER) + Metadata.Key.of(SESSION_ID, ASCII_STRING_MARSHALLER), ) val isOrdinaryMethod = !specialMethods.contains(call.methodDescriptor.fullMethodName) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthRpc.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthRpc.kt index c7ba7278d..43c880c7b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthRpc.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/AuthRpc.kt @@ -13,7 +13,7 @@ import reactor.core.scheduler.Scheduler @Service class AuthRpc( private val authService: AuthService, - private val authScheduler: Scheduler + private val authScheduler: Scheduler, ) : ReactorAuthGrpc.AuthImplBase() { companion object { @@ -39,7 +39,7 @@ class AuthRpc( Mono.error( Status.INTERNAL .withDescription(message) - .asException() + .asException(), ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessor.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessor.kt index 1aeaa81b4..67fb77d18 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessor.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessor.kt @@ -21,7 +21,8 @@ const val SESSION_ID = "sessionId" const val VERSION = "version" enum class AuthVersion { - V1; + V1, + ; companion object { fun getVersion(version: String) = values().find { it.name == version } @@ -32,7 +33,7 @@ enum class AuthVersion { } abstract class AuthProcessor( - private val authorizationConfig: AuthorizationConfig + private val authorizationConfig: AuthorizationConfig, ) { open fun process(keys: KeyReader.Keys, token: String): AuthContext.TokenWrapper { @@ -60,7 +61,7 @@ abstract class AuthProcessor( @Component open class AuthProcessorV1( - authorizationConfig: AuthorizationConfig + authorizationConfig: AuthorizationConfig, ) : AuthProcessor(authorizationConfig) { override fun processInternal(privateKey: PrivateKey): AuthContext.TokenWrapper { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolver.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolver.kt index bc7aeab74..5a2653f5b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolver.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolver.kt @@ -7,7 +7,7 @@ import org.springframework.stereotype.Component @Component class AuthProcessorResolver( - private val authProcessorV1: AuthProcessor + private val authProcessorV1: AuthProcessor, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/service/AuthService.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/service/AuthService.kt index 982046a54..49d2a898f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/service/AuthService.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/service/AuthService.kt @@ -12,7 +12,7 @@ class AuthService( private val authorizationConfig: AuthorizationConfig, private val rsaKeyReader: KeyReader, private val authProcessorResolver: AuthProcessorResolver, - private val authContext: AuthContext + private val authContext: AuthContext, ) { fun authenticate(token: String): String { @@ -24,7 +24,7 @@ class AuthService( val keys = rsaKeyReader.getKeyPair( authorizationConfig.serverConfig.providerPrivateKeyPath, - authorizationConfig.serverConfig.externalPublicKeyPath + authorizationConfig.serverConfig.externalPublicKeyPath, ) val decodedJwt = JWT.decode(token) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/service/KeyReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/service/KeyReader.kt index 608ecf835..3d4f2d65e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/service/KeyReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/service/KeyReader.kt @@ -9,6 +9,6 @@ interface KeyReader { data class Keys( val providerPrivateKey: PrivateKey, - val externalPublicKey: PublicKey + val externalPublicKey: PublicKey, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReader.kt index f6f06be85..0d4f3881c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReader.kt @@ -28,7 +28,7 @@ class RsaKeyReader : KeyReader { return KeyReader.Keys( privateKey, - pubKey + pubKey, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlockByHeight.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlockByHeight.kt index b396abe04..be58861d1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlockByHeight.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlockByHeight.kt @@ -26,7 +26,7 @@ import reactor.core.publisher.Mono */ open class BlockByHeight( private val heights: Reader, - private val blocks: Reader + private val blocks: Reader, ) : Reader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt index 5d3671a86..4f9a64e62 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksMemCache.kt @@ -23,7 +23,7 @@ import io.emeraldpay.dshackle.reader.Reader import reactor.core.publisher.Mono open class BlocksMemCache( - maxSize: Int = 64 + maxSize: Int = 64, ) : Reader { private val mapping = Caffeine.newBuilder() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt index 7910bf067..6cbc03363 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/BlocksRedisCache.kt @@ -33,7 +33,7 @@ import java.time.Instant */ class BlocksRedisCache( redis: RedisReactiveCommands, - chain: Chain + chain: Chain, ) : Reader, OnBlockRedisCache(redis, chain, CachesProto.ValueContainer.ValueType.BLOCK) { @@ -69,7 +69,7 @@ class BlocksRedisCache( BlockId.from(meta.parentHash.toByteArray()), meta.txHashesList.map { TxId(it.toByteArray()) - } + }, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt index 8b9a6fbce..31007ab3c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/Caches.kt @@ -40,7 +40,7 @@ open class Caches( private val redisTxsByHash: TxRedisCache?, private val redisReceipts: ReceiptRedisCache?, private val redisHeightByHashCache: HeightByHashRedisCache?, - private val cacheEnabled: Boolean + private val cacheEnabled: Boolean, ) { companion object { @@ -153,7 +153,7 @@ open class Caches( Flux.fromIterable(transactions) .doOnNext { memTxsByHash.add(it) } .flatMap { redisTxsByHash.add(it, block) } - .then() + .then(), ) } } @@ -224,7 +224,7 @@ open class Caches( /** * Data requested by client */ - REQUESTED + REQUESTED, } class Builder { @@ -298,7 +298,7 @@ open class Caches( } return Caches( blocksByHash!!, blocksByHeight!!, txsByHash!!, receipts!!, - redisBlocksByHash, redisTxsByHash, redisReceiptCache, redisHeightByHashCache, cacheEnabled + redisBlocksByHash, redisTxsByHash, redisReceiptCache, redisHeightByHashCache, cacheEnabled, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt index 9e663a48c..9eff19f75 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/CachesFactory.kt @@ -33,7 +33,7 @@ import kotlin.system.exitProcess @Repository open class CachesFactory( - @Autowired private val cacheConfig: CacheConfig + @Autowired private val cacheConfig: CacheConfig, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashAdding.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashAdding.kt index 87c6fdbc4..baf922a96 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashAdding.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashAdding.kt @@ -31,7 +31,7 @@ import reactor.core.publisher.Mono class HeightByHashAdding( private val mem: Reader, private val redis: HeightByHashCache?, - private val upstreamReader: Reader + private val upstreamReader: Reader, ) : Reader { companion object { @@ -50,12 +50,12 @@ class HeightByHashAdding( return mem.read(key) .switchIfEmpty( Mono.just(key) - .flatMap { redis.read(it) } + .flatMap { redis.read(it) }, ) .switchIfEmpty( Mono.just(key) .flatMap { upstreamReader.read(it) } - .flatMap { redis.add(it).then(Mono.just(it.height)) } + .flatMap { redis.add(it).then(Mono.just(it.height)) }, ) } } @@ -66,7 +66,7 @@ class HeightByHashAdding( .switchIfEmpty( Mono.just(key) .flatMap { upstreamReader.read(it) } - .map { it.height } + .map { it.height }, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashMemCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashMemCache.kt index 12b6e0a22..3acf0f174 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashMemCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashMemCache.kt @@ -23,7 +23,7 @@ import org.slf4j.LoggerFactory import reactor.core.publisher.Mono open class HeightByHashMemCache( - maxSize: Int = 256 + maxSize: Int = 256, ) : Reader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt index 4ccaa13b1..9aa38682d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightByHashRedisCache.kt @@ -33,7 +33,7 @@ import java.util.concurrent.TimeUnit */ class HeightByHashRedisCache( private val redis: RedisReactiveCommands, - private val chain: Chain + private val chain: Chain, ) : Reader, HeightByHashCache { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightCache.kt index 75e07e613..c30cf8114 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/HeightCache.kt @@ -25,7 +25,7 @@ import reactor.core.publisher.Mono * Memory cache for blocks heights, keeps mapping height->hash. */ open class HeightCache( - maxSize: Int = 512 + maxSize: Int = 512, ) : Reader { private val heights = Caffeine.newBuilder() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt index 47e1abf59..23e88b76c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnBlockRedisCache.kt @@ -32,7 +32,7 @@ import kotlin.math.min abstract class OnBlockRedisCache( private val redis: RedisReactiveCommands, private val chain: Chain, - private val valueType: ValueContainer.ValueType + private val valueType: ValueContainer.ValueType, ) : Reader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt index 51dc2ec9b..8ed45cd0a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/OnTxRedisCache.kt @@ -32,7 +32,7 @@ import kotlin.math.min abstract class OnTxRedisCache( private val redis: RedisReactiveCommands, private val chain: Chain, - private val valueType: CachesProto.ValueContainer.ValueType + private val valueType: CachesProto.ValueContainer.ValueType, ) : Reader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptMemCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptMemCache.kt index eccd2455b..70619b8ca 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptMemCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptMemCache.kt @@ -29,7 +29,7 @@ import reactor.core.publisher.Mono */ open class ReceiptMemCache( // how many blocks to keeps in memory - val blocks: Int = 6 + val blocks: Int = 6, ) : Reader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt index 0e648c15f..d03ffe770 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/ReceiptRedisCache.kt @@ -24,7 +24,7 @@ import reactor.core.publisher.Mono open class ReceiptRedisCache( redis: RedisReactiveCommands, - chain: Chain + chain: Chain, ) : OnTxRedisCache(redis, chain, CachesProto.ValueContainer.ValueType.TX_RECEIPT) { override fun deserializeValue(value: CachesProto.ValueContainer): ByteArray { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/TxMemCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/TxMemCache.kt index c13fbdccc..91a4f978a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/TxMemCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/TxMemCache.kt @@ -29,7 +29,7 @@ import reactor.core.publisher.Mono */ open class TxMemCache( // usually there is 100-150 tx per block on Ethereum, we keep data for about 32 blocks by default - private val maxSize: Int = 125 * 32 + private val maxSize: Int = 125 * 32, ) : Reader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt b/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt index 0fc40ab95..b609c7a1d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/cache/TxRedisCache.kt @@ -32,7 +32,7 @@ import reactor.core.publisher.Mono */ open class TxRedisCache( private val redis: RedisReactiveCommands, - private val chain: Chain + private val chain: Chain, ) : Reader, OnTxRedisCache(redis, chain, CachesProto.ValueContainer.ValueType.TX) { @@ -65,7 +65,7 @@ open class TxRedisCache( meta.height, TxId(meta.hash.toByteArray()), BlockId(meta.blockHash.toByteArray()), - value.value.toByteArray() + value.value.toByteArray(), ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/commons/constatnts.kt b/src/main/kotlin/io/emeraldpay/dshackle/commons/Constatnts.kt similarity index 100% rename from src/main/kotlin/io/emeraldpay/dshackle/commons/constatnts.kt rename to src/main/kotlin/io/emeraldpay/dshackle/commons/Constatnts.kt diff --git a/src/main/kotlin/io/emeraldpay/dshackle/commons/SharedFluxHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/commons/SharedFluxHolder.kt index dc0bcb1b9..0229b4c3b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/commons/SharedFluxHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/commons/SharedFluxHolder.kt @@ -17,7 +17,7 @@ class SharedFluxHolder( * I.e., if there is a few calls because of a thread-race only one is kept. * But once it's completed a new one may be created if requested. */ - private val provider: () -> Flux + private val provider: () -> Flux, ) { companion object { @@ -41,7 +41,7 @@ class SharedFluxHolder( provider.invoke() .share() .doFinally { onClose(id) }, - id + id, ) lock.write { if (current != null) { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/AccessLogConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/AccessLogConfig.kt index 1046fdd4d..4e5c45c1d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/AccessLogConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/AccessLogConfig.kt @@ -2,7 +2,7 @@ package io.emeraldpay.dshackle.config class AccessLogConfig( val enabled: Boolean = false, - val includeMessages: Boolean = false + val includeMessages: Boolean = false, ) { var filename: String = "./access_log.jsonl" @@ -15,7 +15,7 @@ class AccessLogConfig( fun disabled(): AccessLogConfig { return AccessLogConfig( - enabled = false + enabled = false, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/AuthConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/AuthConfig.kt index e93d32cef..8c30950d5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/AuthConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/AuthConfig.kt @@ -30,17 +30,17 @@ class AuthConfig { class ClientBasicAuth( val username: String, - val password: String + val password: String, ) : ClientAuth() class ClientTlsAuth( var ca: String? = null, var certificate: String? = null, - var key: String? = null + var key: String? = null, ) : ClientAuth() class ClientTokenAuth( - var publicKeyPath: String? = null + var publicKeyPath: String? = null, ) /** diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/AuthorizationConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/AuthorizationConfig.kt index 222c45386..f2175920b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/AuthorizationConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/AuthorizationConfig.kt @@ -4,7 +4,7 @@ data class AuthorizationConfig( val enabled: Boolean, val publicKeyOwner: String, val serverConfig: ServerConfig, - val clientConfig: ClientConfig + val clientConfig: ClientConfig, ) { fun hasServerConfig() = serverConfig != ServerConfig.default() @@ -12,15 +12,16 @@ data class AuthorizationConfig( companion object { @JvmStatic fun default() = AuthorizationConfig( - false, "", + false, + "", ServerConfig.default(), - ClientConfig.default() + ClientConfig.default(), ) } data class ServerConfig( val providerPrivateKeyPath: String, - val externalPublicKeyPath: String + val externalPublicKeyPath: String, ) { companion object { @JvmStatic diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfig.kt index 8a4a973b2..3c681de22 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/CacheConfig.kt @@ -25,6 +25,6 @@ class CacheConfig { var host: String = "127.0.0.1", var port: Int = 6379, var db: Int? = 0, - var password: String? = null + var password: String? = null, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/CompressionConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/CompressionConfig.kt index 93baf709f..b99864a94 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/CompressionConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/CompressionConfig.kt @@ -1,7 +1,7 @@ package io.emeraldpay.dshackle.config open class CompressionConfig( - var grpc: GRPC = GRPC() + var grpc: GRPC = GRPC(), ) { /** * Config example: @@ -16,7 +16,7 @@ open class CompressionConfig( */ class GRPC( var serverEnabled: Boolean = true, - var clientEnabled: Boolean = true + var clientEnabled: Boolean = true, ) companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt index 2a772390d..b077234f5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/HealthConfig.kt @@ -40,6 +40,6 @@ class HealthConfig { data class ChainConfig( val blockchain: Chain, - val minAvailable: Int = 1 + val minAvailable: Int = 1, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/InvalidConfigException.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/InvalidConfigException.kt index d22783446..a96670188 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/InvalidConfigException.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/InvalidConfigException.kt @@ -19,11 +19,11 @@ package io.emeraldpay.dshackle.config import org.yaml.snakeyaml.error.Mark open class InvalidConfigException( - message: String + message: String, ) : Exception(message) class InvalidConfigYamlException( filename: String, mark: Mark, - message: String + message: String, ) : InvalidConfigException("Invalid YAML configuration $message, at $filename:${mark.line}") diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/MonitoringConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/MonitoringConfig.kt index 6e3a61147..75918e891 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/MonitoringConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/MonitoringConfig.kt @@ -17,7 +17,7 @@ package io.emeraldpay.dshackle.config class MonitoringConfig( val enabled: Boolean, - val prometheus: PrometheusConfig + val prometheus: PrometheusConfig, ) { companion object { @@ -37,7 +37,7 @@ class MonitoringConfig( val enabled: Boolean, val path: String, val host: String, - val port: Int + val port: Int, ) { companion object { fun default(): PrometheusConfig { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt index ddca3a671..ee6c3247c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/ProxyConfig.kt @@ -73,6 +73,6 @@ open class ProxyConfig { /** * Blockchain to dispatch requests */ - val blockchain: Chain + val blockchain: Chain, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt index 57ab07962..3239382af 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/SignatureConfig.kt @@ -5,7 +5,8 @@ import java.util.Locale class SignatureConfig { enum class Algorithm { - NIST_P256; + NIST_P256, + ; fun getCurveName(): String { return if (this == NIST_P256) { @@ -30,6 +31,7 @@ class SignatureConfig { * Signature scheme that we should use */ var algorithm: Algorithm = Algorithm.NIST_P256 + /** * Should we generate signature on this instance if it's not already present */ diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt index afa485e36..51e3b2222 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/TokensConfig.kt @@ -20,7 +20,7 @@ import io.emeraldpay.dshackle.Chain import io.emeraldpay.etherjar.domain.Address class TokensConfig( - val tokens: List + val tokens: List, ) { class Token { @@ -49,6 +49,6 @@ class TokensConfig( } enum class Type { - ERC20 + ERC20, } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt index 64dcb0439..f5024fbb0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/UpstreamsConfig.kt @@ -135,6 +135,7 @@ open class UpstreamsConfig { BITCOIN_JSON_RPC("bitcoin"), DSHACKLE("dshackle", "grpc"), UNKNOWN("unknown"), + ; private val code: Array diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt index 705bebf2b..7741e4309 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/MultistreamsConfig.kt @@ -24,7 +24,7 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) callTargetsHolder: CallTargetsHolder, @Qualifier("headScheduler") headScheduler: Scheduler, - tracer: Tracer + tracer: Tracer, ): List { return Chain.values() .filterNot { it == Chain.UNSPECIFIED } @@ -41,7 +41,7 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) chain: Chain, cachesFactory: CachesFactory, headScheduler: Scheduler, - tracer: Tracer + tracer: Tracer, ): EthereumMultistream { val name = "multi-ethereum-$chain" @@ -50,7 +50,7 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) CopyOnWriteArrayList(), cachesFactory.getCaches(chain), headScheduler, - tracer + tracer, ).also { register(it, name) } } @@ -58,7 +58,7 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) chain: Chain, cachesFactory: CachesFactory, headScheduler: Scheduler, - tracer: Tracer + tracer: Tracer, ): EthereumPosMultiStream { val name = "multi-ethereum-pos-$chain" @@ -67,14 +67,14 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) CopyOnWriteArrayList(), cachesFactory.getCaches(chain), headScheduler, - tracer + tracer, ).also { register(it, name) } } open fun bitcoinMultistream( chain: Chain, cachesFactory: CachesFactory, - headScheduler: Scheduler + headScheduler: Scheduler, ): BitcoinMultistream { val name = "multi-bitcoin-$chain" @@ -82,7 +82,7 @@ open class MultistreamsConfig(val beanFactory: ConfigurableListableBeanFactory) chain, ArrayList(), cachesFactory.getCaches(chain), - headScheduler + headScheduler, ).also { register(it, name) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/context/SchedulersConfig.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/context/SchedulersConfig.kt index fe9a38e21..ddda94f6c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/context/SchedulersConfig.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/context/SchedulersConfig.kt @@ -52,14 +52,15 @@ open class SchedulersConfig { private fun makePool(name: String, size: Int, monitoringConfig: MonitoringConfig): ExecutorService { val pool = Executors.newFixedThreadPool(size, CustomizableThreadFactory("$name-")) - return if (monitoringConfig.enableExtended) + return if (monitoringConfig.enableExtended) { ExecutorServiceMetrics.monitor( Metrics.globalRegistry, pool, name, - Tag.of("reactor_scheduler_id", "_") + Tag.of("reactor_scheduler_id", "_"), ) - else + } else { pool + } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/spans/export.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/spans/Export.kt similarity index 88% rename from src/main/kotlin/io/emeraldpay/dshackle/config/spans/export.kt rename to src/main/kotlin/io/emeraldpay/dshackle/config/spans/Export.kt index 5f48c61b6..204cec26e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/spans/export.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/spans/Export.kt @@ -25,12 +25,13 @@ class NoResponseSpanExportable : SpanExportable { @Component class LongResponseSpanExportable( @Value("\${spans.collect.long-span-threshold}") - private val longSpanThreshold: Long? = null + private val longSpanThreshold: Long? = null, ) : SpanExportable { override fun isExportable(span: MutableSpan): Boolean { return MILLISECONDS.convert( - span.finishTimestamp() - span.startTimestamp(), MICROSECONDS + span.finishTimestamp() - span.startTimestamp(), + MICROSECONDS, ) >= longSpanThreshold!! } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ProviderSpanHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ProviderSpanHandler.kt index 6189e0cdb..2f0c3dd0a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ProviderSpanHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ProviderSpanHandler.kt @@ -79,6 +79,6 @@ class ProviderSpanHandler( private data class SpansInfo( var exportable: Boolean = false, - val spans: MutableList = mutableListOf() + val spans: MutableList = mutableListOf(), ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ZipkinSSLCustomizer.kt b/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ZipkinSSLCustomizer.kt index a36789988..ff908665b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ZipkinSSLCustomizer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/config/spans/ZipkinSSLCustomizer.kt @@ -79,7 +79,7 @@ class ZipkinSSLCustomizer(private val mainConfig: MainConfig) : ZipkinRestTempla override fun intercept( request: HttpRequest, body: ByteArray, - execution: ClientHttpRequestExecution + execution: ClientHttpRequestExecution, ): ClientHttpResponse { request.headers.add("Content-Encoding", "gzip") val gzipped = ByteArrayOutputStream() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt index bb2a31f80..96eddaf59 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockContainer.kt @@ -57,7 +57,7 @@ class BlockContainer( parsed = block, transactions = block.transactions?.map { TxId.from(it.hash) } ?: emptyList(), upstreamId = upstreamId, - parentHash = parent + parentHash = parent, ) } @@ -65,6 +65,7 @@ class BlockContainer( fun from(block: BlockJson<*>): BlockContainer { return from(block, "unknown") } + @JvmStatic fun from(block: BlockJson<*>, upstream: String): BlockContainer { return from(block, Global.objectMapper.writeValueAsBytes(block), upstream) @@ -103,7 +104,7 @@ class BlockContainer( fun copyWithRating(nodeRating: Int): BlockContainer { return BlockContainer( - height, hash, difficulty, timestamp, full, json, parsed, parentHash, transactions, nodeRating + height, hash, difficulty, timestamp, full, json, parsed, parentHash, transactions, nodeRating, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt index b16540b9d..9927ae33d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/BlockId.kt @@ -21,7 +21,7 @@ import io.emeraldpay.etherjar.domain.BlockHash import org.bouncycastle.util.encoders.Hex class BlockId( - value: ByteArray + value: ByteArray, ) : HashId(value) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/DefaultContainer.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/DefaultContainer.kt index 82bc70a7f..7d15a8db8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/DefaultContainer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/DefaultContainer.kt @@ -22,7 +22,7 @@ class DefaultContainer( val blockId: BlockId? = null, val height: Long? = null, json: ByteArray, - parsed: T? = null + parsed: T? = null, ) : SourceContainer(json, parsed) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/HashId.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/HashId.kt index 7355b5115..55dcb9ff2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/HashId.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/HashId.kt @@ -17,7 +17,7 @@ package io.emeraldpay.dshackle.data open class HashId( - val value: ByteArray + val value: ByteArray, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/SourceContainer.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/SourceContainer.kt index 6e42afddd..065dd8811 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/SourceContainer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/SourceContainer.kt @@ -18,7 +18,7 @@ package io.emeraldpay.dshackle.data abstract class SourceContainer( val json: ByteArray?, - private val parsed: Any? + private val parsed: Any?, ) { @Suppress("UNCHECKED_CAST") diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/TxContainer.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/TxContainer.kt index d68ddf95c..e60d9fd22 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/TxContainer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/TxContainer.kt @@ -25,7 +25,7 @@ class TxContainer( val hash: TxId, val blockId: BlockId?, json: ByteArray?, - parsed: Any? = null + parsed: Any? = null, ) : SourceContainer(json, parsed) { companion object { @@ -46,7 +46,7 @@ class TxContainer( TxId.from(tx.hash), tx.blockHash?.let { BlockId.from(it) }, raw, - tx + tx, ) } @@ -56,7 +56,7 @@ class TxContainer( TxId.from(tx.hash), tx.blockHash?.let { BlockId.from(it) }, raw, - tx + tx, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/data/TxId.kt b/src/main/kotlin/io/emeraldpay/dshackle/data/TxId.kt index ce8a64060..befcab135 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/data/TxId.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/data/TxId.kt @@ -21,7 +21,7 @@ import io.emeraldpay.etherjar.rpc.json.TransactionJson import org.bouncycastle.util.encoders.Hex class TxId( - value: ByteArray + value: ByteArray, ) : HashId(value) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt index da8b98e3a..30a7d3b8a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/HealthCheckSetup.kt @@ -30,7 +30,7 @@ import javax.annotation.PreDestroy @Service class HealthCheckSetup( @Autowired private val healthConfig: HealthConfig, - @Autowired private val multistreamHolder: MultistreamHolder + @Autowired private val multistreamHolder: MultistreamHolder, ) { companion object { @@ -51,9 +51,9 @@ class HealthCheckSetup( server = HttpServer.create( InetSocketAddress( healthConfig.host, - healthConfig.port + healthConfig.port, ), - 0 + 0, ) server.createContext(healthConfig.path) { httpExchange -> val response = if (httpExchange.requestURI.query == "detailed") { @@ -115,8 +115,12 @@ class HealthCheckSetup( if (avail < required.minAvailable) { chainUnavailable = true listOf(" LACKS MIN AVAILABILITY") - } else emptyList() - } else emptyList() + } else { + emptyList() + } + } else { + emptyList() + } val upDetails = ups.map { " ${it.getId()} ${it.getStatus()} with lag=${it.getLag()}" } @@ -131,10 +135,12 @@ class HealthCheckSetup( .map { "${it.blockchain.name} UNAVAILABLE" } - } else emptyList() + } else { + emptyList() + } return Detailed( allEnabled && !anyUnavailable, - detailsUnavailable + details + detailsUnavailable + details, ) } @@ -148,6 +154,6 @@ class HealthCheckSetup( data class Detailed( val ok: Boolean, - val details: List + val details: List, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/MonitoringSetup.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/MonitoringSetup.kt index 374513f7d..82c8d8da2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/MonitoringSetup.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/MonitoringSetup.kt @@ -38,7 +38,7 @@ import javax.annotation.PostConstruct @Service class MonitoringSetup( - @Autowired private val monitoringConfig: MonitoringConfig + @Autowired private val monitoringConfig: MonitoringConfig, ) { companion object { @@ -49,15 +49,17 @@ class MonitoringSetup( fun setup() { val prometheusRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT) Metrics.globalRegistry.add(prometheusRegistry) - Metrics.globalRegistry.config().meterFilter(object : MeterFilter { - override fun map(id: Meter.Id): Meter.Id { - if (id.name.startsWith("jvm") || id.name.startsWith("process") || id.name.startsWith("system")) { - return id - } else { - return id.withName("dshackle." + id.name) + Metrics.globalRegistry.config().meterFilter( + object : MeterFilter { + override fun map(id: Meter.Id): Meter.Id { + if (id.name.startsWith("jvm") || id.name.startsWith("process") || id.name.startsWith("system")) { + return id + } else { + return id.withName("dshackle." + id.name) + } } - } - }) + }, + ) if (monitoringConfig.enableJvm) { ClassLoaderMetrics().bindTo(Metrics.globalRegistry) @@ -78,9 +80,9 @@ class MonitoringSetup( val server = HttpServer.create( InetSocketAddress( monitoringConfig.prometheus.host, - monitoringConfig.prometheus.port + monitoringConfig.prometheus.port, ), - 0 + 0, ) server.createContext(monitoringConfig.prometheus.path) { httpExchange -> val response = prometheusRegistry.scrape() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerGrpc.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerGrpc.kt index 6b380d7b7..eef4618b2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerGrpc.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerGrpc.kt @@ -29,7 +29,7 @@ import java.time.Instant @Service class AccessHandlerGrpc( - @Autowired private val accessLogWriter: AccessLogWriter + @Autowired private val accessLogWriter: AccessLogWriter, ) : ServerInterceptor { companion object { @@ -39,9 +39,8 @@ class AccessHandlerGrpc( override fun interceptCall( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { - return when (val method = call.methodDescriptor.bareMethodName) { "SubscribeHead" -> processSubscribeHead(call, headers, next) "SubscribeBalance" -> processSubscribeBalance(call, headers, next, true) @@ -63,15 +62,17 @@ class AccessHandlerGrpc( call: ServerCall, headers: Metadata, next: ServerCallHandler, - builder: EventsBuilder.RequestReply + builder: EventsBuilder.RequestReply, ): ServerCall.Listener { builder.start(headers, call.attributes) val callWrapper: ServerCall = StdCallResponse( - call, builder, accessLogWriter + call, + builder, + accessLogWriter, ) return StdCallListener( next.startCall(callWrapper, headers), - builder + builder, ) } @@ -79,11 +80,13 @@ class AccessHandlerGrpc( private fun processSubscribeHead( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.SubscribeHead() as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.SubscribeHead() as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -92,11 +95,13 @@ class AccessHandlerGrpc( call: ServerCall, headers: Metadata, next: ServerCallHandler, - subscribe: Boolean + subscribe: Boolean, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.SubscribeBalance(subscribe) as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.SubscribeBalance(subscribe) as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -104,11 +109,13 @@ class AccessHandlerGrpc( private fun processSubscribeTxStatus( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.TxStatus() as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.TxStatus() as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -116,11 +123,13 @@ class AccessHandlerGrpc( private fun processNativeCall( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.NativeCall(Instant.now()) as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.NativeCall(Instant.now()) as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -128,11 +137,13 @@ class AccessHandlerGrpc( private fun processNativeSubscribe( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.NativeSubscribe(Events.Channel.GRPC) as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.NativeSubscribe(Events.Channel.GRPC) as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -140,11 +151,13 @@ class AccessHandlerGrpc( private fun processDescribe( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.Describe() as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.Describe() as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -152,11 +165,13 @@ class AccessHandlerGrpc( private fun processStatus( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.Status() as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.Status() as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } @@ -164,17 +179,19 @@ class AccessHandlerGrpc( private fun processEstimateFee( call: ServerCall, headers: Metadata, - next: ServerCallHandler + next: ServerCallHandler, ): ServerCall.Listener { return process( - call, headers, next, - EventsBuilder.EstimateFee() as EventsBuilder.RequestReply<*, ReqT, RespT> + call, + headers, + next, + EventsBuilder.EstimateFee() as EventsBuilder.RequestReply<*, ReqT, RespT>, ) } open class StdCallListener>( val next: ServerCall.Listener, - val builder: EB + val builder: EB, ) : ForwardingServerCallListener() { override fun onMessage(message: Req) { @@ -190,7 +207,7 @@ class AccessHandlerGrpc( open class StdCallResponse>( val next: ServerCall, val builder: EB, - val accessLogWriter: AccessLogWriter + val accessLogWriter: AccessLogWriter, ) : ForwardingServerCall() { override fun getMethodDescriptor(): MethodDescriptor { @@ -204,7 +221,7 @@ class AccessHandlerGrpc( override fun sendMessage(message: RespT) { super.sendMessage(message) accessLogWriter.submit( - builder.onReply(message)!! + builder.onReply(message)!!, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt index 7cea5cf24..eb805bfce 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessHandlerHttp.kt @@ -21,7 +21,7 @@ import kotlin.concurrent.withLock @Service class AccessHandlerHttp( @Autowired private val mainConfig: MainConfig, - @Autowired accessLogWriter: AccessLogWriter + @Autowired accessLogWriter: AccessLogWriter, ) { companion object { @@ -111,7 +111,7 @@ class AccessHandlerHttp( class StandardWsHandlerFactory( private val accessLogWriter: AccessLogWriter, private val wsRequest: WebsocketInbound, - private val blockchain: Chain + private val blockchain: Chain, ) : WsHandlerFactory { override fun call(): RequestHandler { @@ -125,7 +125,7 @@ class AccessHandlerHttp( abstract class AbstractRequestHandler( private val accessLogWriter: AccessLogWriter, - private val channel: Events.Channel + private val channel: Events.Channel, ) : RequestHandler { protected var startTs: Instant? = null protected var request: BlockchainOuterClass.NativeCallRequest? = null @@ -159,7 +159,7 @@ class AccessHandlerHttp( class StandardHandler( accessLogWriter: AccessLogWriter, private val httpRequest: HttpServerRequest, - private val blockchain: Chain + private val blockchain: Chain, ) : RequestHandler, AbstractRequestHandler(accessLogWriter, Events.Channel.JSONRPC) { override fun close() { @@ -177,7 +177,7 @@ class AccessHandlerHttp( class WsRequestHandler( accessLogWriter: AccessLogWriter, private val wsRequest: WebsocketInbound, - private val blockchain: Chain + private val blockchain: Chain, ) : RequestHandler, AbstractRequestHandler(accessLogWriter, Events.Channel.WSJSONRPC) { override fun close() { @@ -195,7 +195,7 @@ class AccessHandlerHttp( class WsSubscriptionHandler( private val accessLogWriter: AccessLogWriter, private val wsRequest: WebsocketInbound, - private val blockchain: Chain + private val blockchain: Chain, ) : SubscriptionHandler { private var builder: EventsBuilder.NativeSubscribeHttp? = null diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriter.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriter.kt index dc07007a0..bc33d3a68 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriter.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/AccessLogWriter.kt @@ -32,7 +32,7 @@ import javax.annotation.PostConstruct @Repository class AccessLogWriter( - @Autowired mainConfig: MainConfig + @Autowired mainConfig: MainConfig, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt index f69f9a4a7..dbe7e40af 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/Events.kt @@ -34,7 +34,7 @@ class Events { abstract class Base( val id: UUID, val method: String, - val channel: Channel + val channel: Channel, ) { val version = "accesslog/v1beta" var ts = Instant.now() @@ -44,7 +44,7 @@ class Events { val blockchain: Chain, method: String, id: UUID, - channel: Channel + channel: Channel, ) : Base(id, method, channel) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -54,7 +54,7 @@ class Events { // initial request details val request: StreamRequestDetails, // index of the current response - val index: Int + val index: Int, ) : ChainBase(blockchain, "SubscribeHead", id, Channel.GRPC) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -67,7 +67,7 @@ class Events { val balanceRequest: BalanceRequest, val addressBalance: AddressBalance, // index of the current response - val index: Int + val index: Int, ) : ChainBase(blockchain, if (subscribe) "SubscribeBalance" else "GetBalance", id, Channel.GRPC) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -78,15 +78,15 @@ class Events { val txStatusRequest: TxStatusRequest, val txStatus: TxStatusResponse, // index of the current response - val index: Int + val index: Int, ) : ChainBase(blockchain, "SubscribeTxStatus", id, Channel.GRPC) data class TxStatusRequest( - val txId: String + val txId: String, ) data class TxStatusResponse( - val confirmations: Int + val confirmations: Int, ) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -113,7 +113,7 @@ class Events { val responseBody: String? = null, val errorMessage: String? = null, val nonce: Long? = null, - val signature: String? = null + val signature: String? = null, ) : ChainBase(blockchain, "NativeCall", id, channel) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -132,14 +132,14 @@ class Events { @JsonInclude(JsonInclude.Include.NON_NULL) class Describe( id: UUID, - val request: StreamRequestDetails + val request: StreamRequestDetails, ) : Base(id, "Describe", Channel.GRPC) @JsonInclude(JsonInclude.Include.NON_NULL) class Status( blockchain: Chain, id: UUID, - val request: StreamRequestDetails + val request: StreamRequestDetails, ) : ChainBase(blockchain, "Status", id, Channel.GRPC) @JsonInclude(JsonInclude.Include.NON_NULL) @@ -147,19 +147,19 @@ class Events { blockchain: Chain, id: UUID, val request: StreamRequestDetails, - val estimateFee: EstimateFeeDetails + val estimateFee: EstimateFeeDetails, ) : ChainBase(blockchain, "EstimateFee", id, Channel.GRPC) data class StreamRequestDetails( val id: UUID, val start: Instant, - val remote: Remote + val remote: Remote, ) data class Remote( val ips: List, val ip: String, - val userAgent: String + val userAgent: String, ) data class NativeCallItemDetails( @@ -167,38 +167,38 @@ class Events { val id: Int, val payloadSizeBytes: Long, val nonce: Long, - val requestParams: String? = null + val requestParams: String? = null, ) data class NativeCallReplyDetails( val id: Int, val succeed: Boolean, val replySizeBytes: Long, - val ts: Instant = Instant.now() + val ts: Instant = Instant.now(), ) data class NativeSubscribeItemDetails( val method: String, - val payloadSizeBytes: Long + val payloadSizeBytes: Long, ) data class NativeSubscribeReplyDetails( val replySizeBytes: Long, - val ts: Instant = Instant.now() + val ts: Instant = Instant.now(), ) data class BalanceRequest( val asset: String, - val addressType: String + val addressType: String, ) data class AddressBalance( val asset: String, - val address: String + val address: String, ) data class EstimateFeeDetails( val mode: String, - val blocks: Int + val blocks: Int, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt index 4049570a4..52216a97b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/monitoring/accesslog/EventsBuilder.kt @@ -66,11 +66,11 @@ class EventsBuilder { companion object { private val remoteIpHeaders = listOf( "x-real-ip", - "x-forwarded-for" + "x-forwarded-for", ) private val remoteIpKeys = listOf( Metadata.Key.of("x-real-ip", Metadata.ASCII_STRING_MARSHALLER), - Metadata.Key.of("x-forwarded-for", Metadata.ASCII_STRING_MARSHALLER) + Metadata.Key.of("x-forwarded-for", Metadata.ASCII_STRING_MARSHALLER), ) private val invalidCharacters = Regex("[\n\t]+") } @@ -78,7 +78,7 @@ class EventsBuilder { var requestDetails = Events.StreamRequestDetails( UUID.randomUUID(), Instant.now(), - Events.Remote(emptyList(), "", "") + Events.Remote(emptyList(), "", ""), ) var chainId: Int = Chain.UNSPECIFIED.id @@ -107,7 +107,7 @@ class EventsBuilder { aLocal -> 1 else -> -1 } - } + }, ).firstOrNull() } @@ -142,8 +142,8 @@ class EventsBuilder { remote = Events.Remote( ips = ips.map { it.hostAddress }, ip = ip, - userAgent = userAgent - ) + userAgent = userAgent, + ), ) } @@ -161,8 +161,8 @@ class EventsBuilder { remote = Events.Remote( ips = ips.map { it.hostAddress }, ip = ip, - userAgent = userAgent - ) + userAgent = userAgent, + ), ) } @@ -192,8 +192,8 @@ class EventsBuilder { remote = Events.Remote( ips = ips.map { it.hostAddress }, ip = ip, - userAgent = userAgent - ) + userAgent = userAgent, + ), ) } @@ -239,7 +239,7 @@ class EventsBuilder { chain, UUID.randomUUID(), requestDetails, - index++ + index++, ) } } @@ -258,7 +258,7 @@ class EventsBuilder { override fun onRequest(msg: BlockchainOuterClass.BalanceRequest) { balanceRequest = Events.BalanceRequest( msg.asset.code.uppercase(Locale.getDefault()), - msg.address.addrTypeCase.name + msg.address.addrTypeCase.name, ) } @@ -275,7 +275,7 @@ class EventsBuilder { requestDetails, balanceRequest!!, addressBalance, - index++ + index++, ) } } @@ -298,7 +298,7 @@ class EventsBuilder { requestDetails, txStatusRequest!!, Events.TxStatusResponse(msg.confirmations), - index++ + index++, ) } @@ -329,8 +329,10 @@ class EventsBuilder { item.nonce, if (accessLogConfig.includeMessages) { if (item.payload != null && !item.payload.isEmpty && item.payload.isValidUtf8) item.payload.toStringUtf8() else "" - } else null - ) + } else { + null + }, + ), ) } } @@ -350,16 +352,18 @@ class EventsBuilder { channel = Events.Channel.GRPC, responseBody = if (accessLogConfig.includeMessages) { if (msg.payload != null && !msg.payload.isEmpty && msg.payload.isValidUtf8) msg.payload.toStringUtf8() else "" - } else null, + } else { + null + }, errorMessage = if (accessLogConfig.includeMessages) msg.errorMessage else null, signature = Hex.encodeHexString(msg.signature.signature.toByteArray()), - nonce = msg.signature.nonce + nonce = msg.signature.nonce, ) } fun onReply( reply: io.emeraldpay.dshackle.rpc.NativeCall.CallResult, - channel: Events.Channel + channel: Events.Channel, ): Events.NativeCall { val item = items.find { it.id == reply.id }!! return Events.NativeCall( @@ -378,13 +382,15 @@ class EventsBuilder { reply.error?.let { it.upstreamError?.message ?: it.message } ?: "" - } else null + } else { + null + }, ) } } class NativeSubscribe( - val channel: Events.Channel + val channel: Events.Channel, ) : Base(), RequestReply { @@ -399,7 +405,7 @@ class EventsBuilder { withChain(msg.chain.number) this.item = Events.NativeSubscribeItemDetails( msg.method, - msg.payload.size().toLong() + msg.payload.size().toLong(), ) } @@ -411,14 +417,14 @@ class EventsBuilder { payloadSizeBytes = msg.payload?.size()?.toLong() ?: 0L, id = UUID.randomUUID(), channel = Events.Channel.GRPC, - responseBody = if (accessLogConfig.includeMessages) (msg.payload?.toStringUtf8() ?: "") else null + responseBody = if (accessLogConfig.includeMessages) (msg.payload?.toStringUtf8() ?: "") else null, ) } } class NativeSubscribeHttp( val channel: Events.Channel, - chain: Chain + chain: Chain, ) : Base(), RequestReply, Long> { @@ -436,7 +442,7 @@ class EventsBuilder { override fun onRequest(msg: Pair) { this.item = Events.NativeSubscribeItemDetails( msg.first, - msg.second?.size?.toLong() ?: 0L + msg.second?.size?.toLong() ?: 0L, ) } @@ -447,7 +453,7 @@ class EventsBuilder { nativeSubscribe = item!!, payloadSizeBytes = msg, id = UUID.randomUUID(), - channel = channel + channel = channel, ) } } @@ -466,7 +472,7 @@ class EventsBuilder { override fun onReply(msg: BlockchainOuterClass.DescribeResponse): Events.Describe { return Events.Describe( id = UUID.randomUUID(), - request = requestDetails + request = requestDetails, ) } } @@ -486,7 +492,7 @@ class EventsBuilder { return Events.Status( blockchain = chain, request = requestDetails, - id = UUID.randomUUID() + id = UUID.randomUUID(), ) } } @@ -515,8 +521,8 @@ class EventsBuilder { id = UUID.randomUUID(), estimateFee = Events.EstimateFeeDetails( mode = mode, - blocks = blocks - ) + blocks = blocks, + ), ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt index 85fba7b70..5e028a1dd 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/BaseHandler.kt @@ -40,7 +40,7 @@ abstract class BaseHandler( chain: Chain, call: ProxyCall, handler: AccessHandlerHttp.RequestHandler, - preserveBatchOrder: Boolean = false + preserveBatchOrder: Boolean = false, ): Publisher { // return empty response for empty request if (call.items.isEmpty()) { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt index aff381e91..0483ea7de 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/HttpHandler.kt @@ -81,7 +81,7 @@ class HttpHandler( fun processRequest( chain: Chain, request: Mono, - handler: AccessHandlerHttp.RequestHandler + handler: AccessHandlerHttp.RequestHandler, ): Flux { return request .map(readRpcJson) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyCall.kt index f4da986f1..c5425495a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyCall.kt @@ -26,7 +26,7 @@ class ProxyCall( /** * Type of the request. The response format depends on it */ - val type: RpcType + val type: RpcType, ) { companion object { @@ -53,6 +53,6 @@ class ProxyCall( * Batch passed as Array of Object. It may be one-element array, i.e., single request, though response * must be formatted as an Array */ - BATCH + BATCH, } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt index 4061e182b..180f69c4d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ProxyServer.kt @@ -45,7 +45,7 @@ class ProxyServer( nativeCall: NativeCall, nativeSubscribe: NativeSubscribe, private val tlsSetup: TlsSetup, - accessHandler: AccessHandlerHttp.HandlerFactory + accessHandler: AccessHandlerHttp.HandlerFactory, ) { companion object { @@ -82,7 +82,9 @@ class ProxyServer( private val httpHandler = HttpHandler(config, readRpcJson, writeRpcJson, nativeCall, accessHandler, requestMetrics) private val wsHandler: WebsocketHandler? = if (config.websocketEnabled) { WebsocketHandler(readRpcJson, writeRpcJson, nativeCall, nativeSubscribe, accessHandler, requestMetrics) - } else null + } else { + null + } fun start() { if (!config.enabled) { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt index dcdca838d..fcc37e84f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/ReadRpcJson.kt @@ -54,34 +54,34 @@ open class ReadRpcJson : Function { throw RpcException( RpcResponseError.CODE_INVALID_REQUEST, "jsonrpc version is not set", - id?.let { JsonRpcResponse.Id.from(it) } + id?.let { JsonRpcResponse.Id.from(it) }, ) } throw RpcException( RpcResponseError.CODE_INVALID_REQUEST, "Unsupported JSON RPC version: " + json["jsonrpc"].toString(), - id?.let { JsonRpcResponse.Id.from(it) } + id?.let { JsonRpcResponse.Id.from(it) }, ) } if (!(json["method"] != null && json["method"] is String)) { throw RpcException( RpcResponseError.CODE_INVALID_REQUEST, "Method is not set", - id?.let { JsonRpcResponse.Id.from(it) } + id?.let { JsonRpcResponse.Id.from(it) }, ) } if (json.containsKey("params") && json["params"] !is List<*>) { throw RpcException( RpcResponseError.CODE_INVALID_REQUEST, "Params must be an array", - id?.let { JsonRpcResponse.Id.from(it) } + id?.let { JsonRpcResponse.Id.from(it) }, ) } RequestJson( json["method"].toString(), // params MAY be omitted (json["params"] ?: emptyList()) as List<*>, - id + id, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt index 9ce907fb4..c152f2cb4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WebsocketHandler.kt @@ -111,7 +111,7 @@ class WebsocketHandler( blockchain: Chain, control: MutableMap>, requests: Flux>, - eventHandlerFactory: AccessHandlerHttp.WsHandlerFactory + eventHandlerFactory: AccessHandlerHttp.WsHandlerFactory, ): Flux { return requests.flatMap { call -> val method = call.method @@ -126,7 +126,7 @@ class WebsocketHandler( // TODO ineffective to encode the params each time just to get size, ideally should get a reference to the original JSON bytes // but it doesn't happen very ofter, only on initial subscribe only for logs with filter Pair(mp.first, mp.second?.let { Global.objectMapper.writeValueAsBytes(it) }) - } + }, ) val currentControl = Sinks.one() control[subscriptionId] = currentControl @@ -165,9 +165,9 @@ class WebsocketHandler( .setId(0) .setMethod("eth_unsubscribe") .setPayload(ByteString.copyFromUtf8("[\"$id\"]")) - .build() + .build(), ) - .build() + .build(), ) val p = control.remove(id.toString()) @@ -216,6 +216,6 @@ class WebsocketHandler( data class WsSubscriptionData( val result: Any?, - val subscription: String + val subscription: String, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt index 83f8c4d91..84bea0eb2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/proxy/WriteRpcJson.kt @@ -103,7 +103,7 @@ open class WriteRpcJson { Flux.concat( Mono.just("["), body, - Mono.just("]") + Mono.just("]"), ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/AlwaysQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/AlwaysQuorum.kt index dddfe18ab..1dd651d3b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/AlwaysQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/AlwaysQuorum.kt @@ -44,7 +44,7 @@ open class AlwaysQuorum : CallQuorum { override fun record( response: ByteArray, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ): Boolean { result = response resolved = true @@ -56,7 +56,7 @@ open class AlwaysQuorum : CallQuorum { override fun record( error: JsonRpcException, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { this.rpcError = error.error sig = signature diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/BroadcastQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/BroadcastQuorum.kt index be126e61b..02a1d1304 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/BroadcastQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/BroadcastQuorum.kt @@ -45,7 +45,7 @@ open class BroadcastQuorum() : CallQuorum, ValueAwareQuorum(String::clas response: ByteArray, responseValue: String?, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { if (txid == null && responseValue != null) { txid = responseValue @@ -58,7 +58,7 @@ open class BroadcastQuorum() : CallQuorum, ValueAwareQuorum(String::clas response: ByteArray?, errorMessage: String?, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { resolvers.add(upstream) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/CallQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/CallQuorum.kt index 735ab2327..047fbdb72 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/CallQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/CallQuorum.kt @@ -28,13 +28,13 @@ interface CallQuorum { fun record( response: ByteArray, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ): Boolean fun record( error: JsonRpcException, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) fun getSignature(): ResponseSigner.Signature? diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/MaximumValueQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/MaximumValueQuorum.kt index 4ad0d6b4d..36edfcfc7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/MaximumValueQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/MaximumValueQuorum.kt @@ -28,7 +28,7 @@ class MaximumValueQuorum : CallQuorum, ValueAwareQuorum(String::class.ja response: ByteArray, responseValue: String?, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { val value = responseValue?.let { str -> HexQuantity.from(str).value.toLong() @@ -51,7 +51,7 @@ class MaximumValueQuorum : CallQuorum, ValueAwareQuorum(String::class.ja response: ByteArray?, errorMessage: String?, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { if (max == null) { resolvers.add(upstream) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotLaggingQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotLaggingQuorum.kt index 04fb1cc0d..de99e6568 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotLaggingQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotLaggingQuorum.kt @@ -46,7 +46,7 @@ class NotLaggingQuorum(val maxLag: Long = 0) : CallQuorum { override fun record( response: ByteArray, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ): Boolean { val lagging = upstream.getLag()?.run { this > maxLag } ?: true if (!lagging) { @@ -61,7 +61,7 @@ class NotLaggingQuorum(val maxLag: Long = 0) : CallQuorum { override fun record( error: JsonRpcException, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { this.rpcError = error.error val lagging = upstream.getLag()?.run { this > maxLag } ?: true diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotNullQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotNullQuorum.kt index e07df6136..b13ae69bb 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotNullQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/NotNullQuorum.kt @@ -21,7 +21,7 @@ class NotNullQuorum : CallQuorum { override fun record( response: ByteArray, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ): Boolean { allFailed = false val receivedNull = response.isEmpty() || Global.nullValue.contentEquals(response) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/QuorumRpcReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/QuorumRpcReader.kt index 6ae3d6fb6..006bd4025 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/QuorumRpcReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/QuorumRpcReader.kt @@ -49,7 +49,7 @@ class QuorumRpcReader( private val apiControl: ApiSource, private val quorum: CallQuorum, signer: ResponseSigner?, - private val tracer: Tracer + private val tracer: Tracer, ) : RpcReader(signer) { companion object { @@ -142,7 +142,7 @@ class QuorumRpcReader( val apiReader = api.getIngressReader() val spanParams = mapOf( SPAN_REQUEST_API_TYPE to apiReader.javaClass.name, - SPAN_REQUEST_UPSTREAM_ID to api.getId() + SPAN_REQUEST_UPSTREAM_ID to api.getId(), ) return SpannedReader(apiReader, tracer, API_READER, spanParams) .read(key) @@ -179,7 +179,7 @@ class QuorumRpcReader( // it may use the error message or other details // val cleanErr: JsonRpcException = getError(key, err) - quorum.record(cleanErr, null, api,) + quorum.record(cleanErr, null, api) // if it's failed after that, then we don't need more calls, stop api source if (quorum.isFailed()) { val msgQuorumFailed = "Quorum is failed, stop api source. Upstream ${api.getId()}, method ${key.method}" @@ -222,7 +222,7 @@ class QuorumRpcReader( val cause = getCause(method) ?: return Mono.empty() if (cause.shouldReturnNull) { Mono.just( - Result(Global.nullValue, null, 1, null) + Result(Global.nullValue, null, 1, null), ) } else { Mono.error(RpcException(1, "No response for method $method. Cause - ${cause.cause}")) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/quorum/ValueAwareQuorum.kt b/src/main/kotlin/io/emeraldpay/dshackle/quorum/ValueAwareQuorum.kt index b68e8004a..3b8d45b07 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/quorum/ValueAwareQuorum.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/quorum/ValueAwareQuorum.kt @@ -25,7 +25,7 @@ import io.emeraldpay.etherjar.rpc.RpcException import org.slf4j.LoggerFactory abstract class ValueAwareQuorum( - val clazz: Class + val clazz: Class, ) : CallQuorum { private val log = LoggerFactory.getLogger(ValueAwareQuorum::class.java) @@ -39,7 +39,7 @@ abstract class ValueAwareQuorum( override fun record( response: ByteArray, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ): Boolean { try { val value = extractValue(response, clazz) @@ -56,7 +56,7 @@ abstract class ValueAwareQuorum( override fun record( error: JsonRpcException, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) { this.rpcError = error.error recordError(null, error.error.message, signature, upstream) @@ -66,14 +66,14 @@ abstract class ValueAwareQuorum( response: ByteArray, responseValue: T?, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) abstract fun recordError( response: ByteArray?, errorMessage: String?, signature: ResponseSigner.Signature?, - upstream: Upstream + upstream: Upstream, ) override fun getError(): JsonRpcError? { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/reader/BroadcastReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/reader/BroadcastReader.kt index ff7935dc2..3f985f4ad 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/reader/BroadcastReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/reader/BroadcastReader.kt @@ -20,10 +20,10 @@ class BroadcastReader( matcher: Selector.Matcher, signer: ResponseSigner?, private val quorum: CallQuorum, - private val tracer: Tracer + private val tracer: Tracer, ) : RpcReader(signer) { private val internalMatcher = Selector.MultiMatcher( - listOf(Selector.AvailabilityMatcher(), matcher) + listOf(Selector.AvailabilityMatcher(), matcher), ) companion object { @@ -58,7 +58,7 @@ class BroadcastReader( quorum.getResult()!!, quorum.getSignature(), upstreams.size, - quorum.getResolvedBy().first() + quorum.getResolvedBy().first(), ) Mono.just(res) } else { @@ -69,22 +69,25 @@ class BroadcastReader( private fun execute( key: JsonRpcRequest, - upstream: Upstream + upstream: Upstream, ): Mono = SpannedReader( - upstream.getIngressReader(), tracer, BROADCAST_READER, mapOf(SPAN_REQUEST_UPSTREAM_ID to upstream.getId()) + upstream.getIngressReader(), + tracer, + BROADCAST_READER, + mapOf(SPAN_REQUEST_UPSTREAM_ID to upstream.getId()), ) .read(key) .map { BroadcastResponse(it, upstream) } .onErrorResume { log.warn("Error during execution ${key.method} from upstream ${upstream.getId()} with message - ${it.message}") Mono.just( - BroadcastResponse(JsonRpcResponse(null, getError(key, it).error), upstream) + BroadcastResponse(JsonRpcResponse(null, getError(key, it).error), upstream), ) } private class BroadcastResponse( val jsonRpcResponse: JsonRpcResponse, - val upstream: Upstream + val upstream: Upstream, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/reader/CompoundReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/reader/CompoundReader.kt index f0e712cd6..22fb1e7b0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/reader/CompoundReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/reader/CompoundReader.kt @@ -26,7 +26,7 @@ import reactor.core.publisher.Mono * Reader returns first value returned by any of the source readers by checking one by one until one of them returns a non-empty result. */ class CompoundReader ( - private vararg val readers: Reader + private vararg val readers: Reader, ) : Reader { companion object { @@ -43,7 +43,7 @@ class CompoundReader ( .timeout(Defaults.timeoutInternal, Mono.empty()) .doOnError { t -> log.warn("Failed to read from $rdr", t) } .onErrorResume { Mono.empty() } - }, 1) + }, 1,) .next() } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/reader/RekeyingReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/reader/RekeyingReader.kt index 5f66e4fab..31c5244fc 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/reader/RekeyingReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/reader/RekeyingReader.kt @@ -29,7 +29,7 @@ class RekeyingReader( /** * Actual reader */ - private val reader: Reader + private val reader: Reader, ) : Reader { override fun read(key: K): Mono { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/reader/RpcReaderFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/reader/RpcReaderFactory.kt index dfd585da8..42712c029 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/reader/RpcReaderFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/reader/RpcReaderFactory.kt @@ -26,7 +26,7 @@ abstract class RpcReader( is JsonRpcException -> err else -> JsonRpcException( JsonRpcResponse.NumberId(key.id), - JsonRpcError(-32603, "Unhandled internal error: ${err.javaClass}: ${err.message}") + JsonRpcError(-32603, "Unhandled internal error: ${err.javaClass}: ${err.message}"), ) } @@ -46,7 +46,7 @@ abstract class RpcReader( val value: ByteArray, val signature: ResponseSigner.Signature?, val quorum: Int, - val resolvedBy: Upstream? + val resolvedBy: Upstream?, ) } @@ -76,6 +76,6 @@ interface RpcReaderFactory { val matcher: Selector.Matcher, val quorum: CallQuorum, val signer: ResponseSigner?, - val tracer: Tracer + val tracer: Tracer, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/reader/SpannedReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/reader/SpannedReader.kt index 47c0486a9..43d43fb90 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/reader/SpannedReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/reader/SpannedReader.kt @@ -17,7 +17,7 @@ class SpannedReader( private val reader: Reader, private val tracer: Tracer, private val name: String, - private val additionalParams: Map = emptyMap() + private val additionalParams: Map = emptyMap(), ) : Reader { override fun read(key: K): Mono { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/reader/TransformingReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/reader/TransformingReader.kt index 056a28316..4c408b1cc 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/reader/TransformingReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/reader/TransformingReader.kt @@ -29,7 +29,7 @@ class TransformingReader( /** * Result transformation */ - private val transformer: Function + private val transformer: Function, ) : Reader { override fun read(key: K): Mono { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt index 2f838cfe6..5fb130dfc 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/BlockchainRpc.kt @@ -91,12 +91,12 @@ class BlockchainRpc( } } startTime = System.currentTimeMillis() - } + }, ).doOnNext { reply -> metrics?.getNativeItemMetrics(idsMap[reply.id] ?: "unknown")?.let { itemMetrics -> itemMetrics.nativeItemResponse.record( System.currentTimeMillis() - startTime, - TimeUnit.MILLISECONDS + TimeUnit.MILLISECONDS, ) if (!reply.succeed) { itemMetrics.nativeItemResponseErr.increment() @@ -116,7 +116,7 @@ class BlockchainRpc( .doOnNext { metrics = chainMetrics.get(it.chain) metrics!!.nativeSubscribeMetric.increment() - } + }, ).doOnNext { metrics?.nativeSubscribeRespMetric?.increment() }.doOnError { failMetric.increment() } @@ -125,7 +125,7 @@ class BlockchainRpc( override fun subscribeHead(request: Mono): Flux { return streamHead.add( request - .doOnNext { chainMetrics.get(it.type).subscribeHeadMetric.increment() } + .doOnNext { chainMetrics.get(it.type).subscribeHeadMetric.increment() }, ).doOnError { failMetric.increment() } } @@ -184,7 +184,7 @@ class BlockchainRpc( .doOnNext { metrics.getBalanceRespMetric.record( System.currentTimeMillis() - startTime, - TimeUnit.MILLISECONDS + TimeUnit.MILLISECONDS, ) } } ?: Flux.error(SilentException.UnsupportedBlockchain(chain)) @@ -210,7 +210,7 @@ class BlockchainRpc( estimateFee.estimateFee(it).doFinally { metrics.estimateFeeRespMetric.record( System.currentTimeMillis() - startTime, - TimeUnit.MILLISECONDS + TimeUnit.MILLISECONDS, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt index 5f4e15852..35075554b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/Describe.kt @@ -28,7 +28,7 @@ import reactor.core.publisher.Mono @Service class Describe( @Autowired private val multistreamHolder: MultistreamHolder, - @Autowired private val subscribeStatus: SubscribeStatus + @Autowired private val subscribeStatus: SubscribeStatus, ) { fun describe(requestMono: Mono): Mono { @@ -56,7 +56,7 @@ class Describe( .setName(label.key) .setValue(label.value) .build() - } + }, ) chainDescription.addNodes(nodeDetails) } @@ -68,7 +68,7 @@ class Describe( Capability.BALANCE -> BlockchainOuterClass.Capabilities.CAP_BALANCE Capability.WS_HEAD -> BlockchainOuterClass.Capabilities.CAP_WS_HEAD } - } + }, ) resp.addChains(chainDescription.build()) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt index 04c5207ec..87fd567b9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/EstimateFee.kt @@ -13,7 +13,7 @@ import reactor.core.publisher.Mono @Service class EstimateFee( - @Autowired private val multistreamHolder: MultistreamHolder + @Autowired private val multistreamHolder: MultistreamHolder, ) { companion object { @@ -24,13 +24,13 @@ class EstimateFee( val chain = Chain.byId(req.chainValue) val up = multistreamHolder.getUpstream(chain) ?: return Mono.error( StatusException( - Status.UNAVAILABLE.withDescription("BLOCKCHAIN UNAVAILABLE: ${req.chainValue}") - ) + Status.UNAVAILABLE.withDescription("BLOCKCHAIN UNAVAILABLE: ${req.chainValue}"), + ), ) val mode = ChainFees.extractMode(req) ?: return Mono.error( StatusException( - Status.UNAVAILABLE.withDescription("UNSUPPORTED MODE: ${req.mode.number}") - ) + Status.UNAVAILABLE.withDescription("UNSUPPORTED MODE: ${req.mode.number}"), + ), ) return up.getFeeEstimation() .estimate(mode, req.blocks) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt index d7a46c519..71dc04db6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCall.kt @@ -72,7 +72,7 @@ open class NativeCall( private val multistreamHolder: MultistreamHolder, private val signer: ResponseSigner, config: MainConfig, - private val tracer: Tracer + private val tracer: Tracer, ) { private val log = LoggerFactory.getLogger(NativeCall::class.java) @@ -87,7 +87,7 @@ open class NativeCall( companion object { val casting: Map> = mapOf( BlockchainType.EVM_POS to EthereumPosMultiStream::class.java, - BlockchainType.EVM_POW to EthereumMultistream::class.java + BlockchainType.EVM_POW to EthereumMultistream::class.java, ) } @@ -97,7 +97,7 @@ open class NativeCall( multistreamHolder.getUpstream(event.chain).let { up -> ethereumCallSelectors.putIfAbsent( event.chain, - EthereumCallSelector(up.caches) + EthereumCallSelector(up.caches), ) } } @@ -121,7 +121,7 @@ open class NativeCall( return@flatMap result .onErrorResume { err -> Mono.just( - CallResult.fail(id, 0, err, null) + CallResult.fail(id, 0, err, null), ) } .doOnNext { callRes -> completeSpan(callRes, requestCount) } @@ -153,7 +153,7 @@ open class NativeCall( ctx: Context, requestCount: Int, requestId: String, - requestSpan: Span? + requestSpan: Span?, ): Context { if (requestCount > 1) { val span = tracer.nextSpan(requestSpan) @@ -167,7 +167,7 @@ open class NativeCall( private fun processCallContext( callContext: CallContext, - requestSpan: Span? + requestSpan: Span?, ): Mono { return if (callContext.isValid()) { run { @@ -186,7 +186,7 @@ open class NativeCall( val error = callContext.getError() Mono.just( - CallResult(error.id, 0, null, error, null, null, null) + CallResult(error.id, 0, null, error, null, null, null), ) } } @@ -222,7 +222,7 @@ open class NativeCall( fun buildSignature( nonce: Long, - signature: ResponseSigner.Signature + signature: ResponseSigner.Signature, ): BlockchainOuterClass.NativeCallReplySignature { val msg = BlockchainOuterClass.NativeCallReplySignature.newBuilder() msg.signature = ByteString.copyFrom(signature.value) @@ -278,7 +278,7 @@ open class NativeCall( fun prepareCall( request: BlockchainOuterClass.NativeCallRequest, - upstream: Multistream + upstream: Multistream, ): Flux { val chain = Chain.byId(request.chainValue) return Flux.fromIterable(request.itemsList) @@ -291,7 +291,7 @@ open class NativeCall( chain: Chain, request: BlockchainOuterClass.NativeCallRequest, requestItem: BlockchainOuterClass.NativeCallItem, - upstream: Multistream + upstream: Multistream, ): Mono { val requestId = requestItem.requestId val requestCount = request.itemsCount @@ -307,11 +307,11 @@ open class NativeCall( requestItem.id, errorMessage, JsonRpcError(RpcResponseError.CODE_METHOD_NOT_EXIST, errorMessage), - null + null, ), requestId, - requestCount - ) + requestCount, + ), ) } // for ethereum the actual block needed for the call may be specified in the call parameters @@ -352,16 +352,17 @@ open class NativeCall( resultDecorator, selector, requestId, - requestCount + requestCount, ) } } private fun getRequestDecorator(method: String): RequestDecorator = - if (method in DefaultEthereumMethods.withFilterIdMethods) + if (method in DefaultEthereumMethods.withFilterIdMethods) { WithFilterIdDecorator() - else + } else { NoneRequestDecorator() + } private fun getResultDecorator(method: String): ResultDecorator = if (method in DefaultEthereumMethods.newFilterMethods) CreateFilterDecorator() else NoneResultDecorator() @@ -382,7 +383,7 @@ open class NativeCall( } } }.switchIfEmpty( - Mono.just(ctx).flatMap(this::executeOnRemote) + Mono.just(ctx).flatMap(this::executeOnRemote), ) .onErrorResume { Mono.just(CallResult.fail(ctx.id, ctx.nonce, it, ctx)) @@ -395,7 +396,7 @@ open class NativeCall( return Mono.error(RpcException(RpcResponseError.CODE_METHOD_NOT_EXIST, "Unsupported method")) } val reader = rpcReaderFactory.create( - RpcReaderData(ctx.upstream, ctx.payload.method, ctx.matcher, ctx.callQuorum, signer, tracer) + RpcReaderData(ctx.upstream, ctx.payload.method, ctx.matcher, ctx.callQuorum, signer, tracer), ) val counter = reader.attempts() @@ -414,20 +415,22 @@ open class NativeCall( Mono.fromSupplier { counter.get().let { attempts -> CallResult.fail( - ctx.id, ctx.nonce, + ctx.id, + ctx.nonce, CallError(1, "No response or no available upstream for ${ctx.payload.method}", null, null), - ctx + ctx, ).also { countFailure(attempts, ctx) } } - } + }, ) } private fun validateResult(bytes: ByteArray, origin: String, ctx: ValidCallContext) { - if (bytes.isEmpty() || nullValue.contentEquals(bytes)) + if (bytes.isEmpty() || nullValue.contentEquals(bytes)) { log.warn("Empty result from origin $origin, method ${ctx.payload.method}, params ${ctx.payload.params}") + } } private fun errorMessage(attempts: Int, method: String): String = @@ -467,7 +470,7 @@ open class NativeCall( abstract class CallContext( val requestId: String, - val requestCount: Int + val requestCount: Int, ) { abstract fun isValid(): Boolean abstract fun get(): ValidCallContext @@ -528,7 +531,7 @@ open class NativeCall( val resultDecorator: ResultDecorator, val forwardedSelector: BlockchainOuterClass.Selector?, requestId: String, - requestCount: Int + requestCount: Int, ) : CallContext(requestId, requestCount) { constructor( @@ -539,10 +542,10 @@ open class NativeCall( callQuorum: CallQuorum, payload: T, requestId: String, - requestCount: Int + requestCount: Int, ) : this( id, nonce, upstream, matcher, callQuorum, payload, - NoneRequestDecorator(), NoneResultDecorator(), null, requestId, requestCount + NoneRequestDecorator(), NoneResultDecorator(), null, requestId, requestCount, ) override fun isValid(): Boolean { @@ -562,7 +565,7 @@ open class NativeCall( fun withPayload(payload: X): ValidCallContext { return ValidCallContext( id, nonce, upstream, matcher, callQuorum, payload, - requestDecorator, resultDecorator, forwardedSelector, requestId, requestCount + requestDecorator, resultDecorator, forwardedSelector, requestId, requestCount, ) } @@ -577,7 +580,7 @@ open class NativeCall( open class InvalidCallContext( private val error: CallError, requestId: String, - requestCount: Int + requestCount: Int, ) : CallContext(requestId, requestCount) { override fun isValid(): Boolean { return false @@ -601,7 +604,7 @@ open class NativeCall( val message: String, val upstreamError: JsonRpcError?, val data: String?, - val upstreamId: String? = null + val upstreamId: String? = null, ) { companion object { @@ -643,7 +646,7 @@ open class NativeCall( val error: CallError?, val signature: ResponseSigner.Signature?, val upstreamId: String?, - val ctx: ValidCallContext? + val ctx: ValidCallContext?, ) { constructor( @@ -652,7 +655,7 @@ open class NativeCall( result: ByteArray?, callError: CallError?, signature: ResponseSigner.Signature?, - ctx: ValidCallContext? + ctx: ValidCallContext?, ) : this(id, nonce, result, callError, signature, callError?.upstreamId, ctx) companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStream.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStream.kt index a8fc7dfb4..ec97cc3f1 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStream.kt @@ -14,7 +14,7 @@ class NativeCallStream( ) { fun nativeCall( - requestMono: Mono + requestMono: Mono, ): Flux { return requestMono.flatMapMany { req -> nativeCall.nativeCall(Mono.just(req)) @@ -64,6 +64,6 @@ class NativeCallStream( private data class StreamNativeResult( val response: NativeCallReplyItem, - val chunkSize: Int + val chunkSize: Int, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt index 1f3b6d9ad..f9b37973f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/NativeSubscribe.kt @@ -39,7 +39,7 @@ import reactor.core.publisher.Mono @Service open class NativeSubscribe( @Autowired private val multistreamHolder: MultistreamHolder, - @Autowired private val signer: ResponseSigner + @Autowired private val signer: ResponseSigner, ) { companion object { @@ -81,17 +81,17 @@ open class NativeSubscribe( fun convertToStatus(t: Throwable) = when (t) { is SilentException.UnsupportedBlockchain -> StatusException( - Status.UNAVAILABLE.withDescription("BLOCKCHAIN UNAVAILABLE: ${t.blockchainId}") + Status.UNAVAILABLE.withDescription("BLOCKCHAIN UNAVAILABLE: ${t.blockchainId}"), ) is UnsupportedOperationException -> StatusException( - Status.UNIMPLEMENTED.withDescription(t.message) + Status.UNIMPLEMENTED.withDescription(t.message), ) else -> { log.warn("Unhandled error", t) StatusException( - Status.INTERNAL.withDescription(t.message) + Status.INTERNAL.withDescription(t.message), ) } } @@ -131,7 +131,7 @@ open class NativeSubscribe( fun buildSignature( nonce: Long, - signature: ResponseSigner.Signature + signature: ResponseSigner.Signature, ): BlockchainOuterClass.NativeCallReplySignature { val msg = BlockchainOuterClass.NativeCallReplySignature.newBuilder() msg.signature = ByteString.copyFrom(signature.value) @@ -143,11 +143,13 @@ open class NativeSubscribe( data class ResponseHolder( val response: Any, - val nonce: Long? + val nonce: Long?, ) { fun getSource(): String? = if (response is HasUpstream) { response.upstreamId.takeIf { it != "unknown" } - } else null + } else { + null + } } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt index 29fc1cee8..a8a074372 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/StreamHead.kt @@ -30,7 +30,7 @@ import reactor.core.publisher.Mono @Service class StreamHead( - @Autowired private val multistreamHolder: MultistreamHolder + @Autowired private val multistreamHolder: MultistreamHolder, ) { private val log = LoggerFactory.getLogger(StreamHead::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeNodeStatus.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeNodeStatus.kt index 668cf6ddc..a7d92a27c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeNodeStatus.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeNodeStatus.kt @@ -21,7 +21,7 @@ import java.util.concurrent.ConcurrentHashMap @Service class SubscribeNodeStatus( - private val multistreams: CurrentMultistreamHolder + private val multistreams: CurrentMultistreamHolder, ) { companion object { @@ -38,7 +38,7 @@ class SubscribeNodeStatus( knownUpstreams[up.getId()] = Sinks.many().multicast().directBestEffort() subscribeUpstreamUpdates(ms, up, knownUpstreams[up.getId()]!!) } - } + }, ) // stop removed upstreams update fluxes val removals = Flux.merge( @@ -57,13 +57,13 @@ class SubscribeNodeStatus( .setStatus( buildStatus( UpstreamAvailability.UNAVAILABLE, - up.getHead().getCurrentHeight() - ) + up.getHead().getCurrentHeight(), + ), ) .build() } } - } + }, ) // subscribe on head/status updates for just added upstreams @@ -85,12 +85,12 @@ class SubscribeNodeStatus( .setNodeId(it.getId()) .setDescription(buildDescription(ms, it)) .setStatus(buildStatus(it.getStatus(), it.getHead().getCurrentHeight())) - .build() + .build(), ), - subscribeUpstreamUpdates(ms, it, knownUpstreams[it.getId()]!!) + subscribeUpstreamUpdates(ms, it, knownUpstreams[it.getId()]!!), ) } - } + }, ) val updates = Flux.merge( multistreams.all().map { ms -> @@ -101,7 +101,7 @@ class SubscribeNodeStatus( .setStatus(buildStatus(it.getStatus(), it.getHead().getCurrentHeight())) .build() } - } + }, ) return Flux.merge(upstreamUpdates, adds, removals, updates) @@ -110,7 +110,7 @@ class SubscribeNodeStatus( private fun subscribeUpstreamUpdates( ms: Multistream, upstream: Upstream, - cancel: Sinks.Many + cancel: Sinks.Many, ): Flux { val heads = upstream.getHead().getFlux() .takeUntilOther(cancel.asFlux()) @@ -121,7 +121,7 @@ class SubscribeNodeStatus( NodeDescription.newBuilder() .setNodeId(upstream.nodeId().toInt()) .setChain(Common.ChainRef.forNumber(ms.chain.id)) - .build() + .build(), ) .setNodeId(upstream.getId()) .setStatus(buildStatus(upstream.getStatus(), block.height)) @@ -141,7 +141,7 @@ class SubscribeNodeStatus( .setNodeId(upstream.getId()) .setDescription(buildDescription(ms, upstream)) .setStatus(buildStatus(upstream.getStatus(), upstream.getHead().getCurrentHeight())) - .build() + .build(), ) return Flux.concat(currentState, Flux.merge(statuses, heads)) } @@ -159,10 +159,10 @@ class SubscribeNodeStatus( .setName(it.key) .setValue(it.value) .build() - } + }, ) .build() - } + }, ) .addAllSupportedSubscriptions(up.getSubscriptionTopics()) .addAllSupportedMethods(up.getMethods().getSupportedMethods()) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt index e9cf744ce..b802fa00d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/SubscribeStatus.kt @@ -28,7 +28,7 @@ import reactor.core.publisher.Mono @Service class SubscribeStatus( - private val multistreamHolder: MultistreamHolder + private val multistreamHolder: MultistreamHolder, ) { fun subscribeStatus(requestMono: Mono): Flux { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt index fcdccd3bc..8cc6964e7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinAddress.kt @@ -43,7 +43,7 @@ import java.util.concurrent.ConcurrentHashMap @Service class TrackBitcoinAddress( - @Autowired private val multistreamHolder: MultistreamHolder + @Autowired private val multistreamHolder: MultistreamHolder, ) : TrackAddress { companion object { @@ -66,8 +66,8 @@ class TrackBitcoinAddress( private val balanceUpstreamMatcher = Selector.MultiMatcher( listOf( Selector.GrpcMatcher(), - Selector.CapabilityMatcher(Capability.BALANCE) - ) + Selector.CapabilityMatcher(Capability.BALANCE), + ), ) @EventListener @@ -119,7 +119,7 @@ class TrackBitcoinAddress( request.address.addressMulti.addressesList .map { addr -> addr.address } // TODO why sorted? - .sorted() + .sorted(), ) } else -> Flux.error(IllegalArgumentException("Unsupported address type")) @@ -130,7 +130,7 @@ class TrackBitcoinAddress( chain: Chain, api: BitcoinMultistream, addresses: Flux, - includeUtxo: Boolean + includeUtxo: Boolean, ): Flux { return addresses .map { Address(chain, it) } @@ -148,7 +148,7 @@ class TrackBitcoinAddress( .switchIfEmpty( Mono.just(0).map { AddressBalance(address, BigInteger.ZERO) - } + }, ) .onErrorResume { t -> log.error("Failed to get unspent", t) @@ -164,8 +164,11 @@ class TrackBitcoinAddress( AddressBalance( address, BigInteger.valueOf(it.value), - if (includeUtxo) listOf(BalanceUtxo(it.txid, it.vout, it.value)) - else emptyList() + if (includeUtxo) { + listOf(BalanceUtxo(it.txid, it.vout, it.value)) + } else { + emptyList() + }, ) }.reduce { a, b -> a.plus(b) } } @@ -183,13 +186,13 @@ class TrackBitcoinAddress( Mono.fromCallable { log.warn("No upstream providing balance for ${api.chain}") } - .then(Mono.error(SilentException.DataUnavailable("BALANCE"))) + .then(Mono.error(SilentException.DataUnavailable("BALANCE"))), ) } fun getRemoteBalance( api: BitcoinMultistream, - request: BlockchainOuterClass.BalanceRequest + request: BlockchainOuterClass.BalanceRequest, ): Flux { return getBalanceGrpc(api).flatMapMany { remote -> remote.getBalance(request) @@ -198,7 +201,7 @@ class TrackBitcoinAddress( fun subscribeRemoteBalance( api: BitcoinMultistream, - request: BlockchainOuterClass.BalanceRequest + request: BlockchainOuterClass.BalanceRequest, ): Flux { return getBalanceGrpc(api).flatMapMany { remote -> remote.subscribeBalance(request) @@ -258,7 +261,7 @@ class TrackBitcoinAddress( .setAsset( Common.Asset.newBuilder() .setChainValue(address.address.chain.id) - .setCode("BTC") + .setCode("BTC"), ) .setAddress(Common.SingleAddress.newBuilder().setAddress(address.address.address)) .addAllUtxo( @@ -268,7 +271,7 @@ class TrackBitcoinAddress( .setIndex(utxo.vout.toLong()) .setTxId(utxo.txid) .build() - } + }, ) .build() } @@ -276,7 +279,7 @@ class TrackBitcoinAddress( open class AddressBalance( val address: Address, var balance: BigInteger = BigInteger.ZERO, - var utxo: List = emptyList() + var utxo: List = emptyList(), ) { constructor(chain: Chain, address: String, balance: BigInteger) : this(Address(chain, address), balance) @@ -293,7 +296,8 @@ class TrackBitcoinAddress( TestNet3Params() } val bitcoinAddress = org.bitcoinj.core.Address.fromString( - network, address + network, + address, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt index aec22cc7b..fc5a27885 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackBitcoinTx.kt @@ -36,7 +36,7 @@ import kotlin.math.min @Service class TrackBitcoinTx( - @Autowired private val multistreamHolder: MultistreamHolder + @Autowired private val multistreamHolder: MultistreamHolder, ) : TrackTx { companion object { @@ -91,7 +91,7 @@ class TrackBitcoinTx( true, status.blockHash, ExtractBlock.getTime(block), - ExtractBlock.getDifficulty(block) + ExtractBlock.getDifficulty(block), ) }.flatMapMany { tx -> withConfirmations(upstream, tx) @@ -154,7 +154,7 @@ class TrackBitcoinTx( Common.BlockInfo.newBuilder() .setBlockId(tx.blockHash!!.substring(2)) .setTimestamp(tx.blockTime!!.toEpochMilli()) - .setHeight(tx.height!!) + .setHeight(tx.height!!), ) } return data.build() @@ -168,7 +168,7 @@ class TrackBitcoinTx( val blockHash: String? = null, val blockTime: Instant? = null, val blockTotalDifficulty: BigInteger? = null, - val confirmations: Long = 0 + val confirmations: Long = 0, ) { fun withHead(headHeight: Long) = diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt index 7c62e12bf..2d5b724b0 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackERC20Address.kt @@ -40,7 +40,7 @@ import javax.annotation.PostConstruct @Service class TrackERC20Address( @Autowired private val multistreamHolder: MultistreamHolder, - @Autowired private val tokensConfig: TokensConfig + @Autowired private val tokensConfig: TokensConfig, ) : TrackAddress { companion object { @@ -61,7 +61,7 @@ class TrackERC20Address( val definition = TokenDefinition( chain, asset, - ERC20Token(Address.from(token.address)) + ERC20Token(Address.from(token.address)), ) tokens[id] = definition log.info("Enable ERC20 balance for $chain:$asset") @@ -134,7 +134,7 @@ class TrackERC20Address( .setAsset( Common.Asset.newBuilder() .setChainValue(address.chain.id) - .setCode(address.tokenName.uppercase(Locale.getDefault())) + .setCode(address.tokenName.uppercase(Locale.getDefault())), ) .setAddress(Common.SingleAddress.newBuilder().setAddress(address.address.toHex())) .build() @@ -145,7 +145,7 @@ class TrackERC20Address( val address: Address, val token: ERC20Token, val tokenName: String, - val balance: BigInteger? = null + val balance: BigInteger? = null, ) { fun withBalance(balance: BigInteger) = TrackedAddress(chain, address, token, tokenName, balance) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt index 1001ec8f7..454e614e5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumAddress.kt @@ -35,7 +35,7 @@ import java.util.Locale @Service class TrackEthereumAddress( - @Autowired private val multistreamHolder: MultistreamHolder + @Autowired private val multistreamHolder: MultistreamHolder, ) : TrackAddress { private val log = LoggerFactory.getLogger(TrackEthereumAddress::class.java) @@ -111,7 +111,7 @@ class TrackEthereumAddress( val addressParsed = Address.from(address.address) return TrackedAddress( chain, - addressParsed + addressParsed, ) } @@ -130,7 +130,7 @@ class TrackEthereumAddress( .setAsset( Common.Asset.newBuilder() .setChainValue(address.chain.id) - .setCode("ETHER") + .setCode("ETHER"), ) .setAddress(Common.SingleAddress.newBuilder().setAddress(address.address.toHex())) .build() @@ -139,7 +139,7 @@ class TrackEthereumAddress( class TrackedAddress( val chain: Chain, val address: Address, - val balance: Wei? = null + val balance: Wei? = null, ) { fun withBalance(balance: Wei) = TrackedAddress(chain, address, balance) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt index 98e236dc3..90580ab26 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/rpc/TrackEthereumTx.kt @@ -48,7 +48,7 @@ import kotlin.math.min class TrackEthereumTx( private val multistreamHolder: MultistreamHolder, @Qualifier("trackTxScheduler") - private val scheduler: Scheduler + private val scheduler: Scheduler, ) : TrackTx { companion object { @@ -109,7 +109,7 @@ class TrackEthereumTx( } } .retryWhen( - Retry.fixedDelay(10, Duration.ofSeconds(2)) + Retry.fixedDelay(10, Duration.ofSeconds(2)), ) .onErrorResume { Mono.empty() } @@ -139,8 +139,8 @@ class TrackEthereumTx( height = block.height, blockTime = block.timestamp, blockTotalDifficulty = block.difficulty, - blockHash = BlockHash(block.hash.value) - ) + blockHash = BlockHash(block.hash.value), + ), ) } else { update(tx) @@ -180,7 +180,7 @@ class TrackEthereumTx( chain, Instant.now(), TransactionId.from(request.txId), - min(max(1, request.confirmationLimit), 100) + min(max(1, request.confirmationLimit), 100), ) return details } @@ -189,11 +189,11 @@ class TrackEthereumTx( return if (block.number != null && block.totalDifficulty != null) { tx.withStatus( blockTotalDifficulty = block.totalDifficulty, - blockTime = block.timestamp + blockTime = block.timestamp, ) } else { tx.withStatus( - mined = false + mined = false, ) } } @@ -219,7 +219,7 @@ class TrackEthereumTx( height = blockTx.blockNumber, found = true, mined = true, - confirmations = 1 + confirmations = 1, ) upstream.getHead().getFlux().next().map { head -> val height = updated.status.height @@ -227,7 +227,7 @@ class TrackEthereumTx( updated } else { updated.withStatus( - confirmations = head.height - height + 1 + confirmations = head.height - height + 1, ) } }.doOnError { t -> @@ -237,8 +237,8 @@ class TrackEthereumTx( Mono.just( tx.withStatus( found = true, - mined = false - ) + mined = false, + ), ) } } @@ -256,7 +256,7 @@ class TrackEthereumTx( Common.BlockInfo.newBuilder() .setBlockId(tx.status.blockHash!!.toHex().substring(2)) .setTimestamp(tx.status.blockTime!!.toEpochMilli()) - .setHeight(tx.status.height!!) + .setHeight(tx.status.height!!), ) } return data.build() @@ -267,19 +267,19 @@ class TrackEthereumTx( val since: Instant, val txid: TransactionId, val maxConfirmations: Int, - val status: TxStatus + val status: TxStatus, ) { constructor( chain: Chain, since: Instant, txid: TransactionId, - maxConfirmations: Int + maxConfirmations: Int, ) : this(chain, since, txid, maxConfirmations, TxStatus()) fun copy( since: Instant = this.since, - status: TxStatus = this.status + status: TxStatus = this.status, ) = TxDetails(chain, since, txid, maxConfirmations, status) fun withStatus( @@ -289,7 +289,7 @@ class TrackEthereumTx( blockHash: BlockHash? = this.status.blockHash, blockTime: Instant? = this.status.blockTime, blockTotalDifficulty: BigInteger? = this.status.blockTotalDifficulty, - confirmations: Long = this.status.confirmations + confirmations: Long = this.status.confirmations, ): TxDetails { return copy( status = this.status.copy( @@ -299,8 +299,8 @@ class TrackEthereumTx( blockHash, blockTime, blockTotalDifficulty, - confirmations - ) + confirmations, + ), ) } @@ -344,7 +344,7 @@ class TrackEthereumTx( val blockHash: BlockHash? = null, val blockTime: Instant? = null, val blockTotalDifficulty: BigInteger? = null, - val confirmations: Long = 0 + val confirmations: Long = 0, ) { fun copy( @@ -354,7 +354,7 @@ class TrackEthereumTx( blockHash: BlockHash? = this.blockHash, blockTime: Instant? = this.blockTime, blockTotalDifficulty: BigInteger? = this.blockTotalDifficulty, - confirmation: Long = this.confirmations + confirmation: Long = this.confirmations, ) = TxStatus(found, height, mined, blockHash, blockTime, blockTotalDifficulty, confirmation) fun clean() = TxStatus(false, null, false, null, null, null, 0) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt b/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt index 728e76b89..bd66465dc 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/startup/UpstreamChangeEvent.kt @@ -36,7 +36,7 @@ class UpstreamChangeEvent( /** * Type of the change */ - val type: ChangeType + val type: ChangeType, ) : CachesEnabled { enum class ChangeType { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractChainFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractChainFees.kt index 11d486e1c..11ec0dd27 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractChainFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractChainFees.kt @@ -12,7 +12,7 @@ import java.util.function.Function abstract class AbstractChainFees( private val heightLimit: Int, private val upstreams: Multistream, - extractTx: (B) -> List? + extractTx: (B) -> List?, ) : ChainFees { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractHead.kt index 2c981fcff..7dba456d5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/AbstractHead.kt @@ -129,7 +129,7 @@ abstract class AbstractHead @JvmOverloads constructor( override fun getFlux(): Flux { return Flux.concat( forkChoice.getHead().toMono(), - stream.asFlux() + stream.asFlux(), ).onBackpressureLatest() } @@ -169,7 +169,10 @@ abstract class AbstractHead @JvmOverloads constructor( log.warn("No head updates $upstreamId for $delay ms @ ${this.javaClass.simpleName}") onNoHeadUpdates() } - }, 180, 30, TimeUnit.SECONDS + }, + 180, + 30, + TimeUnit.SECONDS, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Capability.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Capability.kt index 998e8fdc9..5e2189e59 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/Capability.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/Capability.kt @@ -3,5 +3,5 @@ package io.emeraldpay.dshackle.upstream enum class Capability { RPC, BALANCE, - WS_HEAD + WS_HEAD, } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ChainFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ChainFees.kt index 8d6d36bfe..9cb860920 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ChainFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ChainFees.kt @@ -30,6 +30,6 @@ interface ChainFees { AVG_T50, MIN_ALWAYS, AVG_MIDDLE, - AVG_TOP + AVG_TOP, } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt index fb9068f1a..dca5e1ba4 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/CurrentMultistreamHolder.kt @@ -23,7 +23,7 @@ import javax.annotation.PreDestroy @Component open class CurrentMultistreamHolder( - multistreams: List + multistreams: List, ) : MultistreamHolder { private val log = LoggerFactory.getLogger(CurrentMultistreamHolder::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/DynamicMergedHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/DynamicMergedHead.kt index 175ba8477..f4b676003 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/DynamicMergedHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/DynamicMergedHead.kt @@ -9,7 +9,7 @@ import reactor.core.scheduler.Scheduler open class DynamicMergedHead( forkChoice: ForkChoice, private val label: String = "", - headScheduler: Scheduler + headScheduler: Scheduler, ) : AbstractHead(forkChoice, headScheduler, upstreamId = label), Lifecycle { private var subscription: Disposable? = null @@ -23,7 +23,7 @@ open class DynamicMergedHead( super.start() subscription?.dispose() subscription = super.follow( - dynamicFlux.asFlux() + dynamicFlux.asFlux(), ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HeadLagObserver.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HeadLagObserver.kt index e5aebb7ce..f6d2a1a57 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HeadLagObserver.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HeadLagObserver.kt @@ -36,7 +36,7 @@ abstract class HeadLagObserver( private val followers: Collection, private val distanceExtractor: Extractor, private val lagObserverScheduler: Scheduler, - private val throttling: Duration = Duration.ofSeconds(5) + private val throttling: Duration = Duration.ofSeconds(5), ) : Lifecycle { private val log = LoggerFactory.getLogger(HeadLagObserver::class.java) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt index b5116c8cb..136502273 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/HttpRpcFactory.kt @@ -13,14 +13,14 @@ import io.micrometer.core.instrument.Timer open class HttpRpcFactory( private val url: String, private val basicAuth: AuthConfig.ClientBasicAuth?, - private val tls: ByteArray? + private val tls: ByteArray?, ) : HttpFactory { override fun create(id: String?, chain: Chain): JsonRpcReader { val metricsTags = listOf( // "unknown" is not supposed to happen Tag.of("upstream", id ?: "unknown"), // UNSPECIFIED shouldn't happen too - Tag.of("chain", chain.chainCode) + Tag.of("chain", chain.chainCode), ) val metrics = RpcMetrics( Timer.builder("upstream.rpc.conn") @@ -31,13 +31,13 @@ open class HttpRpcFactory( Counter.builder("upstream.rpc.fail") .description("Number of failures of HTTP JSON RPC requests") .tags(metricsTags) - .register(Metrics.globalRegistry) + .register(Metrics.globalRegistry), ) return JsonRpcHttpClient( url, metrics, basicAuth, - tls + tls, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MatchesResponse.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MatchesResponse.kt index 0b5c56e47..cc389bc0c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MatchesResponse.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MatchesResponse.kt @@ -31,15 +31,15 @@ sealed class MatchesResponse { data class LabelResponse( val name: String, - val values: Collection + val values: Collection, ) : MatchesResponse() data class NotMatchedResponse( - val response: MatchesResponse + val response: MatchesResponse, ) : MatchesResponse() data class MultiResponse( - private val responses: Set + private val responses: Set, ) : MatchesResponse() { val allResponses = mutableSetOf() @@ -57,26 +57,26 @@ sealed class MatchesResponse { } data class MethodResponse( - val method: String + val method: String, ) : MatchesResponse() data class ExistsResponse( - val name: String + val name: String, ) : MatchesResponse() data class CapabilityResponse( - val capability: Capability + val capability: Capability, ) : MatchesResponse() object GrpcResponse : MatchesResponse() data class HeightResponse( val height: Long, - val currentHeight: Long + val currentHeight: Long, ) : MatchesResponse() data class SameNodeResponse( - val upstreamHash: Byte + val upstreamHash: Byte, ) : MatchesResponse() object AvailabilityResponse : MatchesResponse() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt index 6cfb7f3f1..e9abf2516 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/MergedHead.kt @@ -28,7 +28,7 @@ class MergedHead @JvmOverloads constructor( private val sources: Iterable, forkChoice: ForkChoice, headScheduler: Scheduler, - private val label: String = "" + private val label: String = "", ) : AbstractHead(forkChoice, headScheduler, upstreamId = label), Lifecycle, CachesEnabled { private var subscription: Disposable? = null @@ -48,7 +48,7 @@ class MergedHead @JvmOverloads constructor( subscription = super.follow( Flux.merge(sources.map { it.getFlux() }).doOnNext { log.debug("New MERGED $label head $it") - } + }, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamAvailability.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamAvailability.kt index 11e236430..b455eacc9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamAvailability.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamAvailability.kt @@ -41,7 +41,8 @@ enum class UpstreamAvailability(val grpcId: Int) { /** * Unavailable node */ - UNAVAILABLE(5); + UNAVAILABLE(5), + ; fun isBetterTo(other: UpstreamAvailability): Boolean { return other.grpcId > grpcId diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamsMatchesResponse.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamsMatchesResponse.kt index dcef474a4..eeee1be66 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamsMatchesResponse.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/UpstreamsMatchesResponse.kt @@ -15,7 +15,7 @@ class UpstreamsMatchesResponse { "eth_getTransactionByBlockHashAndIndex", "eth_getTransactionByBlockNumberAndIndex", "eth_getUncleByBlockHashAndIndex", - "eth_getUncleByBlockNumberAndIndex" + "eth_getUncleByBlockNumberAndIndex", ) } @@ -69,12 +69,12 @@ class UpstreamsMatchesResponse { data class NotMatchesCause( val shouldReturnNull: Boolean, - val cause: String? = null + val cause: String? = null, ) private class UpstreamNotMatchedResponse( val upstreamId: String, - val matchesResponse: MatchesResponse + val matchesResponse: MatchesResponse, ) { val matchesResponses: Set = when (matchesResponse) { is MultiResponse -> matchesResponse.allResponses diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/AddressActiveCheck.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/AddressActiveCheck.kt index a46d7c71f..5b65b3ed6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/AddressActiveCheck.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/AddressActiveCheck.kt @@ -20,7 +20,7 @@ import org.slf4j.LoggerFactory import reactor.core.publisher.Mono open class AddressActiveCheck( - private val esploraClient: EsploraClient + private val esploraClient: EsploraClient, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinFees.kt index 2db0f1775..c33a66ba5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinFees.kt @@ -76,7 +76,7 @@ class BitcoinFees( return reader.getTx(txid) .switchIfEmpty( Mono.fromCallable { log.warn("No tx $txid") } - .then(Mono.empty()) + .then(Mono.empty()), ) .flatMap { extractVOuts(it).let { @@ -134,7 +134,7 @@ class BitcoinFees( BlockchainOuterClass.EstimateFeeResponse.newBuilder() .setBitcoinStd( BlockchainOuterClass.BitcoinStdFees.newBuilder() - .setSatPerKb(fee) + .setSatPerKb(fee), ) .build() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinHeadLagObserver.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinHeadLagObserver.kt index b7abae4e0..3c1715c8f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinHeadLagObserver.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinHeadLagObserver.kt @@ -26,7 +26,7 @@ import reactor.core.scheduler.Scheduler class BitcoinHeadLagObserver( master: Head, followers: Collection, - headScheduler: Scheduler + headScheduler: Scheduler, ) : HeadLagObserver(master, followers, DistanceExtractor::extractPowDistance, headScheduler) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt index 8ae68e9f9..f7c99796b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt @@ -32,7 +32,7 @@ import reactor.kotlin.core.publisher.cast open class BitcoinReader( private val upstreams: BitcoinMultistream, head: Head, - esploraClient: EsploraClient? + esploraClient: EsploraClient?, ) : Lifecycle { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt index 52f9ca98b..b3944ede9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinRpcHead.kt @@ -36,7 +36,7 @@ class BitcoinRpcHead( private val api: JsonRpcReader, private val extractBlock: ExtractBlock, private val interval: Duration = Duration.ofSeconds(15), - headScheduler: Scheduler + headScheduler: Scheduler, ) : Head, AbstractHead(MostWorkForkChoice(), headScheduler, awaitHeadTimeoutMs = 1200_000), Lifecycle { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt index f4df9af99..acda2cbca 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/CachingMempoolData.kt @@ -32,7 +32,7 @@ import java.util.concurrent.locks.ReentrantLock open class CachingMempoolData( private val upstreams: BitcoinMultistream, - private val head: Head + private val head: Head, ) : Lifecycle { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClient.kt index 996d9a31f..f9364dbae 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClient.kt @@ -37,7 +37,7 @@ import java.util.function.Consumer class EsploraClient( private val url: URI, basicAuth: AuthConfig.ClientBasicAuth? = null, - tlsCAAuth: ByteArray? = null + tlsCAAuth: ByteArray? = null, ) { companion object { @@ -112,8 +112,8 @@ class EsploraClient( EsploraException( "HTTP Code: ${ header.status().code() - } for ${url.scheme}://${url.host}${header.fullPath()}" - ) + } for ${url.scheme}://${url.host}${header.fullPath()}", + ), ) } else { bytes.aggregate().asByteArray() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraUnspentReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraUnspentReader.kt index 5c5317a81..58d39d673 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraUnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraUnspentReader.kt @@ -25,7 +25,7 @@ import java.util.function.Function class EsploraUnspentReader( private val esploraClient: EsploraClient, - private val head: Head + private val head: Head, ) : UnspentReader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ExtractBlock.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ExtractBlock.kt index 3cc8ea680..fb3f381b2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ExtractBlock.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/ExtractBlock.kt @@ -68,7 +68,7 @@ class ExtractBlock { json, data, BlockId.from(parentHash), - transactions + transactions, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RemoteUnspentReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RemoteUnspentReader.kt index a96b3d6aa..609f847bf 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RemoteUnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RemoteUnspentReader.kt @@ -10,7 +10,7 @@ import org.slf4j.LoggerFactory import reactor.core.publisher.Mono class RemoteUnspentReader( - val upstreams: BitcoinMultistream + val upstreams: BitcoinMultistream, ) : UnspentReader { companion object { @@ -20,8 +20,8 @@ class RemoteUnspentReader( private val selector = Selector.MultiMatcher( listOf( Selector.GrpcMatcher(), - Selector.CapabilityMatcher(Capability.BALANCE) - ) + Selector.CapabilityMatcher(Capability.BALANCE), + ), ) override fun read(key: Address): Mono> { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReader.kt index adb382e89..19db031e9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReader.kt @@ -28,7 +28,7 @@ import org.slf4j.LoggerFactory import reactor.core.publisher.Mono class RpcUnspentReader( - private val upstreams: BitcoinMultistream + private val upstreams: BitcoinMultistream, ) : UnspentReader { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddresses.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddresses.kt index 6ff4a37a1..4f55f8767 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddresses.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddresses.kt @@ -30,7 +30,7 @@ import reactor.util.function.Tuples import java.util.concurrent.atomic.AtomicInteger open class XpubAddresses( - private val addressActiveCheck: AddressActiveCheck + private val addressActiveCheck: AddressActiveCheck, ) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspent.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspent.kt index 840386be1..76ed11773 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspent.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspent.kt @@ -22,5 +22,5 @@ data class EsploraUnspent( val vout: Int, val value: Long, val timestamp: Instant, - val height: Long + val height: Long, ) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspentDeserializer.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspentDeserializer.kt index e6581d9c9..71ad6af57 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspentDeserializer.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/data/EsploraUnspentDeserializer.kt @@ -30,7 +30,7 @@ class EsploraUnspentDeserializer : JsonDeserializer() { node.get("vout").asInt(), node.get("value").asLong(), Instant.ofEpochSecond(status.get("block_time").asLong()), - status.get("block_height").asLong() + status.get("block_height").asLong(), ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt index fa4ed09c1..b87d01cef 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/AggregatedCallMethods.kt @@ -23,7 +23,7 @@ import java.util.Collections * Aggregation over several parent configuration. It dispatches call to a first delegate that supports it. */ class AggregatedCallMethods( - private val delegates: Collection + private val delegates: Collection, ) : CallMethods { private val allMethods: Set diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt index 359dcff6c..c352ba075 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/DefaultBitcoinMethods.kt @@ -29,31 +29,37 @@ class DefaultBitcoinMethods : CallMethods { private val networkinfo = Global.objectMapper.writeValueAsBytes( mapOf( "version" to 210100, - "subversion" to "/EmeraldDshackle:${Global.version}/" - ) + "subversion" to "/EmeraldDshackle:${Global.version}/", + ), ) private val freshMethods = listOf( "getblock", - "gettransaction", "gettxout", - "getmemorypool" + "gettransaction", + "gettxout", + "getmemorypool", ).sorted() private val anyResponseMethods = listOf( - "getblockhash", "getrawtransaction" + "getblockhash", + "getrawtransaction", ).sorted() private val headVerifiedMethods = listOf( - "getbestblockhash", "getblocknumber", "getblockcount", - "listunspent", "getreceivedbyaddress" + "getbestblockhash", + "getblocknumber", + "getblockcount", + "listunspent", + "getreceivedbyaddress", ).sorted() private val hardcodedMethods = listOf( - "getconnectioncount", "getnetworkinfo" + "getconnectioncount", + "getnetworkinfo", ).sorted() private val broadcastMethods = listOf( - "sendrawtransaction" + "sendrawtransaction", ).sorted() private val allowedMethods = diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt index 130d406e9..b1eae08e5 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/EthereumCallSelector.kt @@ -31,7 +31,7 @@ import java.util.Objects * The implementation is specific for Ethereum. */ class EthereumCallSelector( - private val caches: Caches + private val caches: Caches, ) { companion object { @@ -46,18 +46,19 @@ class EthereumCallSelector( // no "eth_getStorageAt" because it has different structure, and therefore separate logic "eth_call", "eth_getRootHash", - "bor_getRootHash" + "bor_getRootHash", ) private val FILTER_OBJECT_METHODS = setOf( - "eth_newFilter", "eth_getLogs" + "eth_newFilter", + "eth_getLogs", ) private val GET_BY_HASH_OR_NUMBER_METHODS = setOf( "eth_getBlockByHash", "eth_getBlockByNumber", "bor_getSignersAtHash", "eth_getTransactionByBlockHashAndIndex", "eth_getTransactionByBlockNumberAndIndex", "eth_getBlockTransactionCountByNumber", "bor_getAuthor", "eth_getUncleCountByBlockNumber", - "eth_getUncleByBlockNumberAndIndex" + "eth_getUncleByBlockNumberAndIndex", ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethods.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethods.kt index b1299420f..a5fea9fa8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethods.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/calls/ManagedCallMethods.kt @@ -36,7 +36,7 @@ class ManagedCallMethods( private val enabled: Set, disabled: Set, groupsEnabled: Set, - groupsDisabled: Set + groupsDisabled: Set, ) : CallMethods { companion object { @@ -50,7 +50,7 @@ class ManagedCallMethods( private val allGroupEnabled = groupsEnabled.flatMap { delegate.getGroupMethods(it) } private val allGroupDisabled = groupsDisabled.flatMap { delegate.getGroupMethods(it) } private val allAllowed: Set = Collections.unmodifiableSet( - delegated.keys + allGroupEnabled - allGroupDisabled.toSet() + enabled - disabled + delegated.keys + allGroupEnabled - allGroupDisabled.toSet() + enabled - disabled, ) private val quorum: MutableMap> = HashMap() private val staticResponse: MutableMap = HashMap() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EnrichedMergedHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EnrichedMergedHead.kt index 43552c245..1cfb1cfb9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EnrichedMergedHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EnrichedMergedHead.kt @@ -18,7 +18,7 @@ class EnrichedMergedHead constructor( private val sources: Iterable, private val referenceHead: Head, private val headScheduler: Scheduler, - private val api: Reader + private val api: Reader, ) : Head, Lifecycle { private val enrichedBlocks = CacheBuilder.newBuilder() @@ -51,7 +51,7 @@ class EnrichedMergedHead constructor( .delayElement(Duration.ofSeconds(1)) .flatMap { EthereumBlockEnricher.enrich(BlockHash(block.hash.value), api, headScheduler) - } + }, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumArchiveBlockNumberReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumArchiveBlockNumberReader.kt index 97a50d444..ff446495c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumArchiveBlockNumberReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumArchiveBlockNumberReader.kt @@ -7,7 +7,7 @@ import io.emeraldpay.etherjar.hex.HexQuantity import reactor.core.publisher.Mono class EthereumArchiveBlockNumberReader( - private val reader: JsonRpcReader + private val reader: JsonRpcReader, ) { fun readArchiveBlock(): Mono = @@ -16,7 +16,7 @@ class EthereumArchiveBlockNumberReader( .map { HexQuantity .from( - String(it).substring(3, it.size - 1).toLong(radix = 16) - 10_000 // this is definitely archive + String(it).substring(3, it.size - 1).toLong(radix = 16) - 10_000, // this is definitely archive ).toHex() } } 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 42cd66de9..e77151255 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumBlockValidator.kt @@ -38,7 +38,7 @@ class EthereumBlockValidator : BlockValidator { "extraData", "mixHash", "nonce", - "baseFeePerGas" + "baseFeePerGas", ) private val log = LoggerFactory.getLogger(EthereumBlockValidator::class.java) @@ -67,9 +67,13 @@ class EthereumBlockValidator : BlockValidator { it to text } }.associate { - it.first to if (NUMBER_ELEMENTS.contains(it.first)) encodeBigInt(fromHexStringI(it.second)) else encode( - fromHexString(it.second) - ) + it.first to if (NUMBER_ELEMENTS.contains(it.first)) { + encodeBigInt(fromHexStringI(it.second)) + } else { + encode( + fromHexString(it.second), + ) + } } private fun validateHash(blockHash: BlockId, rlpEncoded: Map): Boolean { @@ -90,7 +94,7 @@ class EthereumBlockValidator : BlockValidator { val encoded = encodeList( ELEMENTS.filterNot { it in listOf("nonce", "mixHash") } .mapNotNull { rlpEncoded[it] } - .toList() + .toList(), ) val headerHash = sha3(encoded) val seed = Keccak.Digest512().digest(headerHash.plus(nonce.asUint64())) @@ -107,7 +111,7 @@ class EthereumBlockValidator : BlockValidator { "Block number {} not valid for {}. Must be greater than {}", it.number, it.hash, - cur.number + cur.number, ) } @@ -117,7 +121,7 @@ class EthereumBlockValidator : BlockValidator { "Block timestamp {} not valid for {}. Must be greater than {}", it.timestamp, it.hash, - cur.timestamp + cur.timestamp, ) } @@ -127,7 +131,7 @@ class EthereumBlockValidator : BlockValidator { curNumber = cur.number, blockTotalDifficulty = it.totalDifficulty, blockNumber = it.number, - blockHash = it.hash.toHex() + blockHash = it.hash.toHex(), ) } ?: false } ?: true @@ -138,14 +142,14 @@ class EthereumBlockValidator : BlockValidator { curNumber: Long, blockTotalDifficulty: BigInteger, blockNumber: Long, - blockHash: String + blockHash: String, ): Boolean { if (blockTotalDifficulty < curTotalDifficulty) { log.warn( "Block totalDifficulty {} not valid for {}. Must be greater than {}", blockTotalDifficulty, blockHash, - curTotalDifficulty + curTotalDifficulty, ) return false } @@ -165,7 +169,7 @@ class EthereumBlockValidator : BlockValidator { blockTotalDifficulty, blockHash, min.toBigInteger(), - max.toBigInteger() + max.toBigInteger(), ) } return valid diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt index 18e9a37cf..66f8d0732 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumCachingReader.kt @@ -56,7 +56,7 @@ open class EthereumCachingReader( private val up: Multistream, private val caches: Caches, callMethodsFactory: Factory, - private val tracer: Tracer + private val tracer: Tracer, ) : Lifecycle { private val objectMapper: ObjectMapper = Global.objectMapper @@ -88,20 +88,20 @@ open class EthereumCachingReader( private val blocksByIdAsCont = CompoundReader( SpannedReader(CacheWithUpstreamIdReader(caches.getBlocksByHash()), tracer, CACHE_BLOCK_BY_HASH_READER), - SpannedReader(RekeyingReader(idToBlockHash, directReader.blockReader), tracer, DIRECT_QUORUM_RPC_READER) + SpannedReader(RekeyingReader(idToBlockHash, directReader.blockReader), tracer, DIRECT_QUORUM_RPC_READER), ) fun blocksByHashAsCont(): Reader> { return CompoundReader( SpannedReader(CacheWithUpstreamIdReader(RekeyingReader(blockHashToId, caches.getBlocksByHash())), tracer, CACHE_BLOCK_BY_HASH_READER), - SpannedReader(directReader.blockReader, tracer, DIRECT_QUORUM_RPC_READER) + SpannedReader(directReader.blockReader, tracer, DIRECT_QUORUM_RPC_READER), ) } fun blocksByHashParsed(): Reader> { return TransformingReader( blocksByHashAsCont(), - extractBlock + extractBlock, ) } @@ -112,14 +112,14 @@ open class EthereumCachingReader( open fun blocksByHeightAsCont(): Reader> { return CompoundReader( SpannedReader(CacheWithUpstreamIdReader(caches.getBlocksByHeight()), tracer, CACHE_BLOCK_BY_HEIGHT_READER), - SpannedReader(directReader.blockByHeightReader, tracer, DIRECT_QUORUM_RPC_READER) + SpannedReader(directReader.blockByHeightReader, tracer, DIRECT_QUORUM_RPC_READER), ) } open fun blocksByHeightParsed(): Reader> { return TransformingReader( blocksByHeightAsCont(), - extractBlock + extractBlock, ) } @@ -127,34 +127,35 @@ open class EthereumCachingReader( return TransformingReader( CompoundReader( CacheWithUpstreamIdReader(RekeyingReader(txHashToId, caches.getTxByHash())), - directReader.txReader + directReader.txReader, ), - extractTx + extractTx, ) } open fun txByHashAsCont(): Reader> { return CompoundReader( CacheWithUpstreamIdReader(SpannedReader(caches.getTxByHash(), tracer, CACHE_TX_BY_HASH_READER)), - SpannedReader(RekeyingReader(idToTxHash, directReader.txReader), tracer, DIRECT_QUORUM_RPC_READER) + SpannedReader(RekeyingReader(idToTxHash, directReader.txReader), tracer, DIRECT_QUORUM_RPC_READER), ) } fun balance(): Reader> { // TODO include height as part of cache? return CompoundReader( - CacheWithUpstreamIdReader(balanceCache), directReader.balanceReader + CacheWithUpstreamIdReader(balanceCache), + directReader.balanceReader, ) } fun receipts(): Reader> { val requested = RekeyingReader( { txid: TxId -> TransactionId.from(txid.value) }, - directReader.receiptReader + directReader.receiptReader, ) return CompoundReader( CacheWithUpstreamIdReader(SpannedReader(caches.getReceipts(), tracer, CACHE_RECEIPTS_READER)), - SpannedReader(requested, tracer, DIRECT_QUORUM_RPC_READER) + SpannedReader(requested, tracer, DIRECT_QUORUM_RPC_READER), ) } @@ -174,7 +175,7 @@ open class EthereumCachingReader( } private class CacheWithUpstreamIdReader( - private val reader: Reader + private val reader: Reader, ) : Reader> { override fun read(key: K): Mono> { return reader.read(key) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt index 9ccaeca9e..b7af956ea 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumDirectReader.kt @@ -44,7 +44,7 @@ class EthereumDirectReader( private val caches: Caches, private val balanceCache: CurrentBlockCache, private val callMethodsFactory: Factory, - private val tracer: Tracer + private val tracer: Tracer, ) { companion object { @@ -85,7 +85,7 @@ class EthereumDirectReader( Mono.empty() } else { Mono.just( - Result(TxContainer.from(tx, result.data), result.upstreamId) + Result(TxContainer.from(tx, result.data), result.upstreamId), ) } } @@ -108,7 +108,7 @@ class EthereumDirectReader( if (str.startsWith("\"") && str.endsWith("\"")) { Result( Wei.from(str.substring(1, str.length - 1)), - it.upstreamId + it.upstreamId, ) } else { throw RpcException(RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, "Not Wei value") @@ -138,11 +138,11 @@ class EthereumDirectReader( blockId = BlockId.from(receipt.blockHash), height = receipt.blockNumber, json = result.data, - parsed = receipt - ) + parsed = receipt, + ), ) Mono.just( - result + result, ) } } @@ -154,7 +154,7 @@ class EthereumDirectReader( private fun readBlock( request: JsonRpcRequest, id: String, - matcher: Selector.Matcher = Selector.empty + matcher: Selector.Matcher = Selector.empty, ): Mono> { return readWithQuorum(request, matcher) .timeout(Defaults.timeoutInternal, Mono.error(TimeoutException("Block not read $id"))) @@ -170,8 +170,8 @@ class EthereumDirectReader( Mono.just( Result( BlockContainer.from(block, result.data, "unknown"), - result.upstreamId - ) + result.upstreamId, + ), ) } } @@ -185,7 +185,7 @@ class EthereumDirectReader( */ private fun readWithQuorum( request: JsonRpcRequest, - matcher: Selector.Matcher = Selector.empty + matcher: Selector.Matcher = Selector.empty, ): Mono> { return Mono.just(rpcReaderFactory) .map { @@ -195,9 +195,13 @@ class EthereumDirectReader( .build() it.create( RpcReaderFactory.RpcReaderData( - up, request.method, requestMatcher, - callMethodsFactory.create().createQuorumFor(request.method), null, tracer - ) + up, + request.method, + requestMatcher, + callMethodsFactory.create().createQuorumFor(request.method), + null, + tracer, + ), ) }.flatMap { it.read(request) @@ -208,6 +212,6 @@ class EthereumDirectReader( data class Result( val data: T, - val upstreamId: String? + val upstreamId: String?, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt index 11bbcbd3c..1dddce471 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumEgressSubscription.kt @@ -15,7 +15,7 @@ import reactor.core.scheduler.Scheduler open class EthereumEgressSubscription( val upstream: EthereumLikeMultistream, val scheduler: Scheduler, - val pendingTxesSource: PendingTxesSource? + val pendingTxesSource: PendingTxesSource?, ) : EgressSubscription { companion object { @@ -66,7 +66,7 @@ open class EthereumEgressSubscription( data class LogsRequest( val address: List
, - val topics: List + val topics: List, ) fun readLogsRequest(params: Map): LogsRequest { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt index 8c815b125..1c01e0b01 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumFees.kt @@ -62,7 +62,7 @@ abstract class EthereumFees( a.max.coerceAtLeast(b.max), a.priority.coerceAtLeast(b.priority), a.paid.coerceAtLeast(b.paid), - Wei.ZERO + Wei.ZERO, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumHeadLagObserver.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumHeadLagObserver.kt index 61e7eb2fd..f3ffde527 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumHeadLagObserver.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumHeadLagObserver.kt @@ -27,7 +27,7 @@ import reactor.core.scheduler.Scheduler class EthereumHeadLagObserver( master: Head, followers: Collection, - headScheduler: Scheduler + headScheduler: Scheduler, ) : HeadLagObserver(master, followers, DistanceExtractor::extractPowDistance, headScheduler) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt index c5861913b..ab7780503 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLegacyFees.kt @@ -34,7 +34,7 @@ class EthereumLegacyFees(upstreams: EthereumMultistream, reader: EthereumCaching BlockchainOuterClass.EstimateFeeResponse.newBuilder() .setEthereumStd( BlockchainOuterClass.EthereumStdFees.newBuilder() - .setFee(it.paid.amount.toString()) + .setFee(it.paid.amount.toString()), ) .build() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLikeRpcUpstream.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLikeRpcUpstream.kt index 25ed837e3..c6aefc7a2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLikeRpcUpstream.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLikeRpcUpstream.kt @@ -95,7 +95,7 @@ open class EthereumLikeRpcUpstream( eventPublisher?.publishEvent(UpstreamChangeEvent(chain, this, UpstreamChangeEvent.ChangeType.UPDATED)) }, { log.debug("Error while checking live subscription for ${getId()}", it) - }) + },) labelsDetector.detectLabels() .toStream() .forEach { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReader.kt index 27f76ec21..03b51881a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumLocalReader.kt @@ -41,7 +41,7 @@ class EthereumLocalReader( private val reader: EthereumCachingReader, private val methods: CallMethods, private val head: Head, - private val localEnabled: Boolean + private val localEnabled: Boolean, ) : JsonRpcReader { override fun read(key: JsonRpcRequest): Mono { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt index a2b2af8f9..d5488be73 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumPriorityFees.kt @@ -38,7 +38,7 @@ class EthereumPriorityFees(upstreams: Multistream, reader: EthereumCachingReader BlockchainOuterClass.EthereumExtFees.newBuilder() .setMax(it.max.amount.toString()) .setPriority(it.priority.amount.toString()) - .setExpect(it.paid.amount.toString()) + .setExpect(it.paid.amount.toString()), ) .build() } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsConnectionPoolFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsConnectionPoolFactory.kt index 8ea17b1b2..840987e2f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsConnectionPoolFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsConnectionPoolFactory.kt @@ -21,7 +21,7 @@ import io.emeraldpay.dshackle.upstream.DefaultUpstream class EthereumWsConnectionPoolFactory( private val id: String, private val connections: Int, - private val ethereumWsConnectionFactory: EthereumWsConnectionFactory + private val ethereumWsConnectionFactory: EthereumWsConnectionFactory, ) { fun create(upstream: DefaultUpstream): WsConnectionPool { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt index 04531b194..2e2be1c3b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumWsHead.kt @@ -47,7 +47,7 @@ class EthereumWsHead( private val skipEnhance: Boolean, private val wsConnectionResubscribeScheduler: Scheduler, private val headScheduler: Scheduler, - private val upstream: DefaultUpstream + private val upstream: DefaultUpstream, ) : DefaultEthereumHead(upstream.getId(), forkChoice, blockValidator, headScheduler), Lifecycle { private var connectionId: String? = null @@ -73,7 +73,7 @@ class EthereumWsHead( val heads = Flux.merge( // get the current block, not just wait for the next update getLatestBlock(api), - listenNewHeads() + listenNewHeads(), ) this.subscription = super.follow(heads) } @@ -134,7 +134,7 @@ class EthereumWsHead( } } }, - headScheduler + headScheduler, ) } else { Mono.just(BlockContainer.from(block)) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt index 34c5eca59..51a17e58b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/HeadLivenessValidator.kt @@ -10,7 +10,7 @@ class HeadLivenessValidator( private val head: Head, private val expectedBlockTime: Duration, private val scheduler: Scheduler, - private val upstreamId: String + private val upstreamId: String, ) { companion object { const val CHECKED_BLOCKS_UNTIL_LIVE = 3 @@ -41,7 +41,7 @@ class HeadLivenessValidator( expectedBlockTime.multipliedBy(CHECKED_BLOCKS_UNTIL_LIVE.toLong() * 2), Flux.just(false).doOnNext { log.debug("head liveness check broken with timeout in $upstreamId") - } + }, ).repeat().subscribeOn(scheduler) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/RLP.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/RLP.kt index 05c76c3f2..01c77e30d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/RLP.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/RLP.kt @@ -64,7 +64,7 @@ class RLP { val totalLength = elements.sumOf { it.size } if (totalLength < SIZE_THRESHOLD) { return byteArrayOf((OFFSET_SHORT_LIST + totalLength).toByte()).plus( - elements.reduce { a, b -> a.plus(b) } + elements.reduce { a, b -> a.plus(b) }, ) } @@ -89,7 +89,7 @@ class RLP { (value shr 24 and 0xff).toByte(), (value shr 16 and 0xff).toByte(), (value shr 8 and 0xff).toByte(), - (value and 0xff).toByte() + (value and 0xff).toByte(), ) } } 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 1c8e81a47..abdf00295 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnection.kt @@ -33,7 +33,7 @@ interface WsConnection : AutoCloseable { data class ConnectionInfo( val connectionId: String, - val connectionState: ConnectionState + val connectionState: ConnectionState, ) enum class ConnectionState { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt index 05ef39d23..2f63a9193 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionImpl.kt @@ -68,7 +68,7 @@ open class WsConnectionImpl( private val basicAuth: AuthConfig.ClientBasicAuth?, private val rpcMetrics: RpcMetrics?, private val onDisconnect: () -> Unit, - private val scheduler: Scheduler + private val scheduler: Scheduler, ) : AutoCloseable, WsConnection, Cloneable { companion object { @@ -176,7 +176,7 @@ open class WsConnectionImpl( val retryInterval = currentBackOff.nextBackOff() resetBackoffTask = resetBackoffExecutor.schedule({ currentBackOff = reconnectBackoff.start() - }, RESET_BACKOFF_TIMEOUT + retryInterval, TimeUnit.MILLISECONDS) + }, RESET_BACKOFF_TIMEOUT + retryInterval, TimeUnit.MILLISECONDS,) if (retryInterval == BackOffExecution.STOP) { log.warn("Reconnect backoff exhausted. Permanently closing the connection") return @@ -188,7 +188,7 @@ open class WsConnectionImpl( connectInternal() }, retryInterval, - TimeUnit.MILLISECONDS + TimeUnit.MILLISECONDS, ) } @@ -220,7 +220,7 @@ open class WsConnectionImpl( }, { _, t -> log.warn("Failed to process response from $uri. Error: ${t.message}") - } + }, ) .headers { headers -> headers.add(HttpHeaderNames.ORIGIN, origin) @@ -238,7 +238,7 @@ open class WsConnectionImpl( .handlePing(true) .compress(false) .maxFramePayloadLength(frameSize) - .build() + .build(), ) .uri(uri) .handle { inbound, outbound -> @@ -294,8 +294,8 @@ open class WsConnectionImpl( return outbound.send( Flux.merge( calls.subscribeOn(scheduler), - consumer.then(Mono.empty()).subscribeOn(scheduler) - ) + consumer.then(Mono.empty()).subscribeOn(scheduler), + ), ) } @@ -310,7 +310,10 @@ open class WsConnectionImpl( private fun onMessageRpc(msg: ResponseWSParser.WsResponse) { val rpcResponse = JsonRpcResponse( - msg.value, msg.error, msg.id, null + msg.value, + msg.error, + msg.id, + null, ) val sender = currentRequests.remove(msg.id.asNumber().toInt()) if (sender == null) { @@ -329,7 +332,9 @@ open class WsConnectionImpl( private fun onMessageSubscription(msg: ResponseWSParser.WsResponse) { val subscription = JsonRpcWsMessage( - msg.value, msg.error, msg.id.asString(), + msg.value, + msg.error, + msg.id.asString(), ) val status = subscriptionResponses.tryEmitNext(subscription) if (status.isFailure) { @@ -375,10 +380,10 @@ open class WsConnectionImpl( JsonRpcResponse.Id.from(originalId), JsonRpcError( RpcResponseError.CODE_INTERNAL_ERROR, - "Response not received from WebSocket" + "Response not received from WebSocket", ), null, - false + false, ) val failOnDisconnect = Mono.from(disconnects.asFlux()) @@ -388,9 +393,9 @@ open class WsConnectionImpl( JsonRpcResponse.Id.from(originalId), JsonRpcError( RpcResponseError.CODE_UPSTREAM_CONNECTION_ERROR, - "Disconnected from WebSocket" - ) - ) + "Disconnected from WebSocket", + ), + ), ) } @@ -401,7 +406,7 @@ open class WsConnectionImpl( .doOnError { rpcMetrics?.fails?.increment() } .map { it.copyWithId(JsonRpcResponse.Id.from(originalId)) } .switchIfEmpty( - Mono.fromCallable { log.warn("No response for ${request.method} ${request.params}") }.then(Mono.error(noResponse)) + Mono.fromCallable { log.warn("No response for ${request.method} ${request.params}") }.then(Mono.error(noResponse)), ) .doFinally { currentRequests.remove(internalId.toInt()) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionMultiPool.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionMultiPool.kt index a15e3dc60..8758e0da8 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionMultiPool.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsConnectionMultiPool.kt @@ -119,7 +119,7 @@ class WsConnectionMultiPool( connectionSubscriptionMap[it.connectionId()] = it.connectionInfoFlux().subscribe { info -> connectionInfo.emitNext(info) { _, res -> res == Sinks.EmitResult.FAIL_NON_SERIALIZED } } - } + }, ) SCHEDULE_GROW } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsSubscriptions.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsSubscriptions.kt index bf76dd252..229855f17 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsSubscriptions.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/WsSubscriptions.kt @@ -43,6 +43,6 @@ interface WsSubscriptions { data class SubscribeData( val data: Flux, - val connectionId: String + val connectionId: String, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt index 15ccbd525..6a7451625 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/ConnectorFactory.kt @@ -9,7 +9,7 @@ interface ConnectorFactory { upstream: DefaultUpstream, validator: EthereumUpstreamValidator, chain: Chain, - skipEnhance: Boolean + skipEnhance: Boolean, ): EthereumConnector fun isValid(): Boolean diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt index 88ead79bd..da833f876 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumConnectorFactory.kt @@ -22,7 +22,7 @@ open class EthereumConnectorFactory( private val blockValidator: BlockValidator, private val wsConnectionResubscribeScheduler: Scheduler, private val headScheduler: Scheduler, - private val expectedBlockTime: Duration + private val expectedBlockTime: Duration, ) : ConnectorFactory { override fun isValid(): Boolean { @@ -49,7 +49,7 @@ open class EthereumConnectorFactory( upstream: DefaultUpstream, validator: EthereumUpstreamValidator, chain: Chain, - skipEnhance: Boolean + skipEnhance: Boolean, ): EthereumConnector { if (wsFactory != null && connectorType == WS_ONLY) { return EthereumWsConnector( @@ -60,7 +60,7 @@ open class EthereumConnectorFactory( skipEnhance, wsConnectionResubscribeScheduler, headScheduler, - expectedBlockTime + expectedBlockTime, ) } if (httpFactory == null) { @@ -76,7 +76,7 @@ open class EthereumConnectorFactory( skipEnhance, wsConnectionResubscribeScheduler, headScheduler, - expectedBlockTime + expectedBlockTime, ) } @@ -84,7 +84,8 @@ open class EthereumConnectorFactory( WS_ONLY, RPC_ONLY, RPC_REQUESTS_WITH_MIXED_HEAD, - RPC_REQUESTS_WITH_WS_HEAD; + RPC_REQUESTS_WITH_WS_HEAD, + ; companion object { val values = values().map { it.name }.toSet() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt index 284bbe932..73233c566 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumRpcConnector.kt @@ -38,7 +38,7 @@ class EthereumRpcConnector( skipEnhance: Boolean, wsConnectionResubscribeScheduler: Scheduler, headScheduler: Scheduler, - expectedBlockTime: Duration + expectedBlockTime: Duration, ) : EthereumConnector, CachesEnabled { private val id = upstream.getId() private val pool: WsConnectionPool? @@ -76,7 +76,7 @@ class EthereumRpcConnector( skipEnhance, wsConnectionResubscribeScheduler, headScheduler, - upstream + upstream, ) // receive all new blocks through WebSockets, but also periodically verify with RPC in case if WS failed val rpcHead = @@ -86,7 +86,7 @@ class EthereumRpcConnector( id, blockValidator, headScheduler, - Duration.ofSeconds(30) + Duration.ofSeconds(30), ) MergedHead(listOf(rpcHead, wsHead), forkChoice, headScheduler, "Merged for $id") } @@ -94,10 +94,13 @@ class EthereumRpcConnector( RPC_REQUESTS_WITH_WS_HEAD -> { EthereumWsHead( AlwaysForkChoice(), - blockValidator, getIngressReader(), - WsSubscriptionsImpl(pool!!), skipEnhance, wsConnectionResubscribeScheduler, + blockValidator, + getIngressReader(), + WsSubscriptionsImpl(pool!!), + skipEnhance, + wsConnectionResubscribeScheduler, headScheduler, - upstream + upstream, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt index d5f1870e3..833d8b9ca 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/connectors/EthereumWsConnector.kt @@ -25,7 +25,7 @@ class EthereumWsConnector( skipEnhance: Boolean, wsConnectionResubscribeScheduler: Scheduler, headScheduler: Scheduler, - expectedBlockTime: Duration + expectedBlockTime: Duration, ) : EthereumConnector { private val pool: WsConnectionPool private val reader: JsonRpcReader @@ -44,7 +44,7 @@ class EthereumWsConnector( skipEnhance, wsConnectionResubscribeScheduler, headScheduler, - upstream + upstream, ) liveness = HeadLivenessValidator(head, expectedBlockTime, headScheduler, upstream.getId()) subscriptions = EthereumWsIngressSubscription(wsSubscriptions) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt index 201750333..6d271af8d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/AggregatedPendingTxes.kt @@ -23,7 +23,7 @@ import reactor.core.publisher.Flux import java.time.Duration class AggregatedPendingTxes( - private val sources: List + private val sources: List, ) : PendingTxesSource { companion object { @@ -37,7 +37,7 @@ class AggregatedPendingTxes( override fun connect(matcher: Selector.Matcher): Flux { return Flux.merge( - sources.map { it.connect(matcher) } + sources.map { it.connect(matcher) }, ).filter { val res = track.getIfPresent(it) if (res == null) { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdates.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdates.kt index 798bd8c00..39f1fda2d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdates.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectBlockUpdates.kt @@ -33,7 +33,7 @@ import kotlin.concurrent.write class ConnectBlockUpdates( private val upstream: EthereumLikeMultistream, - private val scheduler: Scheduler + private val scheduler: Scheduler, ) : SubscriptionConnect { companion object { @@ -110,7 +110,7 @@ class ConnectBlockUpdates( prev.height, UpdateType.DROP, it, - source + source, ) } } @@ -123,7 +123,7 @@ class ConnectBlockUpdates( block.height, UpdateType.NEW, it, - block.upstreamId + block.upstreamId, ) } } @@ -133,11 +133,11 @@ class ConnectBlockUpdates( val blockNumber: Long, val type: UpdateType, val transactionId: TxId, - val upstreamId: String + val upstreamId: String, ) enum class UpdateType { NEW, - DROP + DROP, } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt index 044d9d3d6..46869e69a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectLogs.kt @@ -68,7 +68,7 @@ open class ConnectLogs( val goodTopic = sortedTopics.isEmpty() || ( it.topics.isNotEmpty() && sortedTopics.binarySearch( it.topics[0], - TOPIC_COMPARATOR + TOPIC_COMPARATOR, ) >= 0 ) goodAddress && goodTopic diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectNewHeads.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectNewHeads.kt index 4bd747de8..f1a5b3d0e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectNewHeads.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ConnectNewHeads.kt @@ -29,7 +29,7 @@ import java.util.concurrent.ConcurrentHashMap */ class ConnectNewHeads( private val upstream: EthereumLikeMultistream, - private val scheduler: Scheduler + private val scheduler: Scheduler, ) : SubscriptionConnect { private val connected: MutableMap> = ConcurrentHashMap() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/DefaultPendingTxesSource.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/DefaultPendingTxesSource.kt index 8c4965073..c3773ec79 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/DefaultPendingTxesSource.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/DefaultPendingTxesSource.kt @@ -31,7 +31,7 @@ abstract class DefaultPendingTxesSource : SubscriptionConnect, Pe .backoffOnError(Duration.ofMillis(100), 1.5, Duration.ofSeconds(60)) .build() private val holder = SharedFluxHolder( - connectionSource::connect + connectionSource::connect, ) override fun connect(matcher: Selector.Matcher): Flux { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumLabelsDetector.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumLabelsDetector.kt index 1f20f63df..8155dba1f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumLabelsDetector.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumLabelsDetector.kt @@ -11,13 +11,13 @@ import reactor.core.publisher.Flux import reactor.core.publisher.Mono class EthereumLabelsDetector( - private val reader: JsonRpcReader + private val reader: JsonRpcReader, ) { fun detectLabels(): Flux> { return Flux.merge( detectNodeType(), - detectArchiveNode() + detectArchiveNode(), ) } @@ -45,8 +45,8 @@ class EthereumLabelsDetector( reader.read( JsonRpcRequest( "eth_getBalance", - listOf("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0", it) - ) + listOf("0x756F45E3FA69347A9A973A725E3C98bC4db0b5a0", it), + ), ) } .flatMap(JsonRpcResponse::requireResult) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumWsIngressSubscription.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumWsIngressSubscription.kt index 03fc0b45b..29400c287 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumWsIngressSubscription.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/EthereumWsIngressSubscription.kt @@ -22,7 +22,7 @@ import io.emeraldpay.dshackle.upstream.ethereum.EthereumIngressSubscription import io.emeraldpay.dshackle.upstream.ethereum.WsSubscriptions class EthereumWsIngressSubscription( - conn: WsSubscriptions + conn: WsSubscriptions, ) : IngressSubscription, EthereumIngressSubscription { private val pendingTxes = WebsocketPendingTxes(conn) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceLogs.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceLogs.kt index 556c89e47..44b6477ec 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceLogs.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceLogs.kt @@ -35,7 +35,7 @@ import java.util.concurrent.TimeUnit class ProduceLogs( private val receipts: Reader>, - private val chain: Chain + private val chain: Chain, ) { companion object { @@ -71,7 +71,7 @@ class ProduceLogs( if (old == null) { log.warn( "No old message to produce removal messages for tx ${update.transactionId} " + - "at block ${update.blockHash} for chain ${chain.chainName}" + "at block ${update.blockHash} for chain ${chain.chainName}", ) return Flux.empty() } @@ -104,7 +104,7 @@ class ProduceLogs( txlog.transactionHash, txlog.transactionIndex, false, - update.upstreamId + update.upstreamId, ) } @@ -113,7 +113,7 @@ class ProduceLogs( } catch (t: Throwable) { log.warn( "Invalid Receipt ${update.transactionId} for chain ${chain.chainName}. " + - "${t.javaClass}: ${t.message}" + "${t.javaClass}: ${t.message}", ) Flux.empty() } @@ -122,6 +122,6 @@ class ProduceLogs( private data class LogReference( val block: BlockId, - val tx: TxId + val tx: TxId, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt index b48e59d9e..baf84d8ea 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/ProduceNewHeads.kt @@ -26,7 +26,7 @@ import reactor.core.publisher.Flux * @see NewHeadMessage */ class ProduceNewHeads( - val head: Head + val head: Head, ) { fun start(): Flux { @@ -52,7 +52,7 @@ class ProduceNewHeads( block.stateRoot, block.transactionsRoot, block.withdrawalsRoot, - it.upstreamId + it.upstreamId, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/WebsocketPendingTxes.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/WebsocketPendingTxes.kt index ea6059221..e23fc96d2 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/WebsocketPendingTxes.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/WebsocketPendingTxes.kt @@ -25,7 +25,7 @@ import reactor.core.publisher.Mono import java.time.Duration class WebsocketPendingTxes( - private val wsSubscriptions: WsSubscriptions + private val wsSubscriptions: WsSubscriptions, ) : DefaultPendingTxesSource(), SubscriptionConnect { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/LogMessage.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/LogMessage.kt index 88c77530b..66578ce4a 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/LogMessage.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/subscribe/json/LogMessage.kt @@ -43,5 +43,5 @@ data class LogMessage( val transactionIndex: Long, val removed: Boolean, @get:JsonIgnore - override val upstreamId: String + override val upstreamId: String, ) : HasUpstream diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosHeadLagObserver.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosHeadLagObserver.kt index ff806f199..2b08a83ee 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosHeadLagObserver.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum_pos/EthereumPosHeadLagObserver.kt @@ -11,7 +11,7 @@ import reactor.core.scheduler.Scheduler class EthereumPosHeadLagObserver( master: Head, followers: Collection, - headScheduler: Scheduler + headScheduler: Scheduler, ) : HeadLagObserver(master, followers, DistanceExtractor::extractPriorityDistance, headScheduler) { companion object { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/forkchoice/NoChoiceWithPriorityForkChoice.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/forkchoice/NoChoiceWithPriorityForkChoice.kt index 96b9b1eb0..262cc3e24 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/forkchoice/NoChoiceWithPriorityForkChoice.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/forkchoice/NoChoiceWithPriorityForkChoice.kt @@ -8,7 +8,7 @@ import java.util.concurrent.atomic.AtomicReference class NoChoiceWithPriorityForkChoice( private val nodeRating: Int, - private val upstreamId: String + private val upstreamId: String, ) : ForkChoice { private val head = AtomicReference(null) private val seenBlocks = CacheBuilder.newBuilder() diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt index d7bc61f73..4fac00588 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt @@ -76,7 +76,7 @@ class GrpcHead( Mono.just(client), Mono.just(client) .repeat() - .delayElements(Duration.ofSeconds(1)) + .delayElements(Duration.ofSeconds(1)), ) .concatMap({ it.subscribeHead(chainRef) }, 0) .doOnNext { @@ -103,7 +103,7 @@ class GrpcHead( Long.MAX_VALUE, Duration.ofMillis(100), Duration.ofSeconds(60), - true + true, ) { log.debug("Retry grpc head connection ${parent.getId()}") } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/ClientAuthenticationInterceptor.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/ClientAuthenticationInterceptor.kt index 270095ca3..164fbccd9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/ClientAuthenticationInterceptor.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/ClientAuthenticationInterceptor.kt @@ -11,7 +11,7 @@ import io.grpc.MethodDescriptor class ClientAuthenticationInterceptor( private val upstreamId: String, - private val grpcAuthContext: GrpcAuthContext + private val grpcAuthContext: GrpcAuthContext, ) : ClientInterceptor { companion object { @@ -22,7 +22,7 @@ class ClientAuthenticationInterceptor( override fun interceptCall( method: MethodDescriptor, callOptions: CallOptions, - next: Channel + next: Channel, ): ClientCall = object : ForwardingClientCall.SimpleForwardingClientCall(next.newCall(method, callOptions)) { override fun start(responseListener: Listener, headers: Metadata) { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuth.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuth.kt index c7aca08be..5e862aaf7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuth.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuth.kt @@ -23,7 +23,7 @@ class GrpcUpstreamsAuth( private val authClient: ReactorAuthStub, private val authorizationConfig: AuthorizationConfig, private val grpcAuthContext: GrpcAuthContext, - publicKeyPath: String + publicKeyPath: String, ) { private val rsaKeyReader = RsaKeyReader() private val keys = rsaKeyReader.getKeyPair(authorizationConfig.clientConfig.privateKeyPath, publicKeyPath) @@ -32,7 +32,7 @@ class GrpcUpstreamsAuth( return authClient.authenticate( AuthOuterClass.AuthRequest.newBuilder() .setToken(generateToken()) - .build() + .build(), ).map { verify(it.providerToken, providerId) }.onErrorResume { @@ -66,6 +66,6 @@ class GrpcUpstreamsAuth( data class AuthResult( val passed: Boolean, - val cause: String? = null + val cause: String? = null, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcError.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcError.kt index 8d2743fde..4e4fa5bd7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcError.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcError.kt @@ -25,7 +25,9 @@ data class JsonRpcError(val code: Int, val message: String, val details: Any?) { @JvmStatic fun from(err: RpcException): JsonRpcError { return JsonRpcError( - err.code, err.rpcMessage, err.details + err.code, + err.rpcMessage, + err.details, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt index 13c6a7089..060a4249d 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcException.kt @@ -21,7 +21,7 @@ open class JsonRpcException( val id: JsonRpcResponse.Id, val error: JsonRpcError, val upstreamId: String? = null, - writableStackTrace: Boolean = true + writableStackTrace: Boolean = true, ) : Exception(error.message, null, true, writableStackTrace) { constructor(id: Int, message: String) : this(JsonRpcResponse.NumberId(id), JsonRpcError(-32005, message)) @@ -36,7 +36,8 @@ open class JsonRpcException( } } ?: JsonRpcResponse.NumberId(-4) return JsonRpcException( - id, JsonRpcError.from(err) + id, + JsonRpcError.from(err), ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt index 9d83a093d..5578ca394 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcGrpcClient.kt @@ -48,7 +48,7 @@ class JsonRpcGrpcClient( class Executor( private val stub: ReactorBlockchainGrpc.ReactorBlockchainStub, private val chain: Chain, - private val metrics: RpcMetrics? + private val metrics: RpcMetrics?, ) : JsonRpcReader { override fun read(key: JsonRpcRequest): Mono { @@ -97,8 +97,8 @@ class JsonRpcGrpcClient( RpcException( resp.errorCode, resp.errorMessage, - if (resp.errorData == null || resp.errorData.isEmpty()) null else resp.errorData - ) + if (resp.errorData == null || resp.errorData.isEmpty()) null else resp.errorData, + ), ) } @@ -108,15 +108,15 @@ class JsonRpcGrpcClient( is StatusRuntimeException -> Mono.error( RpcException( RpcResponseError.CODE_UPSTREAM_CONNECTION_ERROR, - "Remote status code: ${t.status.code.name}" - ) + "Remote status code: ${t.status.code.name}", + ), ) else -> Mono.error( RpcException( RpcResponseError.CODE_UPSTREAM_CONNECTION_ERROR, - "Other connection error" - ) + "Other connection error", + ), ) } } @@ -128,7 +128,7 @@ class JsonRpcGrpcClient( return ResponseSigner.Signature( resp.signature.toByteArray(), resp.upstreamId, - resp.keyId + resp.keyId, ) } } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt index 188fac9ef..40b5b8d8f 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcHttpClient.kt @@ -47,7 +47,7 @@ class JsonRpcHttpClient( private val target: String, private val metrics: RpcMetrics, basicAuth: AuthConfig.ClientBasicAuth? = null, - tlsCAAuth: ByteArray? = null + tlsCAAuth: ByteArray? = null, ) : JsonRpcReader { companion object { @@ -180,7 +180,7 @@ class JsonRpcHttpClient( JsonRpcResponse.error( RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, "HTTP Code: $statusCode", - JsonRpcResponse.NumberId(key.id) + JsonRpcResponse.NumberId(key.id), ) } } else { diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcRequest.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcRequest.kt index be5faf472..b9dde32f7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcRequest.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcRequest.kt @@ -27,14 +27,14 @@ data class JsonRpcRequest( val params: List, val id: Int, val nonce: Long?, - val selector: BlockchainOuterClass.Selector? + val selector: BlockchainOuterClass.Selector?, ) { @JvmOverloads constructor( method: String, params: List, nonce: Long? = null, - selectors: BlockchainOuterClass.Selector? = null + selectors: BlockchainOuterClass.Selector? = null, ) : this(method, params, 1, nonce, selectors) fun toJson(): ByteArray { @@ -42,7 +42,7 @@ data class JsonRpcRequest( "jsonrpc" to "2.0", "id" to id, "method" to method, - "params" to params + "params" to params, ) return Global.objectMapper.writeValueAsBytes(json) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcResponse.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcResponse.kt index 0c9ed08f5..92e57ae8b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcResponse.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcResponse.kt @@ -30,7 +30,7 @@ class JsonRpcResponse( * When making a request through Dshackle protocol a remote may provide its signature with the response, which we keep here */ val providedSignature: ResponseSigner.Signature? = null, - val providedUpstreamId: String? = null + val providedUpstreamId: String? = null, ) { constructor(result: ByteArray?, error: JsonRpcError?) : this(result, error, NumberId(0)) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcUpstreamException.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcUpstreamException.kt index 74ba3109a..2a7f6c535 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcUpstreamException.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcUpstreamException.kt @@ -2,5 +2,5 @@ package io.emeraldpay.dshackle.upstream.rpcclient class JsonRpcUpstreamException( id: JsonRpcResponse.Id, - error: JsonRpcError + error: JsonRpcError, ) : JsonRpcException(id, error, null, false) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcWsClient.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcWsClient.kt index 23948c531..5eba7fecb 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcWsClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/JsonRpcWsClient.kt @@ -21,7 +21,7 @@ import io.emeraldpay.etherjar.rpc.RpcResponseError import reactor.core.publisher.Mono class JsonRpcWsClient( - private val wsPool: WsConnectionPool + private val wsPool: WsConnectionPool, ) : JsonRpcReader { override fun read(key: JsonRpcRequest): Mono { @@ -32,9 +32,9 @@ class JsonRpcWsClient( JsonRpcResponse.NumberId(key.id), JsonRpcError( RpcResponseError.CODE_UPSTREAM_CONNECTION_ERROR, - "WebSocket is not connected" - ) - ) + "WebSocket is not connected", + ), + ), ) } return conn.callRpc(key) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt index f0c32ea86..489d47a39 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseParser.kt @@ -47,8 +47,8 @@ abstract class ResponseParser { return Preparsed( error = JsonRpcError( RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, - "Invalid JSON: not an Object" - ) + "Invalid JSON: not an Object", + ), ) } while (parser.nextToken() != JsonToken.END_OBJECT) { @@ -64,8 +64,8 @@ abstract class ResponseParser { return Preparsed( error = JsonRpcError( RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, - "Invalid JSON structure: never finalized" - ) + "Invalid JSON structure: never finalized", + ), ) } @@ -75,8 +75,8 @@ abstract class ResponseParser { return state.copy( error = JsonRpcError( RpcResponseError.CODE_UPSTREAM_INVALID_RESPONSE, - "Invalid JSON (jsonrpc value)" - ) + "Invalid JSON (jsonrpc value)", + ), ) } // just skip the field @@ -181,7 +181,7 @@ abstract class ResponseParser { val nullResult: Boolean = false, val error: JsonRpcError? = null, val subMethod: String? = null, - val subId: String? = null + val subId: String? = null, ) { private val isResultSet = result != null || nullResult diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseWSParser.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseWSParser.kt index 87c76746d..14a2062a9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseWSParser.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/ResponseWSParser.kt @@ -33,7 +33,7 @@ class ResponseWSParser : ResponseParser() { Type.RPC, state.id!!, if (state.nullResult) NULL_RESULT else state.result, - state.error + state.error, ) } if (state.isSubReady) { @@ -41,7 +41,7 @@ class ResponseWSParser : ResponseParser() { Type.SUBSCRIPTION, JsonRpcResponse.Id.from(state.subId!!), if (state.nullResult) NULL_RESULT else state.result, - state.error + state.error, ) } throw IllegalStateException("State is not ready") @@ -103,6 +103,6 @@ class ResponseWSParser : ResponseParser() { val type: Type, val id: JsonRpcResponse.Id, val value: ByteArray?, - val error: JsonRpcError? + val error: JsonRpcError?, ) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/RpcMetrics.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/RpcMetrics.kt index b9c8fda7a..4ef468319 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/RpcMetrics.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/rpcclient/RpcMetrics.kt @@ -20,5 +20,5 @@ import io.micrometer.core.instrument.Timer class RpcMetrics( val timer: Timer, - val fails: Counter + val fails: Counter, ) diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt index 12a2876ad..22690b532 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/signature/ResponseSignerFactory.kt @@ -22,7 +22,7 @@ import java.security.spec.PKCS8EncodedKeySpec @Repository open class ResponseSignerFactory( - @Autowired private val config: SignatureConfig + @Autowired private val config: SignatureConfig, ) : FactoryBean { companion object { diff --git a/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolverTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolverTest.kt index 72932b165..5ec130021 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolverTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorResolverTest.kt @@ -19,7 +19,7 @@ class AuthProcessorResolverTest { "joiVjEifQ.BZILN0GQ7JzXGFz-GZIbFTT9E5L-miB4Nga0v4o_cQThk8gbDelBRzEfdsqxCq_ppPr3v_Own8M-vR9yQElx5nEdlI4xe5QAMdIvr3g" + "12fMckydX9IsW4sVQ1kJJY8RrHb-WL-uI0WSWqoMSwf-Psb-UyiEHAjc3oK7fA72lBaGT4waPHOxRBPvezwg7N934vCZvZMAftFfVgmeEtbCeD7bF" + "umEr0uEmkIKPTg4QwP-VMvqoLBYpMiJVzP_Ipg_wRHJ7fUN0BGEPjjMvhQ_6TWByiQUBz1kTMd0Ebf_kEuXFQeiwA-FXHJpWczzh66CbbmmWAWsi" + - "ehKw3KPZeBj0oQ" + "ehKw3KPZeBj0oQ", ) val processor = authProcessorResolver.getAuthProcessor(token) @@ -32,7 +32,7 @@ class AuthProcessorResolverTest { "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJkcnBjIiwiaWF0IjoxNjkyMTg5NTUzfQ.sQ1Q3DFC7kOlHWdnWaxv2F" + "vhGso6ajJQVWtrE1hYmL_AIH_Lz8LNpqFShlL2itEGfmyRz5-Vrbdf-yWjeyLyNDlf7pay2lNE5Pvm2-EtQd8GUYcCFFIz7Sxc2Iphe2" + "YIx6kBwSlaR0RXBcmUlOtKrnON0bBNzSojBmtCT7-j4hTpoKhYr04Fr9EJWHfw7grVZjU8rEizAX_SR3ZNoufjK_pZaIyI9qUKVPYSepP" + - "lXtQzVjA80qSeYpkeFCOLwlQD_yTArDNWlwe7-CthtBOAtctoTMwyudfJezT2ilXrigzbauzU5BEi1cNxacHpjNuXhyY0TiacJGugWfRgaaGy6g" + "lXtQzVjA80qSeYpkeFCOLwlQD_yTArDNWlwe7-CthtBOAtctoTMwyudfJezT2ilXrigzbauzU5BEi1cNxacHpjNuXhyY0TiacJGugWfRgaaGy6g", ) val e = assertThrows(StatusException::class.java) { authProcessorResolver.getAuthProcessor(token) } @@ -46,7 +46,7 @@ class AuthProcessorResolverTest { "mG3Z-h9P1DlocTKZ3BpAKNdsvRGjXo71I0GUpUemAnauUaH-OgxUOHlNcZ2uB4f1poEWsbpExeuZ15YAiBf2WBCEV6J6xH1u0cPC1O-8" + "hHNb46166ngzo-BtZ7Rn7FeVEayyICslc9iXM5GvoFJyJIdn9uLMzalyDJq2bUmIelym4edkQ3ybF-pqf8garuVVErnAsbOFXbYQlfO5ZJ" + "4zq6PfJo7QSkreMzQ4tK_-JJIGG-EK1bQjsAD7JiXipY2cJY17VlHuavI0DfcJlOe-QggbTH63rxL6JvXCyFux7gI7zdqSBP1fNDJNzTLA" + - "cnR7jCN0kMIa8urQgdePZyRg" + "cnR7jCN0kMIa8urQgdePZyRg", ) val e = assertThrows(StatusException::class.java) { authProcessorResolver.getAuthProcessor(token) } diff --git a/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorV1Test.kt b/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorV1Test.kt index ca161ad9a..5b2c91154 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorV1Test.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/auth/processor/AuthProcessorV1Test.kt @@ -28,10 +28,11 @@ import java.time.Instant class AuthProcessorV1Test { private val processor = AuthProcessorV1( AuthorizationConfig( - true, "drpc", + true, + "drpc", AuthorizationConfig.ServerConfig.default(), - AuthorizationConfig.ClientConfig.default() - ) + AuthorizationConfig.ClientConfig.default(), + ), ) private val rsaKeyReader = RsaKeyReader() private val privProviderPath = ResourceUtils.getFile("classpath:keys/priv.p8.key").path @@ -65,7 +66,7 @@ class AuthProcessorV1Test { val e = assertThrows(StatusException::class.java) { processor.process(keyPair, token) } assertEquals( "INVALID_ARGUMENT: Invalid token: The Token's Signature resulted invalid when verified using the Algorithm: SHA256withRSA", - e.message + e.message, ) } @@ -80,7 +81,7 @@ class AuthProcessorV1Test { val e = assertThrows(StatusException::class.java) { processor.process(keyPair, invalidToken) } assertEquals( "INVALID_ARGUMENT: Invalid token: The Claim 'iss' value doesn't match the required issuer.", - e.message + e.message, ) } diff --git a/src/test/kotlin/io/emeraldpay/dshackle/auth/service/AuthServiceTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/auth/service/AuthServiceTest.kt index 8e1a24615..91c9b4ede 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/auth/service/AuthServiceTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/auth/service/AuthServiceTest.kt @@ -41,15 +41,20 @@ class AuthServiceTest { @Test fun `auth is successful`() { val tokenWrapper = AuthContext.TokenWrapper( - "token", Instant.now(), "sessionId" + "token", + Instant.now(), + "sessionId", ) val authService = AuthService( AuthorizationConfig( - true, "drpc", + true, + "drpc", AuthorizationConfig.ServerConfig("privPath", "pubPath"), - AuthorizationConfig.ClientConfig.default() + AuthorizationConfig.ClientConfig.default(), ), - rsaKeyReader, factory, authContext + rsaKeyReader, + factory, + authContext, ) val pair = KeyReader.Keys(mock(PrivateKey::class.java), mock(PublicKey::class.java)) @@ -66,19 +71,26 @@ class AuthServiceTest { @Test fun `parallel try to auth is successful`() { val tokenWrapper = AuthContext.TokenWrapper( - "token", Instant.now(), "sessionId" + "token", + Instant.now(), + "sessionId", ) val tokenWrapper1 = AuthContext.TokenWrapper( - "token", Instant.now(), "sessionIdNext" + "token", + Instant.now(), + "sessionIdNext", ) val pair = KeyReader.Keys(mock(PrivateKey::class.java), mock(PublicKey::class.java)) val authService = AuthService( AuthorizationConfig( - true, "drpc", + true, + "drpc", AuthorizationConfig.ServerConfig("privPath", "pubPath"), - AuthorizationConfig.ClientConfig.default() + AuthorizationConfig.ClientConfig.default(), ), - rsaKeyReader, factory, authContext + rsaKeyReader, + factory, + authContext, ) `when`(rsaKeyReader.getKeyPair("privPath", "pubPath")).thenReturn(pair) @@ -89,7 +101,8 @@ class AuthServiceTest { val task = Runnable { authService.authenticate(token) } CompletableFuture.allOf( - CompletableFuture.runAsync(task), CompletableFuture.runAsync(task) + CompletableFuture.runAsync(task), + CompletableFuture.runAsync(task), ).join() verify(rsaKeyReader, times(2)).getKeyPair("privPath", "pubPath") diff --git a/src/test/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReaderTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReaderTest.kt index 5f2f0cb0f..f69a05a7e 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReaderTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/auth/service/RsaKeyReaderTest.kt @@ -35,7 +35,7 @@ class RsaKeyReaderTest { "650627570641542946773123818063304222185205897480168513227047010620610697362185901253798594085716467" + "92700927695491574061920135297311257486773262784524717857554194798974994838378321973611865011031457" + "8859834631052697211398759550437148562864384448640344034211059348047816397935347753413946137935402" + - "562264627177210569215727831448291731093608051334025332988696191" + "562264627177210569215727831448291731093608051334025332988696191", ) publicExponent == pubExponent && modulus == pubModulus } @@ -50,7 +50,7 @@ class RsaKeyReaderTest { "2072047577218574632871804997852794886795318485439021501388394533101191305015940756335545719496" + "04557847518214006893286271137213491059994279470633688916032797849945887259137876037521925382454" + "762238089597912107394417801381736627011587603418078578130206830219321107525729614610300336784925" + - "6741484379041499791605663418628739419306248595872949" + "6741484379041499791605663418628739419306248595872949", ) val privExponent = BigInteger( "2704777724417882789147602456408780048462378556719441898242139736695157047955437327090684858" + @@ -59,7 +59,7 @@ class RsaKeyReaderTest { "7744591423894125208163912446945277960899800043458394321204754817284255735206518583285355872405" + "3966258052672146605639969648388744960700258048094135244952249403403074548577386549705289154261" + "2346391566526533514196717633725503640437930121313225102536030460301806443109607461162231878852" + - "64869837629637060803692577216204745443259318662678133769" + "64869837629637060803692577216204745443259318662678133769", ) privateExponent == privExponent && modulus == privModulus diff --git a/src/test/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStreamTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStreamTest.kt index 8ae7f5cce..6a1d63e38 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStreamTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/rpc/NativeCallStreamTest.kt @@ -37,7 +37,7 @@ class NativeCallStreamTest { val req = Mono.just( NativeCallRequest.newBuilder() .setChunkSize(1000) - .build() + .build(), ) val result = nativeCallStream.nativeCall(req) @@ -65,7 +65,7 @@ class NativeCallStreamTest { val req = Mono.just( NativeCallRequest.newBuilder() .setChunkSize(5) - .build() + .build(), ) val chunkResponse: (Int) -> BlockchainOuterClass.NativeCallReplyItem.Builder = { id -> @@ -82,18 +82,18 @@ class NativeCallStreamTest { .expectNext( chunkResponse(15) .setPayload(ByteString.copyFrom("\"0x11".toByteArray())) - .build() + .build(), ) .expectNext( chunkResponse(15) .setPayload(ByteString.copyFrom("26938".toByteArray())) - .build() + .build(), ) .expectNext( chunkResponse(15) .setFinalChunk(true) .setPayload(ByteString.copyFrom("\"".toByteArray())) - .build() + .build(), ) .expectComplete() .verify(Duration.ofSeconds(3)) @@ -115,14 +115,14 @@ class NativeCallStreamTest { val req = Mono.just( NativeCallRequest.newBuilder() .setChunkSize(1000) - .build() + .build(), ) val result = nativeCallStream.nativeCall(req) StepVerifier.create(result) .expectNext( - nativeCallResponse + nativeCallResponse, ) .expectComplete() .verify(Duration.ofSeconds(3)) @@ -145,7 +145,9 @@ class NativeCallStreamTest { } val nativeCallMock = mock { on { nativeCall(any()) } doReturn Flux.just( - nativeCallResponse(1, response), nativeCallResponse(2, response2), nativeCallResponse(3, response3) + nativeCallResponse(1, response), + nativeCallResponse(2, response2), + nativeCallResponse(3, response3), ).flatMap { when (it.id) { 1 -> Mono.just(it).delayElement(Duration.ofMillis(200)) @@ -158,7 +160,7 @@ class NativeCallStreamTest { val req = Mono.just( NativeCallRequest.newBuilder() .setSorted(true) - .build() + .build(), ) val result = nativeCallStream.nativeCall(req) diff --git a/src/test/kotlin/io/emeraldpay/dshackle/rpc/SelectorsTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/rpc/SelectorsTest.kt index 0f24d7bcf..1e44dbd36 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/rpc/SelectorsTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/rpc/SelectorsTest.kt @@ -21,42 +21,42 @@ internal class SelectorsTest { return Stream.of( Arguments.of( Selector.newBuilder().setLabelSelector(leafLabelSelector).build(), - null + null, ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) .setLabelSelector(leafLabelSelector).build(), Selector.newBuilder().setShouldBeForwarded(true) - .setLabelSelector(leafLabelSelector).build() + .setLabelSelector(leafLabelSelector).build(), ), Arguments.of( Selector.newBuilder().setOrSelector(OrSelector.newBuilder()).build(), - null + null, ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) .setOrSelector(OrSelector.newBuilder()).build(), - null + null, ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) .setOrSelector( OrSelector.newBuilder().addSelectors( - Selector.newBuilder().setLabelSelector(leafLabelSelector) - ) + Selector.newBuilder().setLabelSelector(leafLabelSelector), + ), ).build(), - null + null, ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) .setOrSelector( OrSelector.newBuilder().addSelectors( Selector.newBuilder().setShouldBeForwarded(true) - .setLabelSelector(leafLabelSelector) - ) + .setLabelSelector(leafLabelSelector), + ), ).build(), Selector.newBuilder().setShouldBeForwarded(true) - .setLabelSelector(leafLabelSelector).build() + .setLabelSelector(leafLabelSelector).build(), ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) @@ -64,14 +64,14 @@ internal class SelectorsTest { OrSelector.newBuilder() .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - .addSelectors(Selector.newBuilder().setLabelSelector(leafLabelSelector)) + .addSelectors(Selector.newBuilder().setLabelSelector(leafLabelSelector)), ).build(), Selector.newBuilder().setShouldBeForwarded(true) .setOrSelector( OrSelector.newBuilder() .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - ).build() + .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)), + ).build(), ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) @@ -79,35 +79,35 @@ internal class SelectorsTest { AndSelector.newBuilder() .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - .addSelectors(Selector.newBuilder().setLabelSelector(leafLabelSelector)) + .addSelectors(Selector.newBuilder().setLabelSelector(leafLabelSelector)), ).build(), Selector.newBuilder().setShouldBeForwarded(true) .setAndSelector( AndSelector.newBuilder() .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - ).build() + .addSelectors(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)), + ).build(), ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) .setNotSelector( NotSelector.newBuilder() - .setSelector(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) + .setSelector(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)), ).build(), Selector.newBuilder().setShouldBeForwarded(true) .setNotSelector( NotSelector.newBuilder() - .setSelector(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)) - ).build() + .setSelector(Selector.newBuilder().setShouldBeForwarded(true).setLabelSelector(leafLabelSelector)), + ).build(), ), Arguments.of( Selector.newBuilder().setShouldBeForwarded(true) .setNotSelector( NotSelector.newBuilder() - .setSelector(Selector.newBuilder().setLabelSelector(leafLabelSelector)) + .setSelector(Selector.newBuilder().setLabelSelector(leafLabelSelector)), ).build(), - null - ) + null, + ), ) } diff --git a/src/test/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuthTest.kt b/src/test/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuthTest.kt index 2ebc1be0e..2df0ddc1e 100644 --- a/src/test/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuthTest.kt +++ b/src/test/kotlin/io/emeraldpay/dshackle/upstream/grpc/auth/GrpcUpstreamsAuthTest.kt @@ -32,9 +32,10 @@ class GrpcUpstreamsAuthTest { private val providerPublicKeyPath = ResourceUtils.getFile("classpath:keys/public.pem").path private val grpcAuthContext = GrpcAuthContext() private val authConfig = AuthorizationConfig( - true, "drpc", + true, + "drpc", AuthorizationConfig.ServerConfig.default(), - AuthorizationConfig.ClientConfig(privateKeyPath) + AuthorizationConfig.ClientConfig(privateKeyPath), ) private val providerPrivateKeyPath = ResourceUtils.getFile("classpath:keys/priv.p8.key").path @@ -60,8 +61,8 @@ class GrpcUpstreamsAuthTest { Mono.just( AuthOuterClass.AuthResponse.newBuilder() .setProviderToken(token) - .build() - ) + .build(), + ), ) val result = grpcAuth.auth(upstreamId) @@ -90,8 +91,8 @@ class GrpcUpstreamsAuthTest { Mono.just( AuthOuterClass.AuthResponse.newBuilder() .setProviderToken(token) - .build() - ) + .build(), + ), ) val result = grpcAuth.auth(providerId) @@ -100,8 +101,8 @@ class GrpcUpstreamsAuthTest { .expectNext( GrpcUpstreamsAuth.AuthResult( false, - "Error during auth - The Token's Signature resulted invalid when verified using the Algorithm: SHA256withRSA" - ) + "Error during auth - The Token's Signature resulted invalid when verified using the Algorithm: SHA256withRSA", + ), ) .then { assertEquals(null, grpcAuthContext.getToken(upstreamId)) @@ -129,15 +130,15 @@ class GrpcUpstreamsAuthTest { Mono.just( AuthOuterClass.AuthResponse.newBuilder() .setProviderToken(token) - .build() - ) + .build(), + ), ) .thenReturn( Mono.just( AuthOuterClass.AuthResponse.newBuilder() .setProviderToken(token1) - .build() - ) + .build(), + ), ) grpcAuth.auth(providerId).block()