mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 15:00:30 +01:00
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:
parent
c8d739ded5
commit
99cf8c9596
8 changed files with 26 additions and 24 deletions
|
@ -63,12 +63,14 @@ public class Config {
|
|||
public static final String SOCKS5_DISCOVER_MODE = "socks5DiscoverMode";
|
||||
public static final String USE_ALL_PROVIDED_NODES = "useAllProvidedNodes";
|
||||
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);
|
||||
|
||||
public static final int DEFAULT_INT = Integer.MIN_VALUE;
|
||||
static final String DEFAULT_CONFIG_FILE_NAME = "bisq.properties";
|
||||
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;
|
||||
|
||||
|
@ -122,6 +124,7 @@ public class Config {
|
|||
private final String socks5DiscoverMode;
|
||||
private final boolean useAllProvidedNodes;
|
||||
private final String userAgent;
|
||||
private final int numConnectionsForBtc;
|
||||
|
||||
// properties derived from cli options, but not exposed as cli options themselves
|
||||
private boolean localBitcoinNodeIsRunning = false; // FIXME: eliminate mutable state
|
||||
|
@ -430,6 +433,12 @@ public class Config {
|
|||
.withRequiredArg()
|
||||
.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 {
|
||||
OptionSet cliOpts = parser.parse(args);
|
||||
|
||||
|
@ -516,6 +525,7 @@ public class Config {
|
|||
this.socks5DiscoverMode = options.valueOf(socks5DiscoverModeOpt);
|
||||
this.useAllProvidedNodes = options.valueOf(useAllProvidedNodesOpt);
|
||||
this.userAgent = options.valueOf(userAgentOpt);
|
||||
this.numConnectionsForBtc = options.valueOf(numConnectionsForBtcOpt);
|
||||
} catch (OptionException ex) {
|
||||
throw new ConfigException(format("problem parsing option '%s': %s",
|
||||
ex.options().get(0),
|
||||
|
@ -775,4 +785,8 @@ public class Config {
|
|||
public String getUserAgent() {
|
||||
return userAgent;
|
||||
}
|
||||
|
||||
public int getNumConnectionsForBtc() {
|
||||
return numConnectionsForBtc;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package bisq.core.app;
|
||||
|
||||
import bisq.core.btc.BtcOptionKeys;
|
||||
import bisq.core.dao.DaoOptionKeys;
|
||||
|
||||
import bisq.common.BisqException;
|
||||
|
@ -59,7 +58,7 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
|
||||
protected final String rpcUser, rpcPassword,
|
||||
rpcHost, rpcPort, rpcBlockNotificationPort, rpcBlockNotificationHost, dumpBlockchainData, fullDaoNode,
|
||||
numConnectionForBtc, genesisTxId, genesisBlockHeight, genesisTotalSupply,
|
||||
genesisTxId, genesisBlockHeight, genesisTotalSupply,
|
||||
daoActivated;
|
||||
|
||||
public BisqEnvironment(OptionSet options) {
|
||||
|
@ -84,7 +83,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
daoActivated = getProperty(commandLineProperties, DaoOptionKeys.DAO_ACTIVATED, "true");
|
||||
|
||||
//BtcOptionKeys
|
||||
numConnectionForBtc = getProperty(commandLineProperties, BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, "9");
|
||||
|
||||
MutablePropertySources propertySources = getPropertySources();
|
||||
propertySources.addFirst(commandLineProperties);
|
||||
|
@ -114,8 +112,6 @@ public class BisqEnvironment extends StandardEnvironment {
|
|||
setProperty(DaoOptionKeys.GENESIS_BLOCK_HEIGHT, genesisBlockHeight);
|
||||
setProperty(DaoOptionKeys.GENESIS_TOTAL_SUPPLY, genesisTotalSupply);
|
||||
setProperty(DaoOptionKeys.DAO_ACTIVATED, daoActivated);
|
||||
|
||||
setProperty(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC, numConnectionForBtc);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package bisq.core.app;
|
||||
|
||||
import bisq.core.btc.BtcOptionKeys;
|
||||
import bisq.core.btc.setup.WalletsSetup;
|
||||
import bisq.core.btc.wallet.BsqWalletService;
|
||||
import bisq.core.btc.wallet.BtcWalletService;
|
||||
|
@ -286,9 +285,6 @@ public abstract class BisqExecutable implements GracefulShutDownHandler, BisqSet
|
|||
.ofType(boolean.class);
|
||||
|
||||
//BtcOptionKeys
|
||||
parser.accepts(BtcOptionKeys.NUM_CONNECTIONS_FOR_BTC,
|
||||
format("Number of connections to the Bitcoin network (default: %s)", "9"))
|
||||
.withRequiredArg();
|
||||
|
||||
//RpcOptionKeys
|
||||
parser.accepts(DaoOptionKeys.RPC_USER,
|
||||
|
|
|
@ -82,7 +82,7 @@ public class BitcoinModule extends AppModule {
|
|||
|
||||
bindConstant().annotatedWith(named(Config.BTC_NODES)).to(config.getBtcNodes());
|
||||
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.IGNORE_LOCAL_BTC_NODE)).to(config.isIgnoreLocalBtcNode());
|
||||
bindConstant().annotatedWith(Names.named(Config.SOCKS5_DISCOVER_MODE)).to(config.getSocks5DiscoverMode());
|
||||
|
|
|
@ -18,5 +18,4 @@
|
|||
package bisq.core.btc;
|
||||
|
||||
public class BtcOptionKeys {
|
||||
public static final String NUM_CONNECTIONS_FOR_BTC = "numConnectionForBtc";
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@
|
|||
|
||||
package bisq.core.btc.nodes;
|
||||
|
||||
import bisq.core.btc.setup.WalletsSetup;
|
||||
import bisq.core.user.Preferences;
|
||||
|
||||
import bisq.common.config.Config;
|
||||
import bisq.common.util.Utilities;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -83,7 +83,7 @@ public class BtcNodesSetupPreferences {
|
|||
break;
|
||||
case PUBLIC:
|
||||
// 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;
|
||||
case PROVIDED:
|
||||
default:
|
||||
|
|
|
@ -116,7 +116,7 @@ public class WalletConfig extends AbstractIdleService {
|
|||
private final BisqWalletFactory walletFactory;
|
||||
private final Config config;
|
||||
private final String userAgent;
|
||||
private int numConnectionForBtc;
|
||||
private int numConnectionsForBtc;
|
||||
|
||||
private volatile Wallet vBtcWallet;
|
||||
@Nullable
|
||||
|
@ -153,13 +153,13 @@ public class WalletConfig extends AbstractIdleService {
|
|||
File directory,
|
||||
Config config,
|
||||
String userAgent,
|
||||
int numConnectionForBtc,
|
||||
int numConnectionsForBtc,
|
||||
@SuppressWarnings("SameParameterValue") String btcWalletFileName,
|
||||
@SuppressWarnings("SameParameterValue") String bsqWalletFileName,
|
||||
@SuppressWarnings("SameParameterValue") String spvChainFileName) {
|
||||
this.config = config;
|
||||
this.userAgent = userAgent;
|
||||
this.numConnectionForBtc = numConnectionForBtc;
|
||||
this.numConnectionsForBtc = numConnectionsForBtc;
|
||||
this.context = new Context(params);
|
||||
this.params = checkNotNull(context.getParams());
|
||||
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.
|
||||
if (peerAddresses != null) {
|
||||
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);
|
||||
vPeerGroup.setMaxConnections(maxConnections);
|
||||
vPeerGroup.setAddPeersFromAddressMessage(false);
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
|
||||
package bisq.core.btc.setup;
|
||||
|
||||
import bisq.core.btc.BtcOptionKeys;
|
||||
import bisq.core.btc.exceptions.InvalidHostException;
|
||||
import bisq.core.btc.exceptions.RejectedTxException;
|
||||
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.
|
||||
@Slf4j
|
||||
public class WalletsSetup {
|
||||
// We reduce defaultConnections from 12 (PeerGroup.DEFAULT_CONNECTIONS) to 9 nodes
|
||||
public static final int DEFAULT_CONNECTIONS = 9;
|
||||
|
||||
@Getter
|
||||
public final BooleanProperty walletsSetupFailed = new SimpleBooleanProperty();
|
||||
|
@ -124,7 +121,7 @@ public class WalletsSetup {
|
|||
private final Config config;
|
||||
private final BtcNodes btcNodes;
|
||||
private final String btcWalletFileName;
|
||||
private final int numConnectionForBtc;
|
||||
private final int numConnectionsForBtc;
|
||||
private final String userAgent;
|
||||
private final NetworkParameters params;
|
||||
private final File walletDir;
|
||||
|
@ -153,7 +150,7 @@ public class WalletsSetup {
|
|||
@Named(Config.USER_AGENT) String userAgent,
|
||||
@Named(Config.WALLET_DIR) File appDir,
|
||||
@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) {
|
||||
this.regTestHost = regTestHost;
|
||||
this.addressEntryList = addressEntryList;
|
||||
|
@ -161,7 +158,7 @@ public class WalletsSetup {
|
|||
this.socks5ProxyProvider = socks5ProxyProvider;
|
||||
this.config = config;
|
||||
this.btcNodes = btcNodes;
|
||||
this.numConnectionForBtc = numConnectionForBtc != null ? Integer.parseInt(numConnectionForBtc) : DEFAULT_CONNECTIONS;
|
||||
this.numConnectionsForBtc = numConnectionsForBtc;
|
||||
this.useAllProvidedNodes = useAllProvidedNodes;
|
||||
this.userAgent = userAgent;
|
||||
|
||||
|
@ -202,7 +199,7 @@ public class WalletsSetup {
|
|||
walletDir,
|
||||
config,
|
||||
userAgent,
|
||||
numConnectionForBtc,
|
||||
numConnectionsForBtc,
|
||||
btcWalletFileName,
|
||||
BSQ_WALLET_FILE_NAME,
|
||||
SPV_CHAIN_FILE_NAME) {
|
||||
|
|
Loading…
Add table
Reference in a new issue