Skip to content

Commit

Permalink
Merge pull request #3982 from dmos62/local-btc-node-configuration-check
Browse files Browse the repository at this point in the history
Add local Bitcoin node configuration detection
  • Loading branch information
sqrrm authored Feb 27, 2020
2 parents ad3da4b + 85e4515 commit 1d1cba1
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 116 deletions.
28 changes: 19 additions & 9 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
import bisq.common.UserThread;
import bisq.common.app.DevEnv;
import bisq.common.app.Log;
import bisq.common.config.BaseCurrencyNetwork;
import bisq.common.config.Config;
import bisq.common.crypto.CryptoException;
import bisq.common.crypto.KeyRing;
Expand Down Expand Up @@ -193,7 +192,7 @@ default void onRequestWalletPassword() {

@Setter
@Nullable
private Consumer<Runnable> displayTacHandler;
private Consumer<Runnable> displayTacHandler, displayLocalNodeMisconfigurationHandler;
@Setter
@Nullable
private Consumer<String> cryptoSetupFailedHandler, chainFileLockedExceptionHandler,
Expand Down Expand Up @@ -348,7 +347,7 @@ public void start() {
}

private void step2() {
detectLocalBitcoinNode(this::step3);
maybeCheckLocalBitcoinNode(this::step3);
}

private void step3() {
Expand Down Expand Up @@ -482,14 +481,24 @@ private void maybeShowTac() {
}
}

private void detectLocalBitcoinNode(Runnable nextStep) {
BaseCurrencyNetwork baseCurrencyNetwork = config.baseCurrencyNetwork;
if (config.ignoreLocalBtcNode || baseCurrencyNetwork.isDaoRegTest() || baseCurrencyNetwork.isDaoTestNet()) {
private void maybeCheckLocalBitcoinNode(Runnable nextStep) {
if (localBitcoinNode.shouldBeIgnored()) {
nextStep.run();
return;
}

localBitcoinNode.detectAndRun(nextStep);
// Here we only want to provide the user with a choice (in a popup) in case a
// local node is detected, but badly configured.
if (localBitcoinNode.isDetectedButMisconfigured()) {
if (displayLocalNodeMisconfigurationHandler != null) {
displayLocalNodeMisconfigurationHandler.accept(nextStep);
return;
} else {
log.error("displayLocalNodeMisconfigurationHandler undefined", new RuntimeException());
}
}

nextStep.run();
}

private void readMapsFromResources(Runnable nextStep) {
Expand Down Expand Up @@ -559,7 +568,8 @@ else if (displayTorNetworkSettingsHandler != null)

// We only init wallet service here if not using Tor for bitcoinj.
// When using Tor, wallet init must be deferred until Tor is ready.
if (!preferences.getUseTorForBitcoinJ() || localBitcoinNode.isDetected()) {
// TODO encapsulate below conditional inside getUseTorForBitcoinJ
if (!preferences.getUseTorForBitcoinJ() || localBitcoinNode.shouldBeUsed()) {
initWallet();
}

Expand Down Expand Up @@ -862,7 +872,7 @@ private void maybeShowSecurityRecommendation() {
}

private void maybeShowLocalhostRunningInfo() {
maybeTriggerDisplayHandler("bitcoinLocalhostNode", displayLocalhostHandler, localBitcoinNode.isDetected());
maybeTriggerDisplayHandler("bitcoinLocalhostNode", displayLocalhostHandler, localBitcoinNode.shouldBeUsed());
}

private void maybeShowAccountSigningStateInfo() {
Expand Down
5 changes: 0 additions & 5 deletions core/src/main/java/bisq/core/app/CoreModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import java.io.File;

import static bisq.common.config.Config.*;
import static bisq.core.btc.nodes.LocalBitcoinNode.LOCAL_BITCOIN_NODE_PORT;
import static com.google.inject.name.Names.named;

public class CoreModule extends AppModule {
Expand Down Expand Up @@ -78,10 +77,6 @@ protected void configure() {
bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.useDevMode);
bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.referralId);

bindConstant().annotatedWith(named(LOCAL_BITCOIN_NODE_PORT))
.to(config.baseCurrencyNetworkParameters.getPort());


// ordering is used for shut down sequence
install(new TradeModule(config));
install(new EncryptionServiceModule(config));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import java.io.File;

import static bisq.common.config.Config.*;
import static bisq.core.btc.nodes.LocalBitcoinNode.LOCAL_BITCOIN_NODE_PORT;
import static com.google.inject.name.Names.named;

public class ModuleForAppWithP2p extends AppModule {
Expand Down Expand Up @@ -82,9 +81,6 @@ protected void configure() {
bindConstant().annotatedWith(named(USE_DEV_MODE)).to(config.useDevMode);
bindConstant().annotatedWith(named(REFERRAL_ID)).to(config.referralId);

bindConstant().annotatedWith(named(LOCAL_BITCOIN_NODE_PORT))
.to(config.baseCurrencyNetworkParameters.getPort());

// ordering is used for shut down sequence
install(new TradeModule(config));
install(new EncryptionServiceModule(config));
Expand Down
Loading

0 comments on commit 1d1cba1

Please sign in to comment.