Move 'numConnectionsForBtc' option handling to Config

Note that this change makes the user-facing change of renaming
the 'numConnectionForBtc' (singular 'Connection') to
'numConnectionsForBtc' (plural 'Connections'). It is presumed that not
many users are relying on this option for day-to-day operations, and the
singular version was pretty clearly a typo / oversight.
This commit is contained in:
Chris Beams 2019-12-17 14:46:11 +01:00
parent c8d739ded5
commit 99cf8c9596
No known key found for this signature in database
GPG key ID: 3D214F8F5BC5ED73
8 changed files with 26 additions and 24 deletions

View file

@ -63,12 +63,14 @@ public class Config {
public static final String SOCKS5_DISCOVER_MODE = "socks5DiscoverMode"; public static final String SOCKS5_DISCOVER_MODE = "socks5DiscoverMode";
public static final String USE_ALL_PROVIDED_NODES = "useAllProvidedNodes"; public static final String USE_ALL_PROVIDED_NODES = "useAllProvidedNodes";
public static final String USER_AGENT = "userAgent"; public static final String USER_AGENT = "userAgent";
public static final String NUM_CONNECTIONS_FOR_BTC = "numConnectionsForBtc";
private static final Logger log = LoggerFactory.getLogger(Config.class); private static final Logger log = LoggerFactory.getLogger(Config.class);
public static final int DEFAULT_INT = Integer.MIN_VALUE; public static final int DEFAULT_INT = Integer.MIN_VALUE;
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties"; static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
public static final String DEFAULT_REGTEST_HOST = "localhost"; public static final String DEFAULT_REGTEST_HOST = "localhost";
public static final int DEFAULT_NUM_CONNECTIONS_FOR_BTC = 9; // down from BitcoinJ default of 12
public static File CURRENT_APP_DATA_DIR; public static File CURRENT_APP_DATA_DIR;
@ -122,6 +124,7 @@ public class Config {
private final String socks5DiscoverMode; private final String socks5DiscoverMode;
private final boolean useAllProvidedNodes; private final boolean useAllProvidedNodes;
private final String userAgent; private final String userAgent;
private final int numConnectionsForBtc;
// properties derived from cli options, but not exposed as cli options themselves // properties derived from cli options, but not exposed as cli options themselves
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
@ -430,6 +433,12 @@ public class Config {
.withRequiredArg() .withRequiredArg()
.defaultsTo("Bisq"); .defaultsTo("Bisq");
ArgumentAcceptingOptionSpec<Integer> numConnectionsForBtcOpt =
parser.accepts(NUM_CONNECTIONS_FOR_BTC, "Number of connections to the Bitcoin network")
.withRequiredArg()
.ofType(int.class)
.defaultsTo(DEFAULT_NUM_CONNECTIONS_FOR_BTC);
try { try {
OptionSet cliOpts = parser.parse(args); OptionSet cliOpts = parser.parse(args);
@ -516,6 +525,7 @@ public class Config {
this.socks5DiscoverMode = options.valueOf(socks5DiscoverModeOpt); this.socks5DiscoverMode = options.valueOf(socks5DiscoverModeOpt);
this.useAllProvidedNodes = options.valueOf(useAllProvidedNodesOpt); this.useAllProvidedNodes = options.valueOf(useAllProvidedNodesOpt);
this.userAgent = options.valueOf(userAgentOpt); this.userAgent = options.valueOf(userAgentOpt);
this.numConnectionsForBtc = options.valueOf(numConnectionsForBtcOpt);
} catch (OptionException ex) { } catch (OptionException ex) {
throw new ConfigException(format("problem parsing option '%s': %s", throw new ConfigException(format("problem parsing option '%s': %s",
ex.options().get(0), ex.options().get(0),
@ -775,4 +785,8 @@ public class Config {
public String getUserAgent() { public String getUserAgent() {
return userAgent; return userAgent;
} }
public int getNumConnectionsForBtc() {
return numConnectionsForBtc;
}
} }

View file

@ -17,7 +17,6 @@
package bisq.core.app; package bisq.core.app;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.dao.DaoOptionKeys; import bisq.core.dao.DaoOptionKeys;
import bisq.common.BisqException; import bisq.common.BisqException;
@ -59,7 +58,7 @@ public class BisqEnvironment extends StandardEnvironment {
protected final String rpcUser, rpcPassword, protected final String rpcUser, rpcPassword,
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode, rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply, genesisTxId, genesisBlockHeight, genesisTotalSupply,
daoActivated; daoActivated;
public BisqEnvironment(OptionSet options) { public BisqEnvironment(OptionSet options) {
@ -84,7 +83,6 @@ public class BisqEnvironment extends StandardEnvironment {
daoActivated = getProperty(commandLineProperties, DaoOptionKeys.DAO_ACTIVATED, "true"); daoActivated = getProperty(commandLineProperties, DaoOptionKeys.DAO_ACTIVATED, "true");
//BtcOptionKeys //BtcOptionKeys
numConnectionForBtc = getProperty(commandLineProperties, BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, "9");
MutablePropertySources propertySources = getPropertySources(); MutablePropertySources propertySources = getPropertySources();
propertySources.addFirst(commandLineProperties); propertySources.addFirst(commandLineProperties);
@ -114,8 +112,6 @@ public class BisqEnvironment extends StandardEnvironment {
setProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, genesisBlockHeight); setProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, genesisBlockHeight);
setProperty(DaoOptionKeys.GENESIS_TOTAL_SUPPLY, genesisTotalSupply); setProperty(DaoOptionKeys.GENESIS_TOTAL_SUPPLY, genesisTotalSupply);
setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated); setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated);
setProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, numConnectionForBtc);
} }
}); });
} }

View file

@ -17,7 +17,6 @@
package bisq.core.app; package bisq.core.app;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.btc.setup.WalletsSetup; import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.BsqWalletService; import bisq.core.btc.wallet.BsqWalletService;
import bisq.core.btc.wallet.BtcWalletService; import bisq.core.btc.wallet.BtcWalletService;
@ -286,9 +285,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
.ofType(boolean.class); .ofType(boolean.class);
//BtcOptionKeys //BtcOptionKeys
parser.accepts(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC,
format("Number of connections to the Bitcoin network (default: %s)", "9"))
.withRequiredArg();
//RpcOptionKeys //RpcOptionKeys
parser.accepts(DaoOptionKeys.RPC_USER, parser.accepts(DaoOptionKeys.RPC_USER,

View file

@ -82,7 +82,7 @@ public class BitcoinModule extends AppModule {
bindConstant().annotatedWith(named(Config.BTC_NODES)).to(config.getBtcNodes()); bindConstant().annotatedWith(named(Config.BTC_NODES)).to(config.getBtcNodes());
bindConstant().annotatedWith(named(Config.USER_AGENT)).to(config.getUserAgent()); bindConstant().annotatedWith(named(Config.USER_AGENT)).to(config.getUserAgent());
bindConstant().annotatedWith(named(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC)).to(environment.getRequiredProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC)); bindConstant().annotatedWith(named(Config.NUM_CONNECTIONS_FOR_BTC)).to(config.getNumConnectionsForBtc());
bindConstant().annotatedWith(named(Config.USE_ALL_PROVIDED_NODES)).to(config.isUseAllProvidedNodes()); bindConstant().annotatedWith(named(Config.USE_ALL_PROVIDED_NODES)).to(config.isUseAllProvidedNodes());
bindConstant().annotatedWith(named(Config.IGNORE_LOCAL_BTC_NODE)).to(config.isIgnoreLocalBtcNode()); bindConstant().annotatedWith(named(Config.IGNORE_LOCAL_BTC_NODE)).to(config.isIgnoreLocalBtcNode());
bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.getSocks5DiscoverMode()); bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.getSocks5DiscoverMode());

View file

@ -18,5 +18,4 @@
package bisq.core.btc; package bisq.core.btc;
public class BtcOptionKeys { public class BtcOptionKeys {
public static final String NUM_CONNECTIONS_FOR_BTC = "numConnectionForBtc";
} }

View file

@ -17,9 +17,9 @@
package bisq.core.btc.nodes; package bisq.core.btc.nodes;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.user.Preferences; import bisq.core.user.Preferences;
import bisq.common.config.Config;
import bisq.common.util.Utilities; import bisq.common.util.Utilities;
import java.util.Collections; import java.util.Collections;
@ -83,7 +83,7 @@ public class BtcNodesSetupPreferences {
break; break;
case PUBLIC: case PUBLIC:
// We keep the empty nodes // We keep the empty nodes
result = (int) Math.floor(WalletsSetup.DEFAULT_CONNECTIONS * 0.8); result = (int) Math.floor(Config.DEFAULT_NUM_CONNECTIONS_FOR_BTC * 0.8);
break; break;
case PROVIDED: case PROVIDED:
default: default:

View file

@ -116,7 +116,7 @@ public class WalletConfig extends AbstractIdleService {
private final BisqWalletFactory walletFactory; private final BisqWalletFactory walletFactory;
private final Config config; private final Config config;
private final String userAgent; private final String userAgent;
private int numConnectionForBtc; private int numConnectionsForBtc;
private volatile Wallet vBtcWallet; private volatile Wallet vBtcWallet;
@Nullable @Nullable
@ -153,13 +153,13 @@ public class WalletConfig extends AbstractIdleService {
File directory, File directory,
Config config, Config config,
String userAgent, String userAgent,
int numConnectionForBtc, int numConnectionsForBtc,
@SuppressWarnings("SameParameterValue") String btcWalletFileName, @SuppressWarnings("SameParameterValue") String btcWalletFileName,
@SuppressWarnings("SameParameterValue") String bsqWalletFileName, @SuppressWarnings("SameParameterValue") String bsqWalletFileName,
@SuppressWarnings("SameParameterValue") String spvChainFileName) { @SuppressWarnings("SameParameterValue") String spvChainFileName) {
this.config = config; this.config = config;
this.userAgent = userAgent; this.userAgent = userAgent;
this.numConnectionForBtc = numConnectionForBtc; this.numConnectionsForBtc = numConnectionsForBtc;
this.context = new Context(params); this.context = new Context(params);
this.params = checkNotNull(context.getParams()); this.params = checkNotNull(context.getParams());
this.directory = checkNotNull(directory); this.directory = checkNotNull(directory);
@ -438,7 +438,7 @@ public class WalletConfig extends AbstractIdleService {
// before we're actually connected the broadcast waits for an appropriate number of connections. // before we're actually connected the broadcast waits for an appropriate number of connections.
if (peerAddresses != null) { if (peerAddresses != null) {
for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr); for (PeerAddress addr : peerAddresses) vPeerGroup.addAddress(addr);
int maxConnections = Math.min(numConnectionForBtc, peerAddresses.length); int maxConnections = Math.min(numConnectionsForBtc, peerAddresses.length);
log.info("We try to connect to {} btc nodes", maxConnections); log.info("We try to connect to {} btc nodes", maxConnections);
vPeerGroup.setMaxConnections(maxConnections); vPeerGroup.setMaxConnections(maxConnections);
vPeerGroup.setAddPeersFromAddressMessage(false); vPeerGroup.setAddPeersFromAddressMessage(false);

View file

@ -17,7 +17,6 @@
package bisq.core.btc.setup; package bisq.core.btc.setup;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.btc.exceptions.InvalidHostException; import bisq.core.btc.exceptions.InvalidHostException;
import bisq.core.btc.exceptions.RejectedTxException; import bisq.core.btc.exceptions.RejectedTxException;
import bisq.core.btc.model.AddressEntry; import bisq.core.btc.model.AddressEntry;
@ -107,8 +106,6 @@ import static com.google.common.base.Preconditions.checkNotNull;
// merge WalletsSetup with WalletConfig to one class. // merge WalletsSetup with WalletConfig to one class.
@Slf4j @Slf4j
public class WalletsSetup { public class WalletsSetup {
// We reduce defaultConnections from 12 (PeerGroup.DEFAULT_CONNECTIONS) to 9 nodes
public static final int DEFAULT_CONNECTIONS = 9;
@Getter @Getter
public final BooleanProperty walletsSetupFailed = new SimpleBooleanProperty(); public final BooleanProperty walletsSetupFailed = new SimpleBooleanProperty();
@ -124,7 +121,7 @@ public class WalletsSetup {
private final Config config; private final Config config;
private final BtcNodes btcNodes; private final BtcNodes btcNodes;
private final String btcWalletFileName; private final String btcWalletFileName;
private final int numConnectionForBtc; private final int numConnectionsForBtc;
private final String userAgent; private final String userAgent;
private final NetworkParameters params; private final NetworkParameters params;
private final File walletDir; private final File walletDir;
@ -153,7 +150,7 @@ public class WalletsSetup {
@Named(Config.USER_AGENT) String userAgent, @Named(Config.USER_AGENT) String userAgent,
@Named(Config.WALLET_DIR) File appDir, @Named(Config.WALLET_DIR) File appDir,
@Named(Config.USE_ALL_PROVIDED_NODES) boolean useAllProvidedNodes, @Named(Config.USE_ALL_PROVIDED_NODES) boolean useAllProvidedNodes,
@Named(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC) String numConnectionForBtc, @Named(Config.NUM_CONNECTIONS_FOR_BTC) int numConnectionsForBtc,
@Named(Config.SOCKS5_DISCOVER_MODE) String socks5DiscoverModeString) { @Named(Config.SOCKS5_DISCOVER_MODE) String socks5DiscoverModeString) {
this.regTestHost = regTestHost; this.regTestHost = regTestHost;
this.addressEntryList = addressEntryList; this.addressEntryList = addressEntryList;
@ -161,7 +158,7 @@ public class WalletsSetup {
this.socks5ProxyProvider = socks5ProxyProvider; this.socks5ProxyProvider = socks5ProxyProvider;
this.config = config; this.config = config;
this.btcNodes = btcNodes; this.btcNodes = btcNodes;
this.numConnectionForBtc = numConnectionForBtc != null ? Integer.parseInt(numConnectionForBtc) : DEFAULT_CONNECTIONS; this.numConnectionsForBtc = numConnectionsForBtc;
this.useAllProvidedNodes = useAllProvidedNodes; this.useAllProvidedNodes = useAllProvidedNodes;
this.userAgent = userAgent; this.userAgent = userAgent;
@ -202,7 +199,7 @@ public class WalletsSetup {
walletDir, walletDir,
config, config,
userAgent, userAgent,
numConnectionForBtc, numConnectionsForBtc,
btcWalletFileName, btcWalletFileName,
BSQ_WALLET_FILE_NAME, BSQ_WALLET_FILE_NAME,
SPV_CHAIN_FILE_NAME) { SPV_CHAIN_FILE_NAME) {