diff --git a/common/src/main/java/bisq/common/config/Config.java b/common/src/main/java/bisq/common/config/Config.java index f00cfa0e57..e5f0a6e82c 100644 --- a/common/src/main/java/bisq/common/config/Config.java +++ b/common/src/main/java/bisq/common/config/Config.java @@ -68,6 +68,7 @@ public class Config { private final boolean useDevMode; private final boolean useDevPrivilegeKeys; private final boolean dumpStatistics; + private final int maxMemory; // properties derived from cli options, but not exposed as cli options themselves private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state @@ -218,6 +219,11 @@ public class Config { .ofType(boolean.class) .defaultsTo(false); + ArgumentAcceptingOptionSpec maxMemoryOpt = + parser.accepts("maxMemory", "Max. permitted memory (used only by headless versions)") + .withRequiredArg() + .ofType(int.class) + .defaultsTo(1200); try { OptionSet cliOpts = parser.parse(args); @@ -273,6 +279,7 @@ public class Config { this.useDevMode = options.valueOf(useDevModeOpt); this.useDevPrivilegeKeys = options.valueOf(useDevPrivilegeKeysOpt); this.dumpStatistics = options.valueOf(dumpStatisticsOpt); + this.maxMemory = options.valueOf(maxMemoryOpt); } catch (OptionException ex) { throw new ConfigException(format("problem parsing option '%s': %s", ex.options().get(0), @@ -432,4 +439,8 @@ public class Config { public boolean isDumpStatistics() { return dumpStatistics; } + + public int getMaxMemory() { + return maxMemory; + } } diff --git a/core/src/main/java/bisq/core/app/AppOptionKeys.java b/core/src/main/java/bisq/core/app/AppOptionKeys.java index 59f6abe2c0..bc8119b5e4 100644 --- a/core/src/main/java/bisq/core/app/AppOptionKeys.java +++ b/core/src/main/java/bisq/core/app/AppOptionKeys.java @@ -19,6 +19,5 @@ package bisq.core.app; public class AppOptionKeys { public static final String PROVIDERS = "providers"; - public static final String MAX_MEMORY = "maxMemory"; public static final String IGNORE_DEV_MSG_KEY = "ignoreDevMsg"; } diff --git a/core/src/main/java/bisq/core/app/BisqEnvironment.java b/core/src/main/java/bisq/core/app/BisqEnvironment.java index 1888615a28..b6be089afd 100644 --- a/core/src/main/java/bisq/core/app/BisqEnvironment.java +++ b/core/src/main/java/bisq/core/app/BisqEnvironment.java @@ -26,6 +26,7 @@ import bisq.network.p2p.network.ConnectionConfig; import bisq.common.BisqException; import bisq.common.CommonOptionKeys; import bisq.common.config.BaseCurrencyNetwork; +import bisq.common.config.Config; import org.springframework.core.env.JOptCommandLinePropertySource; import org.springframework.core.env.MutablePropertySources; @@ -71,7 +72,7 @@ public class BisqEnvironment extends StandardEnvironment { protected final String btcNodes, seedNodes, ignoreDevMsg, useTorForBtc, rpcUser, rpcPassword, rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode, - banList, maxMemory, socks5ProxyBtcAddress, + banList, socks5ProxyBtcAddress, torRcFile, torRcOptions, externalTorControlPort, externalTorPassword, externalTorCookieFile, socks5ProxyHttpAddress, useAllProvidedNodes, numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply, daoActivated, msgThrottlePerSec, msgThrottlePer10Sec, sendMsgThrottleTrigger, sendMsgThrottleSleep; @@ -93,7 +94,6 @@ public class BisqEnvironment extends StandardEnvironment { //AppOptionKeys ignoreDevMsg = getProperty(commandLineProperties, AppOptionKeys.IGNORE_DEV_MSG_KEY, ""); - maxMemory = getProperty(commandLineProperties, AppOptionKeys.MAX_MEMORY, ""); providers = getProperty(commandLineProperties, AppOptionKeys.PROVIDERS, ""); //NetworkOptionKeys @@ -177,7 +177,6 @@ public class BisqEnvironment extends StandardEnvironment { setProperty(NetworkOptionKeys.SEND_MSG_THROTTLE_SLEEP, sendMsgThrottleSleep); setProperty(AppOptionKeys.IGNORE_DEV_MSG_KEY, ignoreDevMsg); - setProperty(AppOptionKeys.MAX_MEMORY, maxMemory); setProperty(AppOptionKeys.PROVIDERS, providers); setProperty(DaoOptionKeys.RPC_USER, rpcUser); diff --git a/core/src/main/java/bisq/core/app/BisqExecutable.java b/core/src/main/java/bisq/core/app/BisqExecutable.java index fabb6bdd32..515d576fa4 100644 --- a/core/src/main/java/bisq/core/app/BisqExecutable.java +++ b/core/src/main/java/bisq/core/app/BisqExecutable.java @@ -382,10 +382,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet .ofType(int.class); //AppOptionKeys - parser.accepts(AppOptionKeys.MAX_MEMORY, - format("Max. permitted memory (used only at headless versions) (default: %s)", "600")) - .withRequiredArg(); - parser.accepts(AppOptionKeys.IGNORE_DEV_MSG_KEY, format("If set to true all signed network_messages from bisq developers are ignored " + "(Global alert, Version update alert, Filters for offers, nodes or trading account data) (default: %s)", "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 c57a9a0ada..cde2488631 100644 --- a/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java +++ b/core/src/main/java/bisq/core/app/misc/ExecutableForAppWithP2p.java @@ -17,8 +17,6 @@ package bisq.core.app.misc; -import bisq.core.app.AppOptionKeys; -import bisq.core.app.BisqEnvironment; import bisq.core.app.BisqExecutable; import bisq.core.btc.setup.WalletsSetup; import bisq.core.btc.wallet.BsqWalletService; @@ -48,13 +46,11 @@ import lombok.extern.slf4j.Slf4j; @Slf4j public abstract class ExecutableForAppWithP2p extends BisqExecutable implements UncaughtExceptionHandler { - private static final long MAX_MEMORY_MB_DEFAULT = 1200; 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); private volatile boolean stopped; private final long startTime = System.currentTimeMillis(); - private static long maxMemory = MAX_MEMORY_MB_DEFAULT; public ExecutableForAppWithP2p(String fullName, String scriptName, String appName, String version) { super(fullName, scriptName, appName, version); @@ -139,16 +135,8 @@ public abstract class ExecutableForAppWithP2p extends BisqExecutable implements }, CHECK_SHUTDOWN_SEC); } - protected void checkMemory(BisqEnvironment environment, GracefulShutDownHandler gracefulShutDownHandler) { - String maxMemoryOption = environment.getProperty(AppOptionKeys.MAX_MEMORY); - if (maxMemoryOption != null && !maxMemoryOption.isEmpty()) { - try { - maxMemory = Integer.parseInt(maxMemoryOption); - } catch (Throwable t) { - log.error(t.getMessage()); - } - } - + protected void checkMemory(Config config, GracefulShutDownHandler gracefulShutDownHandler) { + int maxMemory = config.getMaxMemory(); UserThread.runPeriodically(() -> { Profiler.printSystemLoad(log); if (!stopped) { diff --git a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java index 201066b0e4..845abf6b40 100644 --- a/seednode/src/main/java/bisq/seednode/SeedNodeMain.java +++ b/seednode/src/main/java/bisq/seednode/SeedNodeMain.java @@ -50,7 +50,7 @@ public class SeedNodeMain extends ExecutableForAppWithP2p { protected void doExecute(OptionSet options) { super.doExecute(options); - checkMemory(bisqEnvironment, this); + checkMemory(config, this); startShutDownInterval(this); CommonSetup.setup(this); diff --git a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java index d80e8ee6c6..aab99ea714 100644 --- a/statsnode/src/main/java/bisq/statistics/StatisticsMain.java +++ b/statsnode/src/main/java/bisq/statistics/StatisticsMain.java @@ -47,7 +47,7 @@ public class StatisticsMain extends ExecutableForAppWithP2p { protected void doExecute(OptionSet options) { super.doExecute(options); - checkMemory(bisqEnvironment, this); + checkMemory(config, this); CommonSetup.setup(this); keepRunning();