Skip to content

Commit

Permalink
Revert to using provided BTC nodes if custom nodes are invalid
Browse files Browse the repository at this point in the history
If the user entered an invalid hostname for a custom BTC node, such as a
V3 onion address, after restarting Bisq they would be presented with an
error due to the node being unreachable and unable to continue nor
correct the config.

So now a warning message will be shown in this situation informing the
user of an invalid config and once they restart their client they will
connect to the provided BTC nodes.

Fixes bisq-network#3137
  • Loading branch information
devinbileck committed Jan 13, 2020
1 parent 9e33ca9 commit 61d2026
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions core/src/main/java/bisq/core/app/BisqHeadlessApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ protected void setupHandlers() {
bisqSetup.setWrongOSArchitectureHandler(msg -> log.error("onWrongOSArchitectureHandler. msg={}", msg));
bisqSetup.setVoteResultExceptionHandler(voteResultException -> log.warn("voteResultException={}", voteResultException.toString()));
bisqSetup.setRejectedTxErrorMessageHandler(errorMessage -> log.warn("setRejectedTxErrorMessageHandler. errorMessage={}", errorMessage));
bisqSetup.setShowPopupIfInvalidBtcConfigHandler(() -> log.error("onShowPopupIfInvalidBtcConfigHandler"));

//TODO move to bisqSetup
corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> log.warn("getCorruptedDatabaseFiles. files={}", files));
Expand Down
10 changes: 7 additions & 3 deletions core/src/main/java/bisq/core/app/BisqSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ default void onRequestWalletPassword() {
@Setter
@Nullable
private Consumer<PrivateNotificationPayload> displayPrivateNotificationHandler;
@Setter
@Nullable
private Runnable showPopupIfInvalidBtcConfigHandler;

@Getter
final BooleanProperty newVersionAvailableProperty = new SimpleBooleanProperty(false);
Expand Down Expand Up @@ -545,9 +548,9 @@ private void startP2pNetworkAndWallet() {
};

Timer startupTimeout = UserThread.runAfter(() -> {
if (p2PNetworkSetup.p2pNetworkFailed.get()) {
// Skip this timeout action if the p2p network setup failed
// since a p2p network error prompt will be shown containing the error message
if (p2PNetworkSetup.p2pNetworkFailed.get() || walletsSetup.walletsSetupFailed.get()) {
// Skip this timeout action if the p2p network or wallet setup failed
// since an error prompt will be shown containing the error message
return;
}
log.warn("startupTimeout called");
Expand Down Expand Up @@ -614,6 +617,7 @@ private void initWallet() {
walletAppSetup.init(chainFileLockedExceptionHandler,
spvFileCorruptedHandler,
showFirstPopupIfResyncSPVRequestedHandler,
showPopupIfInvalidBtcConfigHandler,
walletPasswordHandler,
() -> {
if (allBasicServicesInitialized) {
Expand Down
10 changes: 9 additions & 1 deletion core/src/main/java/bisq/core/app/WalletAppSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package bisq.core.app;

import bisq.core.btc.exceptions.InvalidHostException;
import bisq.core.btc.exceptions.RejectedTxException;
import bisq.core.btc.setup.WalletsSetup;
import bisq.core.btc.wallet.WalletsManager;
Expand Down Expand Up @@ -92,6 +93,7 @@ public WalletAppSetup(WalletsManager walletsManager,
void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
@Nullable Consumer<String> spvFileCorruptedHandler,
@Nullable Runnable showFirstPopupIfResyncSPVRequestedHandler,
@Nullable Runnable showPopupIfInvalidBtcConfigHandler,
Runnable walletPasswordHandler,
Runnable downloadCompleteHandler,
Runnable walletInitializedHandler) {
Expand Down Expand Up @@ -169,7 +171,13 @@ void init(@Nullable Consumer<String> chainFileLockedExceptionHandler,
}
}
},
walletServiceException::set);
exception -> {
if (exception instanceof InvalidHostException && showPopupIfInvalidBtcConfigHandler != null) {
showPopupIfInvalidBtcConfigHandler.run();
} else {
walletServiceException.set(exception);
}
});
}

private String getBtcNetworkAsString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/

package bisq.core.btc.exceptions;

public class InvalidHostException extends IllegalArgumentException {

public InvalidHostException(String message) {
super(message);
}
}
23 changes: 21 additions & 2 deletions core/src/main/java/bisq/core/btc/setup/WalletsSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import bisq.core.app.BisqEnvironment;
import bisq.core.btc.BtcOptionKeys;
import bisq.core.btc.exceptions.InvalidHostException;
import bisq.core.btc.exceptions.RejectedTxException;
import bisq.core.btc.model.AddressEntry;
import bisq.core.btc.model.AddressEntryList;
Expand Down Expand Up @@ -91,6 +92,7 @@
import java.util.concurrent.TimeoutException;
import java.util.stream.Collectors;

import lombok.Getter;
import lombok.extern.slf4j.Slf4j;

import org.jetbrains.annotations.NotNull;
Expand All @@ -107,6 +109,9 @@ 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();

private static final long STARTUP_TIMEOUT = 180;
private static final String BSQ_WALLET_FILE_NAME = "bisq_BSQ.wallet";
private static final String SPV_CHAIN_FILE_NAME = "bisq.spvchain";
Expand Down Expand Up @@ -263,13 +268,27 @@ protected void onSetupCompleted() {
} else if (regTestHost == RegTestHost.REMOTE_HOST) {
configPeerNodesForRegTestServer();
} else {
configPeerNodes(socks5Proxy);
try {
configPeerNodes(socks5Proxy);
} catch (IllegalArgumentException e) {
timeoutTimer.stop();
walletsSetupFailed.set(true);
exceptionHandler.handleException(new InvalidHostException(e.getMessage()));
return;
}
}
} else if (bisqEnvironment.isBitcoinLocalhostNodeRunning()) {
walletConfig.setMinBroadcastConnections(1);
walletConfig.setPeerNodesForLocalHost();
} else {
configPeerNodes(socks5Proxy);
try {
configPeerNodes(socks5Proxy);
} catch (IllegalArgumentException e) {
timeoutTimer.stop();
walletsSetupFailed.set(true);
exceptionHandler.handleException(new InvalidHostException(e.getMessage()));
return;
}
}

walletConfig.setDownloadListener(downloadListener)
Expand Down
1 change: 1 addition & 0 deletions core/src/main/resources/i18n/displayStrings.properties
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,7 @@ settings.net.warn.useCustomNodes.B2XWarning=Please be sure that your Bitcoin nod
Users who connect to nodes that violate consensus rules are responsible for any resulting damage. \
Any resulting disputes will be decided in favor of the other peer. No technical support will be given \
to users who ignore this warning and protection mechanisms!
settings.net.warn.invalidBtcConfig=Connection to the Bitcoin network failed because your configuration is invalid.\n\nYour configuration has been reset to use the provided Bitcoin nodes instead. You will need to restart the application.
settings.net.localhostBtcNodeInfo=(Background information: If you are running a local Bitcoin node (localhost) you can connect exclusively to it.)
settings.net.p2PPeersLabel=Connected peers
settings.net.onionAddressColumn=Onion address
Expand Down
10 changes: 10 additions & 0 deletions desktop/src/main/java/bisq/desktop/main/MainViewModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,8 @@ private void setupHandlers() {

bisqSetup.setRejectedTxErrorMessageHandler(msg -> new Popup().width(850).warning(msg).show());

bisqSetup.setShowPopupIfInvalidBtcConfigHandler(this::showPopupIfInvalidBtcConfig);

corruptedDatabaseFilesHandler.getCorruptedDatabaseFiles().ifPresent(files -> new Popup()
.warning(Res.get("popup.warning.incompatibleDB", files.toString(),
bisqEnvironment.getProperty(AppOptionKeys.APP_DATA_DIR_KEY)))
Expand Down Expand Up @@ -474,6 +476,14 @@ private void showSecondPopupIfResyncSPVRequested(Popup firstPopup) {
.show();
}

private void showPopupIfInvalidBtcConfig() {
preferences.setBitcoinNodesOptionOrdinal(0);
new Popup().warning(Res.get("settings.net.warn.invalidBtcConfig"))
.hideCloseButton()
.useShutDownButton()
.show();
}

private void setupDevDummyPaymentAccounts() {
if (user.getPaymentAccounts() != null && user.getPaymentAccounts().isEmpty()) {
AliPayAccount aliPayAccount = new AliPayAccount();
Expand Down

0 comments on commit 61d2026

Please sign in to comment.