From b73fff0aad5dd24bb395bf571233edc7674f59a6 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 21:50:47 -0500 Subject: [PATCH 01/24] Refactor: Move AsciiLogo to common --- .../src/main/java/bisq/common}/app/AsciiLogo.java | 2 +- core/src/main/java/bisq/core/app/BisqExecutable.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) rename {core/src/main/java/bisq/core => common/src/main/java/bisq/common}/app/AsciiLogo.java (99%) diff --git a/core/src/main/java/bisq/core/app/AsciiLogo.java b/common/src/main/java/bisq/common/app/AsciiLogo.java similarity index 99% rename from core/src/main/java/bisq/core/app/AsciiLogo.java rename to common/src/main/java/bisq/common/app/AsciiLogo.java index f8d30333ddb..f1433cd6c15 100644 --- a/core/src/main/java/bisq/core/app/AsciiLogo.java +++ b/common/src/main/java/bisq/common/app/AsciiLogo.java @@ -15,7 +15,7 @@ * along with Bisq. If not, see . */ -package bisq.core.app; +package bisq.common.app; import lombok.extern.slf4j.Slf4j; diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index f9961adda23..fd1b07e7a11 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -32,6 +32,7 @@ import bisq.common.UserThread; import bisq.common.app.AppModule; +import bisq.common.app.AsciiLogo; import bisq.common.app.DevEnv; import bisq.common.config.BisqHelpFormatter; import bisq.common.config.Config; From fe7ccbd6f9befa400af40c5a5a8ac3bd9954f309 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 21:51:31 -0500 Subject: [PATCH 02/24] Refactor: extract method --- common/src/main/java/bisq/common/setup/CommonSetup.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 73681d2679d..5b81623e368 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -36,6 +36,10 @@ public class CommonSetup { public static void setup(UncaughtExceptionHandler uncaughtExceptionHandler) { setupErrorHandler(uncaughtExceptionHandler); + setSystemProperties(); + } + + protected static void setSystemProperties() { if (Utilities.isLinux()) System.setProperty("prism.lcdtext", "false"); } From b6e97e371e8c172832b509144cb5ce336bcb04af Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 21:53:29 -0500 Subject: [PATCH 03/24] Refactor: add new setup method to CommonSetup with config (WIP) and call it at doExecute. Move AsciiLogo to CommonSetup --- common/src/main/java/bisq/common/setup/CommonSetup.java | 9 +++++++-- core/src/main/java/bisq/core/app/BisqExecutable.java | 7 ++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 5b81623e368..b145a3a2d3b 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -18,6 +18,8 @@ package bisq.common.setup; import bisq.common.UserThread; +import bisq.common.app.AsciiLogo; +import bisq.common.config.Config; import bisq.common.crypto.CryptoUtils; import bisq.common.crypto.LimitedKeyStrengthException; import bisq.common.util.Utilities; @@ -33,10 +35,13 @@ @Slf4j public class CommonSetup { + public static void setup(Config config) { + AsciiLogo.showAsciiLogo(); + setSystemProperties(); + } + public static void setup(UncaughtExceptionHandler uncaughtExceptionHandler) { setupErrorHandler(uncaughtExceptionHandler); - - setSystemProperties(); } protected static void setSystemProperties() { diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index fd1b07e7a11..448219743f5 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -32,13 +32,13 @@ import bisq.common.UserThread; import bisq.common.app.AppModule; -import bisq.common.app.AsciiLogo; import bisq.common.app.DevEnv; import bisq.common.config.BisqHelpFormatter; import bisq.common.config.Config; import bisq.common.config.ConfigException; import bisq.common.handlers.ResultHandler; import bisq.common.proto.persistable.PersistedDataHost; +import bisq.common.setup.CommonSetup; import bisq.common.setup.GracefulShutDownHandler; import bisq.common.util.Utilities; @@ -103,9 +103,10 @@ public void execute(String[] args) { /////////////////////////////////////////////////////////////////////////////////////////// protected void doExecute() { - AsciiLogo.showAsciiLogo(); - configUserThread(); + CommonSetup.setup(config); CoreSetup.setup(config); + + configUserThread(); addCapabilities(); Signal.handle(new Signal("INT"), signal -> { From 7ea3676c55e060cf52a8b0e3de518dd922bc405e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 21:55:50 -0500 Subject: [PATCH 04/24] Refactor: Rename setup to setupUncaughtExceptionHandler rename setupErrorHandler to checkCryptoPolicySetup move UncaughtExceptionHandler code to setupUncaughtExceptionHandler --- .../java/bisq/common/setup/CommonSetup.java | 19 +++++++++---------- .../bisq/core/app/BisqHeadlessAppMain.java | 4 +--- .../java/bisq/daemon/app/BisqDaemonMain.java | 2 +- .../java/bisq/desktop/app/BisqAppMain.java | 2 +- .../main/java/bisq/seednode/SeedNodeMain.java | 2 +- .../java/bisq/statistics/StatisticsMain.java | 4 +--- 6 files changed, 14 insertions(+), 19 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index b145a3a2d3b..ac2a95b0036 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -40,16 +40,7 @@ public static void setup(Config config) { setSystemProperties(); } - public static void setup(UncaughtExceptionHandler uncaughtExceptionHandler) { - setupErrorHandler(uncaughtExceptionHandler); - } - - protected static void setSystemProperties() { - if (Utilities.isLinux()) - System.setProperty("prism.lcdtext", "false"); - } - - private static void setupErrorHandler(UncaughtExceptionHandler uncaughtExceptionHandler) { + public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) { Thread.UncaughtExceptionHandler handler = (thread, throwable) -> { // Might come from another thread if (throwable.getCause() != null && throwable.getCause().getCause() != null && @@ -69,7 +60,15 @@ private static void setupErrorHandler(UncaughtExceptionHandler uncaughtException }; Thread.setDefaultUncaughtExceptionHandler(handler); Thread.currentThread().setUncaughtExceptionHandler(handler); + } + + protected static void setSystemProperties() { + if (Utilities.isLinux()) + System.setProperty("prism.lcdtext", "false"); + } + //TODO not needed anymore + private static void checkCryptoPolicySetup(UncaughtExceptionHandler uncaughtExceptionHandler) { try { CryptoUtils.checkCryptoPolicySetup(); } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) { diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java b/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java index 5c8491c999d..4bd829f9a69 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java @@ -22,8 +22,6 @@ import bisq.common.app.Version; import bisq.common.setup.CommonSetup; -import joptsimple.OptionSet; - import com.google.common.util.concurrent.ThreadFactoryBuilder; import java.util.concurrent.Executors; @@ -72,7 +70,7 @@ protected void configUserThread() { @Override protected void launchApplication() { headlessApp = new BisqHeadlessApp(); - CommonSetup.setup(BisqHeadlessAppMain.this.headlessApp); + CommonSetup.setupUncaughtExceptionHandler(BisqHeadlessAppMain.this.headlessApp); UserThread.execute(this::onApplicationLaunched); } diff --git a/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java b/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java index 9bc34648d60..1fc0ae69da1 100644 --- a/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java +++ b/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java @@ -62,7 +62,7 @@ protected void configUserThread() { @Override protected void launchApplication() { headlessApp = new BisqDaemon(); - CommonSetup.setup(BisqDaemonMain.this.headlessApp); + CommonSetup.setupUncaughtExceptionHandler(BisqDaemonMain.this.headlessApp); UserThread.execute(this::onApplicationLaunched); } diff --git a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java index d02c6e11c65..a724663fa11 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java @@ -78,7 +78,7 @@ protected void launchApplication() { BisqAppMain.this.application = (BisqApp) application; // Necessary to do the setup at this point to prevent Bouncy Castle errors - CommonSetup.setup(BisqAppMain.this.application); + CommonSetup.setupUncaughtExceptionHandler(BisqAppMain.this.application); // Map to user thread! UserThread.execute(this::onApplicationLaunched); }); diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index e5d85573aab..f61e6e36fc2 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -50,7 +50,7 @@ protected void doExecute() { super.doExecute(); checkMemory(config, this); - CommonSetup.setup(this); + CommonSetup.setupUncaughtExceptionHandler(this); keepRunning(); } diff --git a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java index ffa655d2dc6..146d07583c2 100644 --- a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java +++ b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java @@ -24,8 +24,6 @@ import bisq.common.app.AppModule; import bisq.common.setup.CommonSetup; -import joptsimple.OptionSet; - import lombok.extern.slf4j.Slf4j; @Slf4j @@ -47,7 +45,7 @@ protected void doExecute() { super.doExecute(); checkMemory(config, this); - CommonSetup.setup(this); + CommonSetup.setupUncaughtExceptionHandler(this); keepRunning(); } From 9232a5765bba727300bf299b3431198fb21eab58 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:06:51 -0500 Subject: [PATCH 05/24] Improve handling of UncaughtExceptionHandler --- .../java/bisq/core/app/BisqExecutable.java | 20 ++++++++++++++++++- .../bisq/core/app/BisqHeadlessAppMain.java | 7 +++++-- .../app/misc/ExecutableForAppWithP2p.java | 16 +-------------- .../java/bisq/daemon/app/BisqDaemonMain.java | 3 +-- .../java/bisq/desktop/app/BisqAppMain.java | 10 ++++++---- .../main/java/bisq/seednode/SeedNodeMain.java | 2 -- .../java/bisq/statistics/StatisticsMain.java | 2 -- 7 files changed, 32 insertions(+), 28 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 448219743f5..5ca31cf211f 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -40,6 +40,7 @@ import bisq.common.proto.persistable.PersistedDataHost; import bisq.common.setup.CommonSetup; import bisq.common.setup.GracefulShutDownHandler; +import bisq.common.setup.UncaughtExceptionHandler; import bisq.common.util.Utilities; import com.google.inject.Guice; @@ -56,7 +57,7 @@ import sun.misc.Signal; @Slf4j -public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener { +public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener, UncaughtExceptionHandler { private static final int EXIT_SUCCESS = 0; private static final int EXIT_FAILURE = 1; @@ -139,6 +140,10 @@ protected void addCapabilities() { // Headless versions can call inside launchApplication the onApplicationLaunched() manually protected void onApplicationLaunched() { + // As the handler method might be overwritten by subclasses and they use the application as handler + // we need to setup the handler after the application is created. + CommonSetup.setupUncaughtExceptionHandler(this); + setupGuice(); startApplication(); } @@ -264,6 +269,19 @@ public void gracefulShutDown(ResultHandler resultHandler) { } } + + /////////////////////////////////////////////////////////////////////////////////////////// + // UncaughtExceptionHandler implementation + /////////////////////////////////////////////////////////////////////////////////////////// + + @Override + public void handleUncaughtException(Throwable throwable, boolean doShutDown) { + log.error(throwable.toString()); + + if (doShutDown) + gracefulShutDown(() -> log.info("gracefulShutDown complete")); + } + /** * Returns the well-known "user data directory" for the current operating system. */ diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java b/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java index 4bd829f9a69..6a867d875b9 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessAppMain.java @@ -20,7 +20,6 @@ import bisq.common.UserThread; import bisq.common.app.AppModule; import bisq.common.app.Version; -import bisq.common.setup.CommonSetup; import com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -70,7 +69,6 @@ protected void configUserThread() { @Override protected void launchApplication() { headlessApp = new BisqHeadlessApp(); - CommonSetup.setupUncaughtExceptionHandler(BisqHeadlessAppMain.this.headlessApp); UserThread.execute(this::onApplicationLaunched); } @@ -81,6 +79,11 @@ protected void onApplicationLaunched() { headlessApp.setGracefulShutDownHandler(this); } + @Override + public void handleUncaughtException(Throwable throwable, boolean doShutDown) { + headlessApp.handleUncaughtException(throwable, doShutDown); + } + @Override public void onSetupComplete() { log.info("onSetupComplete"); diff --git a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java index b31875323aa..4e6f7619c72 100644 --- a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java +++ b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java @@ -33,7 +33,6 @@ import bisq.common.config.Config; import bisq.common.handlers.ResultHandler; import bisq.common.setup.GracefulShutDownHandler; -import bisq.common.setup.UncaughtExceptionHandler; import bisq.common.util.Profiler; import bisq.common.util.RestartUtil; @@ -55,7 +54,7 @@ import lombok.extern.slf4j.Slf4j; @Slf4j -public abstract class ExecutableForAppWithP2p extends BisqExecutable implements UncaughtExceptionHandler { +public abstract class ExecutableForAppWithP2p extends BisqExecutable { private static final long CHECK_MEMORY_PERIOD_SEC = 300; private static final long CHECK_SHUTDOWN_SEC = TimeUnit.HOURS.toSeconds(1); private static final long SHUTDOWN_INTERVAL = TimeUnit.HOURS.toMillis(24); @@ -177,19 +176,6 @@ public void startShutDownInterval(GracefulShutDownHandler gracefulShutDownHandle }, TimeUnit.HOURS.toSeconds(2)); } - - /////////////////////////////////////////////////////////////////////////////////////////// - // UncaughtExceptionHandler implementation - /////////////////////////////////////////////////////////////////////////////////////////// - - @Override - public void handleUncaughtException(Throwable throwable, boolean doShutDown) { - log.error(throwable.toString()); - - if (doShutDown) - gracefulShutDown(() -> log.info("gracefulShutDown complete")); - } - @SuppressWarnings("InfiniteLoopStatement") protected void keepRunning() { while (true) { diff --git a/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java b/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java index 1fc0ae69da1..a3bd88e1a03 100644 --- a/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java +++ b/daemon/src/main/java/bisq/daemon/app/BisqDaemonMain.java @@ -24,7 +24,6 @@ import bisq.common.UserThread; import bisq.common.app.AppModule; import bisq.common.handlers.ResultHandler; -import bisq.common.setup.CommonSetup; import com.google.common.util.concurrent.ThreadFactoryBuilder; @@ -62,7 +61,6 @@ protected void configUserThread() { @Override protected void launchApplication() { headlessApp = new BisqDaemon(); - CommonSetup.setupUncaughtExceptionHandler(BisqDaemonMain.this.headlessApp); UserThread.execute(this::onApplicationLaunched); } @@ -73,6 +71,7 @@ protected void onApplicationLaunched() { headlessApp.setGracefulShutDownHandler(this); } + ///////////////////////////////////////////////////////////////////////////////////// // We continue with a series of synchronous execution tasks ///////////////////////////////////////////////////////////////////////////////////// diff --git a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java index a724663fa11..a307a2e6ead 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java @@ -27,7 +27,6 @@ import bisq.common.app.AppModule; import bisq.common.app.Version; import bisq.common.proto.persistable.PersistedDataHost; -import bisq.common.setup.CommonSetup; import com.google.inject.Injector; @@ -76,9 +75,6 @@ protected void configUserThread() { protected void launchApplication() { BisqApp.setAppLaunchedHandler(application -> { BisqAppMain.this.application = (BisqApp) application; - - // Necessary to do the setup at this point to prevent Bouncy Castle errors - CommonSetup.setupUncaughtExceptionHandler(BisqAppMain.this.application); // Map to user thread! UserThread.execute(this::onApplicationLaunched); }); @@ -96,6 +92,12 @@ protected void onApplicationLaunched() { application.setGracefulShutDownHandler(this); } + @Override + public void handleUncaughtException(Throwable throwable, boolean doShutDown) { + application.handleUncaughtException(throwable, doShutDown); + } + + /////////////////////////////////////////////////////////////////////////////////////////// // We continue with a series of synchronous execution tasks /////////////////////////////////////////////////////////////////////////////////////////// diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index f61e6e36fc2..5d0ca61b391 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -27,7 +27,6 @@ import bisq.common.app.AppModule; import bisq.common.app.Capabilities; import bisq.common.app.Capability; -import bisq.common.setup.CommonSetup; import lombok.extern.slf4j.Slf4j; @@ -50,7 +49,6 @@ protected void doExecute() { super.doExecute(); checkMemory(config, this); - CommonSetup.setupUncaughtExceptionHandler(this); keepRunning(); } diff --git a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java index 146d07583c2..a57ff64afb8 100644 --- a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java +++ b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java @@ -22,7 +22,6 @@ import bisq.common.UserThread; import bisq.common.app.AppModule; -import bisq.common.setup.CommonSetup; import lombok.extern.slf4j.Slf4j; @@ -45,7 +44,6 @@ protected void doExecute() { super.doExecute(); checkMemory(config, this); - CommonSetup.setupUncaughtExceptionHandler(this); keepRunning(); } From 9d12bf7d521161fe165312a84bf1ff386695084f Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:10:44 -0500 Subject: [PATCH 06/24] Refactor: Move sig int handlers to CommonSetup --- .../java/bisq/common/setup/CommonSetup.java | 19 ++++++++++++++++++- .../java/bisq/core/app/BisqExecutable.java | 16 +--------------- .../java/bisq/desktop/app/BisqAppMain.java | 2 +- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index ac2a95b0036..50a8c742f67 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -32,12 +32,29 @@ import lombok.extern.slf4j.Slf4j; + + +import sun.misc.Signal; + @Slf4j public class CommonSetup { - public static void setup(Config config) { + public static void setup(Config config, GracefulShutDownHandler gracefulShutDownHandler) { AsciiLogo.showAsciiLogo(); setSystemProperties(); + setupSigIntHandlers(gracefulShutDownHandler); + } + + protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDownHandler) { + Signal.handle(new Signal("INT"), signal -> { + gracefulShutDownHandler.gracefulShutDown(() -> { + }); + }); + + Signal.handle(new Signal("TERM"), signal -> { + gracefulShutDownHandler.gracefulShutDown(() -> { + }); + }); } public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) { diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 5ca31cf211f..251a1ceccc8 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -52,10 +52,6 @@ import lombok.extern.slf4j.Slf4j; - - -import sun.misc.Signal; - @Slf4j public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSetup.BisqSetupListener, UncaughtExceptionHandler { @@ -104,22 +100,12 @@ public void execute(String[] args) { /////////////////////////////////////////////////////////////////////////////////////////// protected void doExecute() { - CommonSetup.setup(config); + CommonSetup.setup(config, this); CoreSetup.setup(config); configUserThread(); addCapabilities(); - Signal.handle(new Signal("INT"), signal -> { - gracefulShutDown(() -> { - }); - }); - - Signal.handle(new Signal("TERM"), signal -> { - gracefulShutDown(() -> { - }); - }); - // If application is JavaFX application we need to wait until it is initialized launchApplication(); } diff --git a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java index a307a2e6ead..9590c69d42a 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java @@ -46,7 +46,7 @@ public BisqAppMain() { super("Bisq Desktop", "bisq-desktop", DEFAULT_APP_NAME, Version.VERSION); } - public static void main(String[] args) throws Exception { + public static void main(String[] args) { // For some reason the JavaFX launch process results in us losing the thread // context class loader: reset it. In order to work around a bug in JavaFX 8u25 // and below, you must include the following code as the first line of your From b927f9719eeba4e9469f6e93cc2f2931b230b4ed Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:11:29 -0500 Subject: [PATCH 07/24] Refactor: Move DevEnv setup to CommonSetup --- common/src/main/java/bisq/common/setup/CommonSetup.java | 3 +++ core/src/main/java/bisq/core/app/BisqExecutable.java | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 50a8c742f67..8684e985ac1 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -19,6 +19,7 @@ import bisq.common.UserThread; import bisq.common.app.AsciiLogo; +import bisq.common.app.DevEnv; import bisq.common.config.Config; import bisq.common.crypto.CryptoUtils; import bisq.common.crypto.LimitedKeyStrengthException; @@ -43,6 +44,8 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown AsciiLogo.showAsciiLogo(); setSystemProperties(); setupSigIntHandlers(gracefulShutDownHandler); + DevEnv.setDevMode(config.useDevMode); + DevEnv.setDaoActivated(config.daoActivated); } protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDownHandler) { diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 251a1ceccc8..64380b184c8 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -152,15 +152,9 @@ protected Injector getInjector() { } protected void applyInjector() { - setupDevEnv(); - setupPersistedDataHosts(injector); } - protected void setupDevEnv() { - DevEnv.setDevMode(config.useDevMode); - DevEnv.setDaoActivated(config.daoActivated); - } protected void setupPersistedDataHosts(Injector injector) { try { From 516da22a09dd2e8bfbdec29f79856c1061b0a871 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:12:20 -0500 Subject: [PATCH 08/24] Refactor: Add setup method in DevEnv --- common/src/main/java/bisq/common/app/DevEnv.java | 7 +++++++ common/src/main/java/bisq/common/setup/CommonSetup.java | 3 +-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/bisq/common/app/DevEnv.java b/common/src/main/java/bisq/common/app/DevEnv.java index ca1cb607f34..9bf852d97bf 100644 --- a/common/src/main/java/bisq/common/app/DevEnv.java +++ b/common/src/main/java/bisq/common/app/DevEnv.java @@ -17,6 +17,8 @@ package bisq.common.app; +import bisq.common.config.Config; + import lombok.extern.slf4j.Slf4j; @Slf4j @@ -30,6 +32,11 @@ public class DevEnv { public static final String DEV_PRIVILEGE_PUB_KEY = "027a381b5333a56e1cc3d90d3a7d07f26509adf7029ed06fc997c656621f8da1ee"; public static final String DEV_PRIVILEGE_PRIV_KEY = "6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a"; + public static void setup(Config config) { + DevEnv.setDevMode(config.useDevMode); + DevEnv.setDaoActivated(config.daoActivated); + } + // If set to true we ignore several UI behavior like confirmation popups as well dummy accounts are created and // offers are filled with default values. Intended to make dev testing faster. private static boolean devMode = false; diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 8684e985ac1..fbcca2deeb3 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -44,8 +44,7 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown AsciiLogo.showAsciiLogo(); setSystemProperties(); setupSigIntHandlers(gracefulShutDownHandler); - DevEnv.setDevMode(config.useDevMode); - DevEnv.setDaoActivated(config.daoActivated); + DevEnv.setup(config); } protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDownHandler) { From aa7315b32d1a4121e4d1ad2e24502367faa84238 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:16:32 -0500 Subject: [PATCH 09/24] Refactor: Rename onUiReadyHandler to onApplicationStartedHandler --- desktop/src/main/java/bisq/desktop/app/BisqApp.java | 4 ++-- desktop/src/main/java/bisq/desktop/main/MainView.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/desktop/src/main/java/bisq/desktop/app/BisqApp.java b/desktop/src/main/java/bisq/desktop/app/BisqApp.java index c595daf1383..8ddc2ffef38 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqApp.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqApp.java @@ -129,10 +129,10 @@ public void start(Stage stage) { appLaunchedHandler.accept(this); } - public void startApplication(Runnable onUiReadyHandler) { + public void startApplication(Runnable onApplicationStartedHandler) { try { MainView mainView = loadMainView(injector); - mainView.setOnUiReadyHandler(onUiReadyHandler); + mainView.setOnApplicationStartedHandler(onApplicationStartedHandler); scene = createAndConfigScene(mainView, injector); setupStage(scene); diff --git a/desktop/src/main/java/bisq/desktop/main/MainView.java b/desktop/src/main/java/bisq/desktop/main/MainView.java index 0784ff10853..2af3ad2db8e 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainView.java +++ b/desktop/src/main/java/bisq/desktop/main/MainView.java @@ -117,7 +117,7 @@ public class MainView extends InitializableView private final static int SHOW_TOR_SETTINGS_DELAY_SEC = 90; private Label versionLabel; @Setter - private Runnable onUiReadyHandler; + private Runnable onApplicationStartedHandler; public static StackPane getRootContainer() { return MainView.rootContainer; @@ -405,7 +405,7 @@ protected Tooltip computeValue() { daoStateMonitoringService.addListener(this); // Delay a bit to give time for rendering the splash screen - UserThread.execute(() -> onUiReadyHandler.run()); + UserThread.execute(() -> onApplicationStartedHandler.run()); } /////////////////////////////////////////////////////////////////////////////////////////// From 4f9a6ea436f74252dab4a8fbbc559b493512e753 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:17:36 -0500 Subject: [PATCH 10/24] Refactor: Move periodic printSystemLoad to commonSetup --- common/src/main/java/bisq/common/setup/CommonSetup.java | 4 ++++ desktop/src/main/java/bisq/desktop/app/BisqApp.java | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index fbcca2deeb3..79e11f5975c 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -23,6 +23,7 @@ import bisq.common.config.Config; import bisq.common.crypto.CryptoUtils; import bisq.common.crypto.LimitedKeyStrengthException; +import bisq.common.util.Profiler; import bisq.common.util.Utilities; import org.bitcoinj.store.BlockStoreException; @@ -31,6 +32,8 @@ import java.security.NoSuchAlgorithmException; +import java.util.concurrent.TimeUnit; + import lombok.extern.slf4j.Slf4j; @@ -45,6 +48,7 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown setSystemProperties(); setupSigIntHandlers(gracefulShutDownHandler); DevEnv.setup(config); + UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), 10, TimeUnit.MINUTES); } protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDownHandler) { diff --git a/desktop/src/main/java/bisq/desktop/app/BisqApp.java b/desktop/src/main/java/bisq/desktop/app/BisqApp.java index 8ddc2ffef38..8520a2bc7f4 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqApp.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqApp.java @@ -41,13 +41,11 @@ import bisq.core.offer.OpenOfferManager; import bisq.core.user.Preferences; -import bisq.common.UserThread; import bisq.common.app.DevEnv; import bisq.common.app.Log; import bisq.common.config.Config; import bisq.common.setup.GracefulShutDownHandler; import bisq.common.setup.UncaughtExceptionHandler; -import bisq.common.util.Profiler; import bisq.common.util.Utilities; import com.google.inject.Injector; @@ -74,7 +72,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Objects; -import java.util.concurrent.TimeUnit; import java.util.function.Consumer; import org.slf4j.LoggerFactory; @@ -137,8 +134,6 @@ public void startApplication(Runnable onApplicationStartedHandler) { setupStage(scene); injector.getInstance(AvoidStandbyModeService.class).init(); - - UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES); } catch (Throwable throwable) { log.error("Error during app init", throwable); handleUncaughtException(throwable, false); From bb99eef059ac545931c2ceb0c93b900baec5c88d Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:26:42 -0500 Subject: [PATCH 11/24] Refactor: Move AvoidStandbyModeService from BisqApp to BisqExecutable.setupAvoidStandbyMode --- core/src/main/java/bisq/core/app/BisqExecutable.java | 4 ++++ desktop/src/main/java/bisq/desktop/app/BisqApp.java | 4 ---- desktop/src/main/java/bisq/desktop/app/BisqAppMain.java | 6 ++++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 64380b184c8..0d65b92dd95 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -131,6 +131,7 @@ protected void onApplicationLaunched() { CommonSetup.setupUncaughtExceptionHandler(this); setupGuice(); + setupAvoidStandbyMode(); startApplication(); } @@ -170,6 +171,9 @@ protected void setupPersistedDataHosts(Injector injector) { } } + protected void setupAvoidStandbyMode() { + } + protected abstract void startApplication(); // Once the application is ready we get that callback and we start the setup diff --git a/desktop/src/main/java/bisq/desktop/app/BisqApp.java b/desktop/src/main/java/bisq/desktop/app/BisqApp.java index 8520a2bc7f4..d5c0ac46b2a 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqApp.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqApp.java @@ -32,7 +32,6 @@ import bisq.desktop.util.CssTheme; import bisq.desktop.util.ImageUtil; -import bisq.core.app.AvoidStandbyModeService; import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.WalletsManager; import bisq.core.dao.governance.voteresult.MissingDataRequestService; @@ -90,7 +89,6 @@ @Slf4j public class BisqApp extends Application implements UncaughtExceptionHandler { - private static final long LOG_MEMORY_PERIOD_MIN = 10; @Setter private static Consumer appLaunchedHandler; @Getter @@ -132,8 +130,6 @@ public void startApplication(Runnable onApplicationStartedHandler) { mainView.setOnApplicationStartedHandler(onApplicationStartedHandler); scene = createAndConfigScene(mainView, injector); setupStage(scene); - - injector.getInstance(AvoidStandbyModeService.class).init(); } catch (Throwable throwable) { log.error("Error during app init", throwable); handleUncaughtException(throwable, false); diff --git a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java index 9590c69d42a..e28d4a36812 100644 --- a/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java +++ b/desktop/src/main/java/bisq/desktop/app/BisqAppMain.java @@ -21,6 +21,7 @@ import bisq.desktop.common.view.guice.InjectorViewFactory; import bisq.desktop.setup.DesktopPersistedDataHost; +import bisq.core.app.AvoidStandbyModeService; import bisq.core.app.BisqExecutable; import bisq.common.UserThread; @@ -121,6 +122,11 @@ protected void setupPersistedDataHosts(Injector injector) { PersistedDataHost.apply(DesktopPersistedDataHost.getPersistedDataHosts(injector)); } + @Override + protected void setupAvoidStandbyMode() { + injector.getInstance(AvoidStandbyModeService.class).init(); + } + @Override protected void startApplication() { // We need to be in user thread! We mapped at launchApplication already. Once From 907fd66dc21919d6797624d4eac796d1e4ae2d52 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:27:09 -0500 Subject: [PATCH 12/24] Remove empty loop --- core/src/main/java/bisq/core/app/BisqSetup.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 8c6292705e7..6ce84167436 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -348,8 +348,6 @@ public void addBisqSetupListener(BisqSetupListener listener) { } public void start() { - UserThread.runPeriodically(() -> { - }, 1); maybeReSyncSPVChain(); maybeShowTac(this::step2); } From fe577b3651fb21ee800a1e0cf95737ad29e4d414 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:30:40 -0500 Subject: [PATCH 13/24] Remove checkCryptoSetup as not needed anymore --- .../main/java/bisq/core/app/BisqSetup.java | 36 ------------------- 1 file changed, 36 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 6ce84167436..5d00dac343b 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -65,10 +65,8 @@ import bisq.core.util.FormattingUtils; import bisq.core.util.coin.CoinFormatter; -import bisq.network.crypto.DecryptedDataTuple; import bisq.network.crypto.EncryptionService; import bisq.network.p2p.P2PService; -import bisq.network.p2p.peers.keepalive.messages.Ping; import bisq.network.p2p.storage.payload.PersistableNetworkPayload; import bisq.common.ClockWatcher; @@ -77,10 +75,7 @@ import bisq.common.app.DevEnv; import bisq.common.app.Log; import bisq.common.config.Config; -import bisq.common.crypto.CryptoException; import bisq.common.crypto.KeyRing; -import bisq.common.crypto.SealedAndSigned; -import bisq.common.proto.ProtobufferException; import bisq.common.util.InvalidVersionException; import bisq.common.util.Utilities; @@ -355,7 +350,6 @@ public void start() { private void step2() { torSetup.cleanupTorFiles(); readMapsFromResources(this::step3); - checkCryptoSetup(); checkForCorrectOSArchitecture(); checkOSXVersion(); checkIfRunningOnQubesOS(); @@ -492,36 +486,6 @@ private void readMapsFromResources(Runnable nextStep) { }); } - private void checkCryptoSetup() { - // We want to test if the client is compiled with the correct crypto provider (BountyCastle) - // and if the unlimited Strength for cryptographic keys is set. - // If users compile themselves they might miss that step and then would get an exception in the trade. - // To avoid that we add a sample encryption and signing here at startup to see if it doesn't cause an exception. - // See: https://github.com/bisq-network/exchange/blob/master/doc/build.md#7-enable-unlimited-strength-for-cryptographic-keys - new Thread(() -> { - try { - // just use any simple dummy msg - Ping payload = new Ping(1, 1); - SealedAndSigned sealedAndSigned = EncryptionService.encryptHybridWithSignature(payload, - keyRing.getSignatureKeyPair(), keyRing.getPubKeyRing().getEncryptionPubKey()); - DecryptedDataTuple tuple = encryptionService.decryptHybridWithSignature(sealedAndSigned, keyRing.getEncryptionKeyPair().getPrivate()); - if (tuple.getNetworkEnvelope() instanceof Ping && - ((Ping) tuple.getNetworkEnvelope()).getNonce() == payload.getNonce() && - ((Ping) tuple.getNetworkEnvelope()).getLastRoundTripTime() == payload.getLastRoundTripTime()) { - log.debug("Crypto test succeeded"); - } else { - throw new CryptoException("Payload not correct after decryption"); - } - } catch (CryptoException | ProtobufferException e) { - e.printStackTrace(); - String msg = Res.get("popup.warning.cryptoTestFailed", e.getMessage()); - log.error(msg); - if (cryptoSetupFailedHandler != null) - cryptoSetupFailedHandler.accept(msg); - } - }, "checkCryptoThread").start(); - } - private void startP2pNetworkAndWallet(Runnable nextStep) { ChangeListener walletInitializedListener = (observable, oldValue, newValue) -> { // TODO that seems to be called too often if Tor takes longer to start up... From 49866508c161fdf1c7190a2c7a0c4ccc251387e5 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:31:37 -0500 Subject: [PATCH 14/24] Remove checkCryptoPolicySetup as not needed anymore --- .../main/java/bisq/common/crypto/CryptoUtils.java | 10 ---------- .../main/java/bisq/common/setup/CommonSetup.java | 14 -------------- 2 files changed, 24 deletions(-) diff --git a/common/src/main/java/bisq/common/crypto/CryptoUtils.java b/common/src/main/java/bisq/common/crypto/CryptoUtils.java index 6d1a5c71aa0..83ab4317f43 100644 --- a/common/src/main/java/bisq/common/crypto/CryptoUtils.java +++ b/common/src/main/java/bisq/common/crypto/CryptoUtils.java @@ -17,9 +17,6 @@ package bisq.common.crypto; -import javax.crypto.Cipher; - -import java.security.NoSuchAlgorithmException; import java.security.PublicKey; import java.security.SecureRandom; import java.security.spec.X509EncodedKeySpec; @@ -40,11 +37,4 @@ public static byte[] getRandomBytes(int size) { new SecureRandom().nextBytes(bytes); return bytes; } - - public static void checkCryptoPolicySetup() throws NoSuchAlgorithmException, LimitedKeyStrengthException { - if (Cipher.getMaxAllowedKeyLength("AES") > 128) - log.debug("Congratulations, you have unlimited key length support!"); - else - throw new LimitedKeyStrengthException(); - } } diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 79e11f5975c..b7ac6ec42f0 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -21,8 +21,6 @@ import bisq.common.app.AsciiLogo; import bisq.common.app.DevEnv; import bisq.common.config.Config; -import bisq.common.crypto.CryptoUtils; -import bisq.common.crypto.LimitedKeyStrengthException; import bisq.common.util.Profiler; import bisq.common.util.Utilities; @@ -30,8 +28,6 @@ import org.apache.commons.lang3.exception.ExceptionUtils; -import java.security.NoSuchAlgorithmException; - import java.util.concurrent.TimeUnit; import lombok.extern.slf4j.Slf4j; @@ -89,14 +85,4 @@ protected static void setSystemProperties() { if (Utilities.isLinux()) System.setProperty("prism.lcdtext", "false"); } - - //TODO not needed anymore - private static void checkCryptoPolicySetup(UncaughtExceptionHandler uncaughtExceptionHandler) { - try { - CryptoUtils.checkCryptoPolicySetup(); - } catch (NoSuchAlgorithmException | LimitedKeyStrengthException e) { - e.printStackTrace(); - UserThread.execute(() -> uncaughtExceptionHandler.handleUncaughtException(e, true)); - } - } } From 073f1630b1b8a18a0ec5e60c72c26eabbeef59cb Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:32:10 -0500 Subject: [PATCH 15/24] Remove Remove LimitedKeyStrengthException as not needed anymore --- .../crypto/LimitedKeyStrengthException.java | 24 ------------------- 1 file changed, 24 deletions(-) delete mode 100644 common/src/main/java/bisq/common/crypto/LimitedKeyStrengthException.java diff --git a/common/src/main/java/bisq/common/crypto/LimitedKeyStrengthException.java b/common/src/main/java/bisq/common/crypto/LimitedKeyStrengthException.java deleted file mode 100644 index 731130eeee0..00000000000 --- a/common/src/main/java/bisq/common/crypto/LimitedKeyStrengthException.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * This file is part of Bisq. - * - * Bisq is free software: you can redistribute it and/or modify it - * under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation, either version 3 of the License, or (at - * your option) any later version. - * - * Bisq is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public - * License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with Bisq. If not, see . - */ - -package bisq.common.crypto; - -public class LimitedKeyStrengthException extends Exception { - public LimitedKeyStrengthException() { - super("Default crypto policy has not been changed. Only weak keys with length 128 are allowed by the default policy."); - } -} From 51ce37ded972711f74eaa1ed65d2eed0abc80251 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:32:47 -0500 Subject: [PATCH 16/24] Refactor: Rearrange methods --- .../java/bisq/common/setup/CommonSetup.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index b7ac6ec42f0..2bd70aaa786 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -47,18 +47,6 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), 10, TimeUnit.MINUTES); } - protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDownHandler) { - Signal.handle(new Signal("INT"), signal -> { - gracefulShutDownHandler.gracefulShutDown(() -> { - }); - }); - - Signal.handle(new Signal("TERM"), signal -> { - gracefulShutDownHandler.gracefulShutDown(() -> { - }); - }); - } - public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) { Thread.UncaughtExceptionHandler handler = (thread, throwable) -> { // Might come from another thread @@ -85,4 +73,16 @@ protected static void setSystemProperties() { if (Utilities.isLinux()) System.setProperty("prism.lcdtext", "false"); } + + protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDownHandler) { + Signal.handle(new Signal("INT"), signal -> { + gracefulShutDownHandler.gracefulShutDown(() -> { + }); + }); + + Signal.handle(new Signal("TERM"), signal -> { + gracefulShutDownHandler.gracefulShutDown(() -> { + }); + }); + } } From a38f59a88af2f212a7820ab710487322d182a9b8 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:36:18 -0500 Subject: [PATCH 17/24] Refactor: Move common bases setup code to CommonSetup --- .../java/bisq/common/setup/CommonSetup.java | 35 ++++++++++++++++++- .../main/java/bisq/core/setup/CoreSetup.java | 29 --------------- 2 files changed, 34 insertions(+), 30 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index 2bd70aaa786..e6b4e9810c6 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -20,6 +20,8 @@ import bisq.common.UserThread; import bisq.common.app.AsciiLogo; import bisq.common.app.DevEnv; +import bisq.common.app.Log; +import bisq.common.app.Version; import bisq.common.config.Config; import bisq.common.util.Profiler; import bisq.common.util.Utilities; @@ -28,8 +30,14 @@ import org.apache.commons.lang3.exception.ExceptionUtils; +import java.net.URISyntaxException; + +import java.nio.file.Paths; + import java.util.concurrent.TimeUnit; +import ch.qos.logback.classic.Level; + import lombok.extern.slf4j.Slf4j; @@ -41,10 +49,16 @@ public class CommonSetup { public static void setup(Config config, GracefulShutDownHandler gracefulShutDownHandler) { AsciiLogo.showAsciiLogo(); + setupLog(config); + Version.setBaseCryptoNetworkId(config.baseCurrencyNetwork.ordinal()); + Version.printVersion(); + maybePrintPathOfCodeSource(); + UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), 10, TimeUnit.MINUTES); + setSystemProperties(); setupSigIntHandlers(gracefulShutDownHandler); + DevEnv.setup(config); - UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), 10, TimeUnit.MINUTES); } public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaughtExceptionHandler) { @@ -69,6 +83,14 @@ public static void setupUncaughtExceptionHandler(UncaughtExceptionHandler uncaug Thread.currentThread().setUncaughtExceptionHandler(handler); } + private static void setupLog(Config config) { + String logPath = Paths.get(config.appDataDir.getPath(), "bisq").toString(); + Log.setup(logPath); + log.info("Log files under: {}", logPath); + Utilities.printSysInfo(); + Log.setLevel(Level.toLevel(config.logLevel)); + } + protected static void setSystemProperties() { if (Utilities.isLinux()) System.setProperty("prism.lcdtext", "false"); @@ -85,4 +107,15 @@ protected static void setupSigIntHandlers(GracefulShutDownHandler gracefulShutDo }); }); } + + protected static void maybePrintPathOfCodeSource() { + try { + final String pathOfCodeSource = Utilities.getPathOfCodeSource(); + if (!pathOfCodeSource.endsWith("classes")) + log.info("Path to Bisq jar file: " + pathOfCodeSource); + } catch (URISyntaxException e) { + log.error(e.toString()); + e.printStackTrace(); + } + } } diff --git a/core/src/main/java/bisq/core/setup/CoreSetup.java b/core/src/main/java/bisq/core/setup/CoreSetup.java index 9265539af42..8f5eea38aab 100644 --- a/core/src/main/java/bisq/core/setup/CoreSetup.java +++ b/core/src/main/java/bisq/core/setup/CoreSetup.java @@ -20,16 +20,7 @@ import bisq.core.locale.CurrencyUtil; import bisq.core.locale.Res; -import bisq.common.app.Log; -import bisq.common.app.Version; import bisq.common.config.Config; -import bisq.common.util.Utilities; - -import java.net.URISyntaxException; - -import java.nio.file.Paths; - -import ch.qos.logback.classic.Level; import lombok.extern.slf4j.Slf4j; @@ -37,29 +28,9 @@ public class CoreSetup { public static void setup(Config config) { - setupLog(config); CoreNetworkCapabilities.setSupportedCapabilities(config); Res.setup(); CurrencyUtil.setup(); - - Version.setBaseCryptoNetworkId(config.baseCurrencyNetwork.ordinal()); - Version.printVersion(); - - try { - final String pathOfCodeSource = Utilities.getPathOfCodeSource(); - if (!pathOfCodeSource.endsWith("classes")) - log.info("Path to Bisq jar file: " + pathOfCodeSource); - } catch (URISyntaxException e) { - log.error(e.toString()); - e.printStackTrace(); - } } - private static void setupLog(Config config) { - String logPath = Paths.get(config.appDataDir.getPath(), "bisq").toString(); - Log.setup(logPath); - log.info("Log files under: {}", logPath); - Utilities.printSysInfo(); - Log.setLevel(Level.toLevel(config.logLevel)); - } } From c3e1ae691b1ae62dceb2d14460bf468fb61289f3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:39:13 -0500 Subject: [PATCH 18/24] Remove cryptoSetupFailedHandler --- core/src/main/java/bisq/core/app/BisqHeadlessApp.java | 1 - core/src/main/java/bisq/core/app/BisqSetup.java | 2 +- desktop/src/main/java/bisq/desktop/main/MainViewModel.java | 5 ----- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java index 03140f8dfad..16f6a5e2715 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java @@ -78,7 +78,6 @@ protected void setupHandlers() { log.info("onDisplayTacHandler: We accept the tacs automatically in headless mode"); acceptedHandler.run(); }); - bisqSetup.setCryptoSetupFailedHandler(msg -> log.error("onCryptoSetupFailedHandler: msg={}", msg)); bisqSetup.setDisplayTorNetworkSettingsHandler(show -> log.info("onDisplayTorNetworkSettingsHandler: show={}", show)); bisqSetup.setSpvFileCorruptedHandler(msg -> log.error("onSpvFileCorruptedHandler: msg={}", msg)); bisqSetup.setChainFileLockedExceptionHandler(msg -> log.error("onChainFileLockedExceptionHandler: msg={}", msg)); diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 5d00dac343b..43fd2631f88 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -191,7 +191,7 @@ default void onRequestWalletPassword() { private Consumer displayTacHandler; @Setter @Nullable - private Consumer cryptoSetupFailedHandler, chainFileLockedExceptionHandler, + private Consumer chainFileLockedExceptionHandler, spvFileCorruptedHandler, lockedUpFundsHandler, daoErrorMessageHandler, daoWarnMessageHandler, filterWarningHandler, displaySecurityRecommendationHandler, displayLocalhostHandler, wrongOSArchitectureHandler, displaySignedByArbitratorHandler, diff --git a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java index 95ea9fb148a..82741024ab7 100644 --- a/desktop/src/main/java/bisq/desktop/main/MainViewModel.java +++ b/desktop/src/main/java/bisq/desktop/main/MainViewModel.java @@ -303,11 +303,6 @@ private void setupHandlers() { tacWindow.onAction(acceptedHandler::run).show(); }, 1)); - bisqSetup.setCryptoSetupFailedHandler(msg -> UserThread.execute(() -> - new Popup().warning(msg) - .useShutDownButton() - .useReportBugButton() - .show())); bisqSetup.setDisplayTorNetworkSettingsHandler(show -> { if (show) { torNetworkSettingsWindow.show(); From 346ad517a1eac034b68c7c6ca9d8fe2c7e2cf270 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:43:11 -0500 Subject: [PATCH 19/24] Refactor: Move osUserDataDir method to Utilities, rename to getUserDataDir --- .../main/java/bisq/common/util/Utilities.java | 16 ++++++++++++++ .../java/bisq/core/app/BisqExecutable.java | 21 +------------------ 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/common/src/main/java/bisq/common/util/Utilities.java b/common/src/main/java/bisq/common/util/Utilities.java index d12c2d0a593..42e68020cf7 100644 --- a/common/src/main/java/bisq/common/util/Utilities.java +++ b/common/src/main/java/bisq/common/util/Utilities.java @@ -43,6 +43,8 @@ import java.net.URI; import java.net.URISyntaxException; +import java.nio.file.Paths; + import java.io.File; import java.io.IOException; @@ -198,6 +200,20 @@ public static String getOSVersion() { return System.getProperty("os.version").toLowerCase(Locale.US); } + /** + * Returns the well-known "user data directory" for the current operating system. + */ + public static File getUserDataDir() { + if (Utilities.isWindows()) + return new File(System.getenv("APPDATA")); + + if (Utilities.isOSX()) + return Paths.get(System.getProperty("user.home"), "Library", "Application Support").toFile(); + + // *nix + return Paths.get(System.getProperty("user.home"), ".local", "share").toFile(); + } + public static int getMinorVersion() throws InvalidVersionException { String version = getOSVersion(); String[] tokens = version.split("\\."); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 0d65b92dd95..2b47617ea7d 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -46,10 +46,6 @@ import com.google.inject.Guice; import com.google.inject.Injector; -import java.nio.file.Paths; - -import java.io.File; - import lombok.extern.slf4j.Slf4j; @Slf4j @@ -77,7 +73,7 @@ public BisqExecutable(String fullName, String scriptName, String appName, String public void execute(String[] args) { try { - config = new Config(appName, osUserDataDir(), args); + config = new Config(appName, Utilities.getUserDataDir(), args); if (config.helpRequested) { config.printHelp(System.out, new BisqHelpFormatter(fullName, scriptName, version)); System.exit(EXIT_SUCCESS); @@ -156,7 +152,6 @@ protected void applyInjector() { setupPersistedDataHosts(injector); } - protected void setupPersistedDataHosts(Injector injector) { try { PersistedDataHost.apply(CorePersistedDataHost.getPersistedDataHosts(injector)); @@ -265,18 +260,4 @@ public void handleUncaughtException(Throwable throwable, boolean doShutDown) { if (doShutDown) gracefulShutDown(() -> log.info("gracefulShutDown complete")); } - - /** - * Returns the well-known "user data directory" for the current operating system. - */ - private static File osUserDataDir() { - if (Utilities.isWindows()) - return new File(System.getenv("APPDATA")); - - if (Utilities.isOSX()) - return Paths.get(System.getProperty("user.home"), "Library", "Application Support").toFile(); - - // *nix - return Paths.get(System.getProperty("user.home"), ".local", "share").toFile(); - } } From 11383b9e84fb04147ef00f49edb03f7bb74ae1a3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 22:45:11 -0500 Subject: [PATCH 20/24] Refactor: Rename startAppSetup to runBisqSetup --- core/src/main/java/bisq/core/app/BisqExecutable.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index 2b47617ea7d..e8a2b886462 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -173,10 +173,10 @@ protected void setupAvoidStandbyMode() { // Once the application is ready we get that callback and we start the setup protected void onApplicationStarted() { - startAppSetup(); + runBisqSetup(); } - protected void startAppSetup() { + protected void runBisqSetup() { BisqSetup bisqSetup = injector.getInstance(BisqSetup.class); bisqSetup.addBisqSetupListener(this); bisqSetup.start(); From 6e7e975c0571c671949fbef855d6f802a1503260 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 23:03:11 -0500 Subject: [PATCH 21/24] Improve printSystemLoad --- .../main/java/bisq/common/setup/CommonSetup.java | 3 ++- .../src/main/java/bisq/common/util/Profiler.java | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/common/src/main/java/bisq/common/setup/CommonSetup.java b/common/src/main/java/bisq/common/setup/CommonSetup.java index e6b4e9810c6..997611e9997 100644 --- a/common/src/main/java/bisq/common/setup/CommonSetup.java +++ b/common/src/main/java/bisq/common/setup/CommonSetup.java @@ -53,7 +53,8 @@ public static void setup(Config config, GracefulShutDownHandler gracefulShutDown Version.setBaseCryptoNetworkId(config.baseCurrencyNetwork.ordinal()); Version.printVersion(); maybePrintPathOfCodeSource(); - UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), 10, TimeUnit.MINUTES); + Profiler.printSystemLoad(); + UserThread.runPeriodically(Profiler::printSystemLoad, 10, TimeUnit.MINUTES); setSystemProperties(); setupSigIntHandlers(gracefulShutDownHandler); diff --git a/common/src/main/java/bisq/common/util/Profiler.java b/common/src/main/java/bisq/common/util/Profiler.java index 3031bf0d803..8a60402df81 100644 --- a/common/src/main/java/bisq/common/util/Profiler.java +++ b/common/src/main/java/bisq/common/util/Profiler.java @@ -17,15 +17,18 @@ package bisq.common.util; -import org.slf4j.Logger; +import lombok.extern.slf4j.Slf4j; +@Slf4j public class Profiler { - public static void printSystemLoad(Logger log) { - log.info(printSystemLoadString()); - } + public static void printSystemLoad() { + Runtime runtime = Runtime.getRuntime(); + long free = runtime.freeMemory() / 1024 / 1024; + long total = runtime.totalMemory() / 1024 / 1024; + long used = total - free; - public static String printSystemLoadString() { - return "System load: Memory (MB): " + getUsedMemoryInMB() + " / No. of threads: " + Thread.activeCount(); + log.info("System report: Used memory: {} MB; Free memory: {} MB; Total memory: {} MB; No. of threads: {}", + used, free, total, Thread.activeCount()); } public static long getUsedMemoryInMB() { From 1b1888673ced5ea07feb785c1e2103670dfb295e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Wed, 30 Sep 2020 23:12:06 -0500 Subject: [PATCH 22/24] Refactor: Move handler code to domain classes --- .../main/java/bisq/core/app/BisqSetup.java | 112 +----------------- .../java/bisq/core/app/WalletAppSetup.java | 80 +++++++++++++ .../java/bisq/core/filter/FilterManager.java | 31 +++++ 3 files changed, 114 insertions(+), 109 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqSetup.java b/core/src/main/java/bisq/core/app/BisqSetup.java index 43fd2631f88..4bafdc0058d 100644 --- a/core/src/main/java/bisq/core/app/BisqSetup.java +++ b/core/src/main/java/bisq/core/app/BisqSetup.java @@ -65,7 +65,6 @@ import bisq.core.util.FormattingUtils; import bisq.core.util.coin.CoinFormatter; -import bisq.network.crypto.EncryptionService; import bisq.network.p2p.P2PService; import bisq.network.p2p.storage.payload.PersistableNetworkPayload; @@ -75,12 +74,10 @@ import bisq.common.app.DevEnv; import bisq.common.app.Log; import bisq.common.config.Config; -import bisq.common.crypto.KeyRing; import bisq.common.util.InvalidVersionException; import bisq.common.util.Utilities; import org.bitcoinj.core.Coin; -import org.bitcoinj.core.RejectMessage; import javax.inject.Inject; import javax.inject.Named; @@ -169,8 +166,6 @@ default void onRequestWalletPassword() { private final FeeService feeService; private final DaoSetup daoSetup; private final UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService; - private final EncryptionService encryptionService; - private final KeyRing keyRing; private final Config config; private final AccountAgeWitnessService accountAgeWitnessService; private final SignedWitnessService signedWitnessService; @@ -238,7 +233,7 @@ default void onRequestWalletPassword() { private boolean allBasicServicesInitialized; @SuppressWarnings("FieldCanBeLocal") private MonadicBinding p2pNetworkAndWalletInitialized; - private List bisqSetupListeners = new ArrayList<>(); + private final List bisqSetupListeners = new ArrayList<>(); @Inject public BisqSetup(P2PNetworkSetup p2PNetworkSetup, @@ -269,8 +264,6 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup, FeeService feeService, DaoSetup daoSetup, UnconfirmedBsqChangeOutputListService unconfirmedBsqChangeOutputListService, - EncryptionService encryptionService, - KeyRing keyRing, Config config, AccountAgeWitnessService accountAgeWitnessService, SignedWitnessService signedWitnessService, @@ -315,8 +308,6 @@ public BisqSetup(P2PNetworkSetup p2PNetworkSetup, this.feeService = feeService; this.daoSetup = daoSetup; this.unconfirmedBsqChangeOutputListService = unconfirmedBsqChangeOutputListService; - this.encryptionService = encryptionService; - this.keyRing = keyRing; this.config = config; this.accountAgeWitnessService = accountAgeWitnessService; this.signedWitnessService = signedWitnessService; @@ -679,79 +670,7 @@ private void initDomainServices() { balances.onAllServicesInitialized(); - walletAppSetup.getRejectedTxException().addListener((observable, oldValue, newValue) -> { - if (newValue == null || newValue.getTxId() == null) { - return; - } - - RejectMessage rejectMessage = newValue.getRejectMessage(); - log.warn("We received reject message: {}", rejectMessage); - - // TODO: Find out which reject messages are critical and which not. - // We got a report where a "tx already known" message caused a failed trade but the deposit tx was valid. - // To avoid such false positives we only handle reject messages which we consider clearly critical. - - switch (rejectMessage.getReasonCode()) { - case OBSOLETE: - case DUPLICATE: - case NONSTANDARD: - case CHECKPOINT: - case OTHER: - // We ignore those cases to avoid that not critical reject messages trigger a failed trade. - log.warn("We ignore that reject message as it is likely not critical."); - break; - case MALFORMED: - case INVALID: - case DUST: - case INSUFFICIENTFEE: - // We delay as we might get the rejected tx error before we have completed the create offer protocol - log.warn("We handle that reject message as it is likely critical."); - UserThread.runAfter(() -> { - String txId = newValue.getTxId(); - openOfferManager.getObservableList().stream() - .filter(openOffer -> txId.equals(openOffer.getOffer().getOfferFeePaymentTxId())) - .forEach(openOffer -> { - // We delay to avoid concurrent modification exceptions - UserThread.runAfter(() -> { - openOffer.getOffer().setErrorMessage(newValue.getMessage()); - if (rejectedTxErrorMessageHandler != null) { - rejectedTxErrorMessageHandler.accept(Res.get("popup.warning.openOffer.makerFeeTxRejected", openOffer.getId(), txId)); - } - openOfferManager.removeOpenOffer(openOffer, () -> { - log.warn("We removed an open offer because the maker fee was rejected by the Bitcoin " + - "network. OfferId={}, txId={}", openOffer.getShortId(), txId); - }, log::warn); - }, 1); - }); - - tradeManager.getTradableList().stream() - .filter(trade -> trade.getOffer() != null) - .forEach(trade -> { - String details = null; - if (txId.equals(trade.getDepositTxId())) { - details = Res.get("popup.warning.trade.txRejected.deposit"); - } - if (txId.equals(trade.getOffer().getOfferFeePaymentTxId()) || txId.equals(trade.getTakerFeeTxId())) { - details = Res.get("popup.warning.trade.txRejected.tradeFee"); - } - - if (details != null) { - // We delay to avoid concurrent modification exceptions - String finalDetails = details; - UserThread.runAfter(() -> { - trade.setErrorMessage(newValue.getMessage()); - if (rejectedTxErrorMessageHandler != null) { - rejectedTxErrorMessageHandler.accept(Res.get("popup.warning.trade.txRejected", - finalDetails, trade.getShortId(), txId)); - } - tradeManager.addTradeToFailedTrades(trade); - }, 1); - } - }); - }, 3); - } - }); - + walletAppSetup.setRejectedTxErrorMessageHandler(rejectedTxErrorMessageHandler, openOfferManager, tradeManager); arbitratorManager.onAllServicesInitialized(); mediatorManager.onAllServicesInitialized(); @@ -788,32 +707,7 @@ private void initDomainServices() { priceFeedService.setCurrencyCodeOnInit(); filterManager.onAllServicesInitialized(); - filterManager.addListener(filter -> { - if (filter != null && filterWarningHandler != null) { - if (filter.getSeedNodes() != null && !filter.getSeedNodes().isEmpty()) { - log.info(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))); - // Let's keep that more silent. Might be used in case a node is unstable and we don't want to confuse users. - // filterWarningHandler.accept(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))); - } - - if (filter.getPriceRelayNodes() != null && !filter.getPriceRelayNodes().isEmpty()) { - log.info(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))); - // Let's keep that more silent. Might be used in case a node is unstable and we don't want to confuse users. - // filterWarningHandler.accept(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))); - } - - if (filterManager.requireUpdateToNewVersionForTrading()) { - filterWarningHandler.accept(Res.get("popup.warning.mandatoryUpdate.trading")); - } - - if (filterManager.requireUpdateToNewVersionForDAO()) { - filterWarningHandler.accept(Res.get("popup.warning.mandatoryUpdate.dao")); - } - if (filter.isDisableDao()) { - filterWarningHandler.accept(Res.get("popup.warning.disable.dao")); - } - } - }); + filterManager.setFilterWarningHandler(filterWarningHandler); voteResultService.getVoteResultExceptions().addListener((ListChangeListener) c -> { c.next(); diff --git a/core/src/main/java/bisq/core/app/WalletAppSetup.java b/core/src/main/java/bisq/core/app/WalletAppSetup.java index 3627b3be99d..8e98601e0e9 100644 --- a/core/src/main/java/bisq/core/app/WalletAppSetup.java +++ b/core/src/main/java/bisq/core/app/WalletAppSetup.java @@ -22,11 +22,15 @@ import bisq.core.btc.setup.WalletsSetup; import bisq.core.btc.wallet.WalletsManager; import bisq.core.locale.Res; +import bisq.core.offer.OpenOfferManager; +import bisq.core.trade.TradeManager; import bisq.core.user.Preferences; import bisq.core.util.FormattingUtils; +import bisq.common.UserThread; import bisq.common.config.Config; +import org.bitcoinj.core.RejectMessage; import org.bitcoinj.core.VersionMessage; import org.bitcoinj.store.BlockStoreException; import org.bitcoinj.store.ChainFileLockedException; @@ -183,6 +187,82 @@ void init(@Nullable Consumer chainFileLockedExceptionHandler, }); } + void setRejectedTxErrorMessageHandler(Consumer rejectedTxErrorMessageHandler, + OpenOfferManager openOfferManager, + TradeManager tradeManager) { + getRejectedTxException().addListener((observable, oldValue, newValue) -> { + if (newValue == null || newValue.getTxId() == null) { + return; + } + + RejectMessage rejectMessage = newValue.getRejectMessage(); + log.warn("We received reject message: {}", rejectMessage); + + // TODO: Find out which reject messages are critical and which not. + // We got a report where a "tx already known" message caused a failed trade but the deposit tx was valid. + // To avoid such false positives we only handle reject messages which we consider clearly critical. + + switch (rejectMessage.getReasonCode()) { + case OBSOLETE: + case DUPLICATE: + case NONSTANDARD: + case CHECKPOINT: + case OTHER: + // We ignore those cases to avoid that not critical reject messages trigger a failed trade. + log.warn("We ignore that reject message as it is likely not critical."); + break; + case MALFORMED: + case INVALID: + case DUST: + case INSUFFICIENTFEE: + // We delay as we might get the rejected tx error before we have completed the create offer protocol + log.warn("We handle that reject message as it is likely critical."); + UserThread.runAfter(() -> { + String txId = newValue.getTxId(); + openOfferManager.getObservableList().stream() + .filter(openOffer -> txId.equals(openOffer.getOffer().getOfferFeePaymentTxId())) + .forEach(openOffer -> { + // We delay to avoid concurrent modification exceptions + UserThread.runAfter(() -> { + openOffer.getOffer().setErrorMessage(newValue.getMessage()); + if (rejectedTxErrorMessageHandler != null) { + rejectedTxErrorMessageHandler.accept(Res.get("popup.warning.openOffer.makerFeeTxRejected", openOffer.getId(), txId)); + } + openOfferManager.removeOpenOffer(openOffer, () -> { + log.warn("We removed an open offer because the maker fee was rejected by the Bitcoin " + + "network. OfferId={}, txId={}", openOffer.getShortId(), txId); + }, log::warn); + }, 1); + }); + + tradeManager.getTradableList().stream() + .filter(trade -> trade.getOffer() != null) + .forEach(trade -> { + String details = null; + if (txId.equals(trade.getDepositTxId())) { + details = Res.get("popup.warning.trade.txRejected.deposit"); + } + if (txId.equals(trade.getOffer().getOfferFeePaymentTxId()) || txId.equals(trade.getTakerFeeTxId())) { + details = Res.get("popup.warning.trade.txRejected.tradeFee"); + } + + if (details != null) { + // We delay to avoid concurrent modification exceptions + String finalDetails = details; + UserThread.runAfter(() -> { + trade.setErrorMessage(newValue.getMessage()); + if (rejectedTxErrorMessageHandler != null) { + rejectedTxErrorMessageHandler.accept(Res.get("popup.warning.trade.txRejected", + finalDetails, trade.getShortId(), txId)); + } + tradeManager.addTradeToFailedTrades(trade); + }, 1); + } + }); + }, 3); + } + }); + } private String getBtcNetworkAsString() { String postFix; if (config.ignoreLocalBtcNode) diff --git a/core/src/main/java/bisq/core/filter/FilterManager.java b/core/src/main/java/bisq/core/filter/FilterManager.java index ca7f7670912..9ac91c0880a 100644 --- a/core/src/main/java/bisq/core/filter/FilterManager.java +++ b/core/src/main/java/bisq/core/filter/FilterManager.java @@ -18,6 +18,7 @@ package bisq.core.filter; import bisq.core.btc.nodes.BtcNodes; +import bisq.core.locale.Res; import bisq.core.payment.payload.PaymentAccountPayload; import bisq.core.payment.payload.PaymentMethod; import bisq.core.provider.ProvidersRepository; @@ -57,6 +58,7 @@ import java.util.Collections; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Consumer; import java.lang.reflect.Method; @@ -206,6 +208,35 @@ public void onRequestCustomBridges() { }); } + public void setFilterWarningHandler(Consumer filterWarningHandler) { + addListener(filter -> { + if (filter != null && filterWarningHandler != null) { + if (filter.getSeedNodes() != null && !filter.getSeedNodes().isEmpty()) { + log.info(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))); + // Let's keep that more silent. Might be used in case a node is unstable and we don't want to confuse users. + // filterWarningHandler.accept(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.seed"))); + } + + if (filter.getPriceRelayNodes() != null && !filter.getPriceRelayNodes().isEmpty()) { + log.info(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))); + // Let's keep that more silent. Might be used in case a node is unstable and we don't want to confuse users. + // filterWarningHandler.accept(Res.get("popup.warning.nodeBanned", Res.get("popup.warning.priceRelay"))); + } + + if (requireUpdateToNewVersionForTrading()) { + filterWarningHandler.accept(Res.get("popup.warning.mandatoryUpdate.trading")); + } + + if (requireUpdateToNewVersionForDAO()) { + filterWarningHandler.accept(Res.get("popup.warning.mandatoryUpdate.dao")); + } + if (filter.isDisableDao()) { + filterWarningHandler.accept(Res.get("popup.warning.disable.dao")); + } + } + }); + } + public boolean isPrivilegedDevPubKeyBanned(String pubKeyAsHex) { Filter filter = getFilter(); if (filter == null) { From a8a881ea3eaadec1a3202648d6272bb6ad867b6e Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 1 Oct 2020 09:56:26 -0500 Subject: [PATCH 23/24] Fix wrong printSystemLoad calls --- core/src/main/java/bisq/core/app/BisqHeadlessApp.java | 3 --- .../main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java | 4 ++-- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java index 16f6a5e2715..ed17af065eb 100644 --- a/core/src/main/java/bisq/core/app/BisqHeadlessApp.java +++ b/core/src/main/java/bisq/core/app/BisqHeadlessApp.java @@ -22,7 +22,6 @@ import bisq.common.UserThread; import bisq.common.setup.GracefulShutDownHandler; import bisq.common.storage.CorruptedDatabaseFilesHandler; -import bisq.common.util.Profiler; import com.google.inject.Injector; @@ -60,8 +59,6 @@ public void startApplication() { tradeManager = injector.getInstance(TradeManager.class); setupHandlers(); - - UserThread.runPeriodically(() -> Profiler.printSystemLoad(log), LOG_MEMORY_PERIOD_MIN, TimeUnit.MINUTES); } catch (Throwable throwable) { log.error("Error during app init", throwable); handleUncaughtException(throwable, false); diff --git a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java index 4e6f7619c72..297c7bf4fd4 100644 --- a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java +++ b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java @@ -189,7 +189,7 @@ protected void keepRunning() { protected void checkMemory(Config config, GracefulShutDownHandler gracefulShutDownHandler) { int maxMemory = config.maxMemory; UserThread.runPeriodically(() -> { - Profiler.printSystemLoad(log); + Profiler.printSystemLoad(); if (!stopped) { long usedMemoryInMB = Profiler.getUsedMemoryInMB(); double warningTrigger = maxMemory * 0.8; @@ -199,7 +199,7 @@ protected void checkMemory(Config config, GracefulShutDownHandler gracefulShutDo "\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n\n", (int) warningTrigger, usedMemoryInMB, Profiler.getFreeMemoryInMB()); System.gc(); - Profiler.printSystemLoad(log); + Profiler.printSystemLoad(); } UserThread.runAfter(() -> { From d84122259b91c4aa7d93e3fd864547c916a4d2a3 Mon Sep 17 00:00:00 2001 From: chimp1984 Date: Thu, 1 Oct 2020 10:35:30 -0500 Subject: [PATCH 24/24] Fix merge conflicts --- core/src/main/java/bisq/core/app/WalletAppSetup.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/bisq/core/app/WalletAppSetup.java b/core/src/main/java/bisq/core/app/WalletAppSetup.java index 2749211c63f..3c7c7466c39 100644 --- a/core/src/main/java/bisq/core/app/WalletAppSetup.java +++ b/core/src/main/java/bisq/core/app/WalletAppSetup.java @@ -235,7 +235,7 @@ void setRejectedTxErrorMessageHandler(Consumer rejectedTxErrorMessageHan }, 1); }); - tradeManager.getTradableList().stream() + tradeManager.getTradesAsObservableList().stream() .filter(trade -> trade.getOffer() != null) .forEach(trade -> { String details = null; @@ -255,7 +255,6 @@ void setRejectedTxErrorMessageHandler(Consumer rejectedTxErrorMessageHan rejectedTxErrorMessageHandler.accept(Res.get("popup.warning.trade.txRejected", finalDetails, trade.getShortId(), txId)); } - tradeManager.addTradeToFailedTrades(trade); }, 1); } });