diff --git a/build.gradle b/build.gradle index cf0ef353..66ec9817 100644 --- a/build.gradle +++ b/build.gradle @@ -10,7 +10,7 @@ buildscript { gradlePluginPortal() } dependencies { - classpath 'com.google.protobuf:protobuf-gradle-plugin:0.9.1' + classpath 'com.google.protobuf:protobuf-gradle-plugin:0.10.0' } } diff --git a/gradle.properties b/gradle.properties index fd99adb0..eacee52b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ kotlin.code.style=official grpcVersion=1.49.2 -reactiveGrpcVersion=1.2.0 +reactiveGrpcVersion=1.2.4 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 2896e9d6..217a3f16 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,33 +1,33 @@ [versions] -groovy = "5.0.3" -protoc = "4.33.2" -jackson = "2.20.1" -grpc = "1.78.0" -spring-boot = "4.0.1" -reactor = "3.8.1" -netty = "4.2.9.Final" -netty-tcnative = "2.0.74.Final" -kotlin = "2.3.0" -httpcomponents = "5.5.1" +groovy = "5.0.6" +protoc = "4.34.1" +jackson = "2.21.3" +grpc = "1.81.0" +spring-boot = "4.0.6" +reactor = "3.8.5" +netty = "4.2.13.Final" +netty-tcnative = "2.0.77.Final" +kotlin = "2.3.21" +httpcomponents = "5.6.1" [libraries] -apache-commons-lang3 = "org.apache.commons:commons-lang3:3.9" -apache-commons-collections4 = "org.apache.commons:commons-collections4:4.3" +apache-commons-lang3 = "org.apache.commons:commons-lang3:3.20.0" +apache-commons-collections4 = "org.apache.commons:commons-collections4:4.5.0" apache-commons-math3 = "org.apache.commons:commons-math3:3.6.1" -commons-codec = "commons-codec:commons-codec:1.20.0" +commons-codec = "commons-codec:commons-codec:1.22.0" -bitcoinj = "org.bitcoinj:bitcoinj-core:0.15.8" +bitcoinj = "org.bitcoinj:bitcoinj-core:0.17.1" logstash-encoder = "net.logstash.logback:logstash-logback-encoder:9.0" -janino = "org.codehaus.janino:janino:3.1.9" +janino = "org.codehaus.janino:janino:3.1.12" -bouncycastle-prov = "org.bouncycastle:bcprov-jdk15on:1.61" -bouncycastle-pkix = 'org.bouncycastle:bcpkix-jdk15on:1.61' +bouncycastle-prov = "org.bouncycastle:bcprov-jdk15on:1.70" +bouncycastle-pkix = 'org.bouncycastle:bcpkix-jdk15on:1.70' caffeine = "com.github.ben-manes.caffeine:caffeine:2.8.5" -commons-io = "commons-io:commons-io:2.6" +commons-io = "commons-io:commons-io:2.22.0" cglib-nodep = "cglib:cglib-nodep:3.3.0" @@ -52,7 +52,7 @@ jackson-datatype-jsr310 = { module = "com.fasterxml.jackson.datatype:jackson-dat jackson-module-kotlin = { module = "com.fasterxml.jackson.module:jackson-module-kotlin", version.ref = "jackson" } jackson-yaml = { module = "com.fasterxml.jackson.dataformat:jackson-dataformat-yaml", version.ref = "jackson" } -java-websocket = "org.java-websocket:Java-WebSocket:1.5.1" +java-websocket = "org.java-websocket:Java-WebSocket:1.6.0" javax-annotations = "javax.annotation:javax.annotation-api:1.3.2" @@ -61,13 +61,13 @@ kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = lettuce-core = "io.lettuce:lettuce-core:7.5.2.RELEASE" -prom-exporter-server = "io.prometheus:prometheus-metrics-exporter-httpserver:1.5.0" -micrometer-registry-prometheus = "io.micrometer:micrometer-registry-prometheus:1.16.0" -micrometer-ctx-prop = "io.micrometer:context-propagation:1.2.0" +prom-exporter-server = "io.prometheus:prometheus-metrics-exporter-httpserver:1.6.1" +micrometer-registry-prometheus = "io.micrometer:micrometer-registry-prometheus:1.16.5" +micrometer-ctx-prop = "io.micrometer:context-propagation:1.2.1" mockserver-netty = "org.mock-server:mockserver-netty:5.15.0" -mockito-kotlin = "org.mockito.kotlin:mockito-kotlin:6.1.0" +mockito-kotlin = "org.mockito.kotlin:mockito-kotlin:6.3.0" netty-common = { module = "io.netty:netty-common", version.ref = "netty" } netty-transport = { module = "io.netty:netty-transport", version.ref = "netty" } @@ -83,18 +83,18 @@ netty-tcnative-core = { module = "io.netty:netty-tcnative", version.ref = "netty netty-tcnative-boringssl = { module = "io.netty:netty-tcnative-boringssl-static", version.ref = "netty-tcnative"} netty-macos = { module = "io.netty:netty-resolver-dns-native-macos", version.ref = "netty" } -zeromq = "org.zeromq:jeromq:0.5.2" +zeromq = "org.zeromq:jeromq:0.6.0" -objgenesis = "org.objenesis:objenesis:3.1" +objgenesis = "org.objenesis:objenesis:3.5" reactor-core = { module = "io.projectreactor:reactor-core", version.ref = "reactor" } reactor-micrometer = { module = "io.projectreactor:reactor-core-micrometer", version.ref = "reactor" } -reactor-netty = { module = "io.projectreactor.netty:reactor-netty", version = "1.3.1" } +reactor-netty = { module = "io.projectreactor.netty:reactor-netty", version = "1.3.5" } reactor-extra = { module = "io.projectreactor.addons:reactor-extra", version = "3.6.0" } -reactor-kotlin = { module = "io.projectreactor.kotlin:reactor-kotlin-extensions", version = "1.1.7" } +reactor-kotlin = { module = "io.projectreactor.kotlin:reactor-kotlin-extensions", version = "1.3.0" } reactor-test = { module = "io.projectreactor:reactor-test", version.ref = "reactor" } -reactor-grpc-stub = "com.salesforce.servicelibs:reactor-grpc-stub:1.2.0" +reactor-grpc-stub = "com.salesforce.servicelibs:reactor-grpc-stub:1.2.4" snake-yaml = "org.yaml:snakeyaml:2.6" @@ -105,15 +105,15 @@ spring-boot-starter-actuator = { module = "org.springframework.boot:spring-boot- spring-boot-starter-test = { module = "org.springframework.boot:spring-boot-starter-test", version.ref = "spring-boot" } -testcontainers = "org.testcontainers:testcontainers:2.0.3" +testcontainers = "org.testcontainers:testcontainers:2.0.5" testcontainers-ganache = "io.github.ganchix:testcontainers-java-module-ganache:0.0.4" -assertj = "org.assertj:assertj-core:3.23.1" +assertj = "org.assertj:assertj-core:3.27.7" -brave-instrumentation-grpc = "io.zipkin.brave:brave-instrumentation-grpc:6.3.0" -brave-ctx-slf4j = "io.zipkin.brave:brave-context-slf4j:6.3.0" +brave-instrumentation-grpc = "io.zipkin.brave:brave-instrumentation-grpc:6.3.1" +brave-ctx-slf4j = "io.zipkin.brave:brave-context-slf4j:6.3.1" -auth0-jwt = "com.auth0:java-jwt:4.4.0" +auth0-jwt = "com.auth0:java-jwt:4.5.2" mockito-inline = "org.mockito:mockito-inline:5.2.0" @@ -135,8 +135,8 @@ bouncycastle = ["bouncycastle-pkix", "bouncycastle-prov"] [plugins] kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" } -jib = { id = "com.google.cloud.tools.jib", version = "3.5.2" } -spring = { id = "org.springframework.boot", version = "4.0.1" } +jib = { id = "com.google.cloud.tools.jib", version = "3.5.3" } +spring = { id = "org.springframework.boot", version = "4.0.6" } git = { id = "com.palantir.git-version", version = "5.0.0" } -protobuf = { id = "com.google.protobuf", version = "0.9.6" } +protobuf = { id = "com.google.protobuf", version = "0.10.0" } ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.6.0" } diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 7454180f..b1b8ef56 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 63e0e830..4dcb8425 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,8 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip +networkTimeout=10000 +retries=0 +retryBackOffMs=500 zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c7873..b9bb139f 100755 --- a/gradlew +++ b/gradlew @@ -1,7 +1,7 @@ #!/bin/sh # -# Copyright © 2015-2021 the original authors. +# Copyright © 2015 the original authors. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. # +# SPDX-License-Identifier: Apache-2.0 +# ############################################################################## # @@ -55,7 +57,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/3d91ce3b8caaf77ad09f381f43615b715b53f72c/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +82,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -133,22 +132,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -165,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -193,18 +198,27 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ - org.gradle.wrapper.GradleWrapperMain \ + -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index ac1b06f9..aa5f10b0 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -13,19 +13,22 @@ @rem See the License for the specific language governing permissions and @rem limitations under the License. @rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## -@rem Set local scope for the variables with windows NT shell -if "%OS%"=="Windows_NT" setlocal +@rem Set local scope for the variables, and ensure extensions are enabled +setlocal EnableExtensions set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,15 +43,15 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% @@ -56,34 +59,24 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 -goto fail +"%COMSPEC%" /c exit 1 :execute @rem Setup the command line -set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* +@rem endlocal doesn't take effect until after the line is parsed and variables are expanded +@rem which allows us to clear the local environment before executing the java command +endlocal & "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* & call :exitWithErrorLevel -:end -@rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd - -:fail -rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of -rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 - -:mainEnd -if "%OS%"=="Windows_NT" endlocal - -:omega +:exitWithErrorLevel +@rem Use "%COMSPEC%" /c exit to allow operators to work properly in scripts +"%COMSPEC%" /c exit %ERRORLEVEL% 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 5b65b3ed..27166fc9 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/AddressActiveCheck.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/AddressActiveCheck.kt @@ -15,7 +15,7 @@ */ package io.emeraldpay.dshackle.upstream.bitcoin -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address import org.slf4j.LoggerFactory import reactor.core.publisher.Mono 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 5a85eba3..14fb535c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/BitcoinReader.kt @@ -25,7 +25,7 @@ import io.emeraldpay.dshackle.upstream.Lifecycle import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent import io.emeraldpay.dshackle.upstream.rpcclient.ListParams -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address import org.slf4j.LoggerFactory import reactor.core.publisher.Mono import reactor.kotlin.core.publisher.cast 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 f9364dba..eb9709d7 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClient.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClient.kt @@ -22,7 +22,7 @@ import io.netty.handler.codec.http.HttpHeaderNames import io.netty.handler.codec.http.HttpHeaders import io.netty.handler.ssl.SslContextBuilder import io.netty.resolver.DefaultAddressResolverGroup -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address import org.slf4j.LoggerFactory import reactor.core.publisher.Mono import reactor.netty.http.client.HttpClient 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 58d39d67..4575c2d6 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraUnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/EsploraUnspentReader.kt @@ -18,7 +18,7 @@ package io.emeraldpay.dshackle.upstream.bitcoin import io.emeraldpay.dshackle.upstream.Head import io.emeraldpay.dshackle.upstream.bitcoin.data.EsploraUnspent import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address import org.slf4j.LoggerFactory import reactor.core.publisher.Mono import java.util.function.Function diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/LocalCallRouter.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/LocalCallRouter.kt index 5617eacc..77c58c11 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/LocalCallRouter.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/LocalCallRouter.kt @@ -26,7 +26,8 @@ import io.emeraldpay.dshackle.upstream.calls.CallMethods import io.emeraldpay.dshackle.upstream.ethereum.rpc.RpcException import io.emeraldpay.dshackle.upstream.ethereum.rpc.RpcResponseError import io.emeraldpay.dshackle.upstream.rpcclient.ListParams -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address +import org.bitcoinj.base.AddressParser import org.slf4j.LoggerFactory import reactor.core.publisher.Mono @@ -70,7 +71,7 @@ class LocalCallRouter( } val addresses = key.params.list[2] if (addresses is List<*> && addresses.size > 0) { - val address = addresses[0].toString().let { Address.fromString(null, it) } + val address = addresses[0].toString().let { AddressParser.getDefault().parseAddress(it) } return reader.listUnspent(address).map { val rpc = it.map(convertUnspent(address)) val json = Global.objectMapper.writeValueAsBytes(rpc) 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 28e836b8..3331a03c 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RemoteUnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RemoteUnspentReader.kt @@ -3,7 +3,7 @@ package io.emeraldpay.dshackle.upstream.bitcoin import io.emeraldpay.dshackle.upstream.Capability import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address import reactor.core.publisher.Mono class RemoteUnspentReader( 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 ecc53cd8..3dca232b 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReader.kt @@ -24,7 +24,7 @@ import io.emeraldpay.dshackle.upstream.Selector import io.emeraldpay.dshackle.upstream.bitcoin.data.RpcUnspent import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent import io.emeraldpay.dshackle.upstream.rpcclient.ListParams -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address import org.slf4j.LoggerFactory import reactor.core.publisher.Mono diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/UnspentReader.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/UnspentReader.kt index d922c587..cb1c88cb 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/UnspentReader.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/UnspentReader.kt @@ -17,6 +17,6 @@ package io.emeraldpay.dshackle.upstream.bitcoin import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.bitcoin.data.SimpleUnspent -import org.bitcoinj.core.Address +import org.bitcoinj.base.Address interface UnspentReader : Reader> 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 4f55f876..64d5b3af 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddresses.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddresses.kt @@ -15,15 +15,16 @@ */ package io.emeraldpay.dshackle.upstream.bitcoin -import org.bitcoinj.core.Address -import org.bitcoinj.core.ECKey +import org.bitcoinj.base.Address +import org.bitcoinj.base.BitcoinNetwork +import org.bitcoinj.base.LegacyAddress +import org.bitcoinj.base.ScriptType +import org.bitcoinj.base.SegwitAddress import org.bitcoinj.core.NetworkParameters import org.bitcoinj.crypto.ChildNumber import org.bitcoinj.crypto.DeterministicKey +import org.bitcoinj.crypto.ECKey import org.bitcoinj.crypto.HDKeyDerivation -import org.bitcoinj.params.MainNetParams -import org.bitcoinj.params.TestNet3Params -import org.bitcoinj.script.Script import org.slf4j.LoggerFactory import reactor.core.publisher.Flux import reactor.util.function.Tuples @@ -35,8 +36,6 @@ open class XpubAddresses( companion object { private val log = LoggerFactory.getLogger(XpubAddresses::class.java) - private val MAINNET = MainNetParams() - private val TESTNET = TestNet3Params() private val INACTIVE_LIMIT = 20 } @@ -45,39 +44,45 @@ open class XpubAddresses( // https://electrum.readthedocs.io/en/latest/xpub_version_bytes.html // TODO doesn't support SH keys right now. should? val prefix = xpub.substring(0, 4) - val type: Script.ScriptType - val network: NetworkParameters + val type: ScriptType + val params: NetworkParameters when (prefix) { "xpub" -> { - type = Script.ScriptType.P2PKH - network = MAINNET + type = ScriptType.P2PKH + params = NetworkParameters.of(BitcoinNetwork.MAINNET) } "zpub" -> { - type = Script.ScriptType.P2WPKH - network = MAINNET + type = ScriptType.P2WPKH + params = NetworkParameters.of(BitcoinNetwork.MAINNET) } "tpub" -> { - type = Script.ScriptType.P2PKH - network = TESTNET + type = ScriptType.P2PKH + params = NetworkParameters.of(BitcoinNetwork.TESTNET) } "vpub" -> { - type = Script.ScriptType.P2WPKH - network = TESTNET + type = ScriptType.P2WPKH + params = NetworkParameters.of(BitcoinNetwork.TESTNET) } else -> return Flux.error(IllegalArgumentException("Unsupported type: $prefix")) } val key: DeterministicKey try { - key = DeterministicKey.deserializeB58(xpub, network) + key = DeterministicKey.deserializeB58(xpub, params) } catch (t: Throwable) { return Flux.error(t) } return Flux.range(start, limit) .map { HDKeyDerivation.deriveChildKey(key, ChildNumber(it, false)) } - .map { Address.fromKey(network, ECKey.fromPublicOnly(it.pubKeyPoint), type) } + .map { addressFromKey(params, ECKey.fromPublicOnly(it.pubKey), type) } + } + + private fun addressFromKey(params: NetworkParameters, key: ECKey, type: ScriptType): Address = when (type) { + ScriptType.P2PKH -> LegacyAddress.fromKey(params, key) + ScriptType.P2WPKH -> SegwitAddress.fromKey(params, key) + else -> throw IllegalArgumentException("Unsupported script type: $type") } open fun activeAddresses(xpub: String, start: Int, limit: Int): Flux
{ diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt index 4921d236..a2ecb61e 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/EthereumUpstreamValidator.kt @@ -34,7 +34,7 @@ import io.emeraldpay.dshackle.upstream.rpcclient.ListParams import org.slf4j.Logger import org.slf4j.LoggerFactory import reactor.core.publisher.Mono -import reactor.kotlin.extra.retry.retryRandomBackoff +import reactor.util.retry.Retry import java.math.BigInteger import java.time.Duration import java.util.concurrent.TimeoutException @@ -75,12 +75,17 @@ abstract class AbstractCallLimitValidator( Mono.fromCallable { log.error("No response for eth_call limit check from ${upstream.getId()}") } .then(Mono.error(TimeoutException("Validation timeout for call limit"))), ) - .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> - log.warn( - "error during validateCallLimit for ${upstream.getId()}, iteration ${ctx.iteration()}, " + - "message ${ctx.exception().message}", - ) - } + .retryWhen( + Retry.backoff(3, Duration.ofMillis(100)) + .maxBackoff(Duration.ofMillis(500)) + .jitter(1.0) + .doBeforeRetry { signal -> + log.warn( + "error during validateCallLimit for ${upstream.getId()}, iteration ${signal.totalRetries() + 1}, " + + "message ${signal.failure().message}", + ) + }, + ) .onErrorReturn(ValidateUpstreamSettingsResult.UPSTREAM_SETTINGS_ERROR) } @@ -164,14 +169,19 @@ class ChainIdValidator( private fun chainId(): Mono { return validatorReader.get() .read(ChainRequest("eth_chainId", ListParams())) - .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> - log.warn( - "error during chainId retrieving for {}, iteration {}, reason - {}", - upstream.getId(), - ctx.iteration(), - ctx.exception().message, - ) - } + .retryWhen( + Retry.backoff(3, Duration.ofMillis(100)) + .maxBackoff(Duration.ofMillis(500)) + .jitter(1.0) + .doBeforeRetry { signal -> + log.warn( + "error during chainId retrieving for {}, iteration {}, reason - {}", + upstream.getId(), + signal.totalRetries() + 1, + signal.failure().message, + ) + }, + ) .doOnError { log.error("Error during execution 'eth_chainId' - {} for {}", it.message, upstream.getId()) } .flatMap(ChainResponse::requireStringResult) } @@ -179,14 +189,19 @@ class ChainIdValidator( private fun netVersion(): Mono { return validatorReader.get() .read(ChainRequest("net_version", ListParams())) - .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> - log.warn( - "error during netVersion retrieving for {}, iteration {}, reason - {}", - upstream.getId(), - ctx.iteration(), - ctx.exception().message, - ) - } + .retryWhen( + Retry.backoff(3, Duration.ofMillis(100)) + .maxBackoff(Duration.ofMillis(500)) + .jitter(1.0) + .doBeforeRetry { signal -> + log.warn( + "error during netVersion retrieving for {}, iteration {}, reason - {}", + upstream.getId(), + signal.totalRetries() + 1, + signal.failure().message, + ) + }, + ) .doOnError { log.error("Error during execution 'net_version' - {} for {}", it.message, upstream.getId()) } .flatMap(ChainResponse::requireStringResult) } @@ -264,14 +279,19 @@ class ErigonBuggedValidator( private fun isErigon(): Mono = upstream.getIngressReader() .read(ChainRequest("web3_clientVersion", ListParams())) - .retryRandomBackoff(3, Duration.ofMillis(100), Duration.ofMillis(500)) { ctx -> - log.warn( - "error during clientVersion retrieving for {}, iteration {}, reason - {}", - upstream.getId(), - ctx.iteration(), - ctx.exception().message, - ) - } + .retryWhen( + Retry.backoff(3, Duration.ofMillis(100)) + .maxBackoff(Duration.ofMillis(500)) + .jitter(1.0) + .doBeforeRetry { signal -> + log.warn( + "error during clientVersion retrieving for {}, iteration {}, reason - {}", + upstream.getId(), + signal.totalRetries() + 1, + signal.failure().message, + ) + }, + ) .flatMap(ChainResponse::requireStringResult) .map { it.lowercase().contains("erigon") } .doOnError { log.error("Error during execution 'web3_clientVersion' - {} for {}", it.message, upstream.getId()) } diff --git a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/LogIndexValidator.kt b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/LogIndexValidator.kt index d3c1bb33..bea004d3 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/LogIndexValidator.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/ethereum/LogIndexValidator.kt @@ -26,7 +26,7 @@ import io.emeraldpay.dshackle.upstream.rpcclient.ListParams import org.slf4j.Logger import org.slf4j.LoggerFactory import reactor.core.publisher.Mono -import reactor.kotlin.extra.retry.retryRandomBackoff +import reactor.util.retry.Retry import java.time.Duration import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicReference @@ -84,12 +84,17 @@ class LogIndexValidator( } } .timeout(Duration.ofSeconds(15)) - .retryRandomBackoff(2, Duration.ofMillis(200), Duration.ofMillis(1000)) { ctx -> - log.debug( - "Retry logIndex validation for ${upstream.getId()}, iteration ${ctx.iteration()}, " + - "error: ${ctx.exception().message}", - ) - } + .retryWhen( + Retry.backoff(2, Duration.ofMillis(200)) + .maxBackoff(Duration.ofMillis(1000)) + .jitter(1.0) + .doBeforeRetry { signal -> + log.debug( + "Retry logIndex validation for ${upstream.getId()}, iteration ${signal.totalRetries() + 1}, " + + "error: ${signal.failure().message}", + ) + }, + ) .onErrorResume { err -> log.warn("Error during logIndex validation for ${upstream.getId()}: ${err.message}") // In case of error, return last known state to avoid false positives 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 493c2486..2acd0b75 100644 --- a/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt +++ b/src/main/kotlin/io/emeraldpay/dshackle/upstream/grpc/GrpcHead.kt @@ -35,7 +35,7 @@ import reactor.core.publisher.Flux import reactor.core.publisher.Mono import reactor.core.publisher.Sinks import reactor.core.scheduler.Scheduler -import reactor.kotlin.extra.retry.retryExponentialBackoff +import reactor.util.retry.Retry import java.time.Duration import java.util.function.Function @@ -108,14 +108,14 @@ class GrpcHead( blocks = blocks.doOnNext { log.trace("Received block ${it.height}") - }.retryExponentialBackoff( - Long.MAX_VALUE, - Duration.ofMillis(100), - Duration.ofSeconds(60), - true, - ) { - log.debug("Retry grpc head connection ${parent.getId()}") - } + }.retryWhen( + Retry.backoff(Long.MAX_VALUE, Duration.ofMillis(100)) + .maxBackoff(Duration.ofSeconds(60)) + .jitter(0.5) + .doBeforeRetry { + log.debug("Retry grpc head connection ${parent.getId()}") + }, + ) headSubscription = super.follow(blocks) } diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClientSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClientSpec.groovy index bc7af0f0..5975f71b 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClientSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/EsploraClientSpec.groovy @@ -1,7 +1,7 @@ package io.emeraldpay.dshackle.upstream.bitcoin import io.emeraldpay.dshackle.upstream.bitcoin.data.EsploraUnspent -import org.bitcoinj.core.Address +import org.bitcoinj.base.AddressParser /** * Copyright (c) 2020 EmeraldPay, Inc @@ -19,8 +19,6 @@ import org.bitcoinj.core.Address * limitations under the License. */ -import org.bitcoinj.params.MainNetParams -import org.bitcoinj.params.TestNet3Params import org.mockserver.integration.ClientAndServer import org.mockserver.model.HttpRequest import org.mockserver.model.HttpResponse @@ -53,7 +51,7 @@ class EsploraClientSpec extends Specification { ) def client = new EsploraClient(new URI("http://localhost:${mockServer.port}"), null, null) when: - def act = client.getUtxo(Address.fromString(new MainNetParams(), "35vktkPo4wdK8Twu4VMiuPLdCx23XEykGY")) + def act = client.getUtxo(AddressParser.getDefault().parseAddress("35vktkPo4wdK8Twu4VMiuPLdCx23XEykGY")) then: StepVerifier.create(act) @@ -74,7 +72,7 @@ class EsploraClientSpec extends Specification { .verify(Duration.ofSeconds(3)) when: - def actTotal = client.getUtxo(Address.fromString(new MainNetParams(), "35vktkPo4wdK8Twu4VMiuPLdCx23XEykGY")) + def actTotal = client.getUtxo(AddressParser.getDefault().parseAddress("35vktkPo4wdK8Twu4VMiuPLdCx23XEykGY")) .block() .sum { it.value } @@ -94,7 +92,7 @@ class EsploraClientSpec extends Specification { ) def client = new EsploraClient(new URI("http://localhost:${mockServer.port}"), null, null) when: - def act = client.getTransactions(Address.fromString(TestNet3Params.get(), "tb1qyatuwvkfx8thy2ntmtuea6v42vp3zefqvll8kx")) + def act = client.getTransactions(AddressParser.getDefault().parseAddress("tb1qyatuwvkfx8thy2ntmtuea6v42vp3zefqvll8kx")) then: StepVerifier.create(act) @@ -124,7 +122,7 @@ class EsploraClientSpec extends Specification { ) def client = new EsploraClient(new URI("http://localhost:${mockServer.port}"), null, null) when: - def act = client.getTransactions(Address.fromString(TestNet3Params.get(), "tb1qyatuwvkfx8thy2ntmtuea6v42vp3zefqvll8kx")) + def act = client.getTransactions(AddressParser.getDefault().parseAddress("tb1qyatuwvkfx8thy2ntmtuea6v42vp3zefqvll8kx")) then: StepVerifier.create(act) diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReaderSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReaderSpec.groovy index 578ad832..c80f238a 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReaderSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/RpcUnspentReaderSpec.groovy @@ -19,8 +19,7 @@ import io.emeraldpay.dshackle.reader.Reader import io.emeraldpay.dshackle.upstream.ChainRequest import io.emeraldpay.dshackle.upstream.ChainResponse import io.emeraldpay.dshackle.upstream.rpcclient.ListParams -import org.bitcoinj.core.Address -import org.bitcoinj.params.MainNetParams +import org.bitcoinj.base.AddressParser import reactor.core.publisher.Mono import spock.lang.Specification @@ -38,7 +37,7 @@ class RpcUnspentReaderSpec extends Specification { def reader = new RpcUnspentReader(upstreams) when: - def act = reader.read(Address.fromString(new MainNetParams(), "1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK")).block() + def act = reader.read(AddressParser.getDefault().parseAddress("1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK")).block() then: // cat src/test/resources/bitcoin/unspent-one-addr.json | jq '. | length' @@ -72,7 +71,7 @@ class RpcUnspentReaderSpec extends Specification { def reader = new RpcUnspentReader(upstreams) when: - def act = reader.read(Address.fromString(new MainNetParams(), "35hK24tcLEWcgNA4JxpvbkNkoAcDGqQPsP")).block() + def act = reader.read(AddressParser.getDefault().parseAddress("35hK24tcLEWcgNA4JxpvbkNkoAcDGqQPsP")).block() then: // cat src/test/resources/bitcoin/unspent-two-addr.json | jq '[.[] | select(.address == "35hK24tcLEWcgNA4JxpvbkNkoAcDGqQPsP")] | length' @@ -107,7 +106,7 @@ class RpcUnspentReaderSpec extends Specification { def reader = new RpcUnspentReader(upstreams) when: - def act = reader.read(Address.fromString(new MainNetParams(), "1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK")).block() + def act = reader.read(AddressParser.getDefault().parseAddress("1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK")).block() then: // cat src/test/resources/bitcoin/unspent-two-addr.json | jq '[.[] | select(.address == "1K7xkspJg7DDKNwzXgoRSDCUxiFsRegsSK")] | length' diff --git a/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddressesSpec.groovy b/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddressesSpec.groovy index c3f6d096..8ddd648d 100644 --- a/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddressesSpec.groovy +++ b/src/test/groovy/io/emeraldpay/dshackle/upstream/bitcoin/XpubAddressesSpec.groovy @@ -15,8 +15,7 @@ */ package io.emeraldpay.dshackle.upstream.bitcoin -import org.bitcoinj.core.Address -import org.bitcoinj.params.MainNetParams +import org.bitcoinj.base.AddressParser import reactor.core.publisher.Mono import reactor.test.StepVerifier import spock.lang.Specification @@ -119,7 +118,7 @@ class XpubAddressesSpec extends Specification { def "list when only fist is active"() { setup: AddressActiveCheck check = Mock(AddressActiveCheck) { - 1 * isActive(Address.fromString(MainNetParams.get(), "bc1qaexx257l7sgm62szw2ulj6n2v99t5ph9ekkul3")) >> Mono.just(true) + 1 * isActive(AddressParser.getDefault().parseAddress("bc1qaexx257l7sgm62szw2ulj6n2v99t5ph9ekkul3")) >> Mono.just(true) 20 * isActive(_) >> Mono.just(false) } XpubAddresses addresses = new XpubAddresses(check) @@ -143,7 +142,7 @@ class XpubAddressesSpec extends Specification { def "list when only 3rd is active"() { setup: AddressActiveCheck check = Mock(AddressActiveCheck) { - 1 * isActive(Address.fromString(MainNetParams.get(), "bc1qah84zz7aavf3f5eyx5f29809y6xugqyphq0wtz")) >> Mono.just(true) + 1 * isActive(AddressParser.getDefault().parseAddress("bc1qah84zz7aavf3f5eyx5f29809y6xugqyphq0wtz")) >> Mono.just(true) // 2 times before, 20 times after 22 * isActive(_) >> Mono.just(false) } @@ -169,11 +168,11 @@ class XpubAddressesSpec extends Specification { setup: AddressActiveCheck check = Mock(AddressActiveCheck) { // 2 - 1 * isActive(Address.fromString(MainNetParams.get(), "bc1qah84zz7aavf3f5eyx5f29809y6xugqyphq0wtz")) >> Mono.just(true) + 1 * isActive(AddressParser.getDefault().parseAddress("bc1qah84zz7aavf3f5eyx5f29809y6xugqyphq0wtz")) >> Mono.just(true) // 11 - 1 * isActive(Address.fromString(MainNetParams.get(), "bc1q3kqug4cx95a02yhwn6geelftmw3zklrgmhjll8")) >> Mono.just(true) + 1 * isActive(AddressParser.getDefault().parseAddress("bc1q3kqug4cx95a02yhwn6geelftmw3zklrgmhjll8")) >> Mono.just(true) // 22 - 1 * isActive(Address.fromString(MainNetParams.get(), "bc1qf7m2rrmrksj34vhgxmm04y43dlj7c5f58f8ku6")) >> Mono.just(true) + 1 * isActive(AddressParser.getDefault().parseAddress("bc1qf7m2rrmrksj34vhgxmm04y43dlj7c5f58f8ku6")) >> Mono.just(true) // 0..1 = 2 // + 3..10 = 8 // + 12..21 = 10