mirror of
https://github.com/haveno-dex/haveno.git
synced 2025-01-03 17:40:10 +00:00
fallback from custom node to provided nodes on startup error #923
Co-authored-by: nsec1 <167650977+nsec1@users.noreply.github.com>
This commit is contained in:
parent
4494af8bc0
commit
26a5ffcb31
3 changed files with 29 additions and 18 deletions
|
@ -557,6 +557,7 @@ public final class XmrConnectionService {
|
||||||
|
|
||||||
// update polling
|
// update polling
|
||||||
doPollDaemon();
|
doPollDaemon();
|
||||||
|
if (currentConnection != getConnection()) return; // polling can change connection
|
||||||
UserThread.runAfter(() -> updatePolling(), getRefreshPeriodMs() / 1000);
|
UserThread.runAfter(() -> updatePolling(), getRefreshPeriodMs() / 1000);
|
||||||
|
|
||||||
// notify listeners in parallel
|
// notify listeners in parallel
|
||||||
|
@ -607,13 +608,22 @@ public final class XmrConnectionService {
|
||||||
try {
|
try {
|
||||||
lastInfo = daemon.getInfo();
|
lastInfo = daemon.getInfo();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
try {
|
|
||||||
|
// skip handling if shutting down
|
||||||
|
if (isShutDownStarted) return;
|
||||||
|
|
||||||
|
// fallback to provided nodes if custom connection fails on startup
|
||||||
|
if (lastInfo == null && "".equals(config.xmrNode) && preferences.getMoneroNodesOption() == XmrNodes.MoneroNodesOption.CUSTOM) {
|
||||||
|
log.warn("Failed to fetch daemon info from custom node on startup, falling back to provided nodes: " + e.getMessage());
|
||||||
|
preferences.setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.PROVIDED.ordinal());
|
||||||
|
initializeConnections();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// switch to best connection
|
||||||
log.warn("Failed to fetch daemon info, trying to switch to best connection: " + e.getMessage());
|
log.warn("Failed to fetch daemon info, trying to switch to best connection: " + e.getMessage());
|
||||||
switchToBestConnection();
|
switchToBestConnection();
|
||||||
lastInfo = daemon.getInfo();
|
lastInfo = daemon.getInfo(); // caught internally if still fails
|
||||||
} catch (Exception e2) {
|
|
||||||
throw e2; // caught internally
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// connected to daemon
|
// connected to daemon
|
||||||
|
|
|
@ -262,11 +262,11 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
cssThemeProperty.set(prefPayload.getCssTheme());
|
cssThemeProperty.set(prefPayload.getCssTheme());
|
||||||
|
|
||||||
|
|
||||||
// if no valid Bitcoin block explorer is set, select the 1st valid Bitcoin block explorer
|
// if no valid Monero block explorer is set, select the 1st valid Monero block explorer
|
||||||
ArrayList<BlockChainExplorer> btcExplorers = getBlockChainExplorers();
|
ArrayList<BlockChainExplorer> xmrExplorers = getBlockChainExplorers();
|
||||||
if (getBlockChainExplorer() == null ||
|
if (getBlockChainExplorer() == null ||
|
||||||
getBlockChainExplorer().name.length() == 0) {
|
getBlockChainExplorer().name.length() == 0) {
|
||||||
setBlockChainExplorer(btcExplorers.get(0));
|
setBlockChainExplorer(xmrExplorers.get(0));
|
||||||
}
|
}
|
||||||
tradeCurrenciesAsObservable.addAll(prefPayload.getTraditionalCurrencies());
|
tradeCurrenciesAsObservable.addAll(prefPayload.getTraditionalCurrencies());
|
||||||
tradeCurrenciesAsObservable.addAll(prefPayload.getCryptoCurrencies());
|
tradeCurrenciesAsObservable.addAll(prefPayload.getCryptoCurrencies());
|
||||||
|
@ -278,8 +278,8 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
|
|
||||||
if (xmrNodesFromOptions != null && !xmrNodesFromOptions.isEmpty()) {
|
if (xmrNodesFromOptions != null && !xmrNodesFromOptions.isEmpty()) {
|
||||||
if (getMoneroNodes() != null && !getMoneroNodes().equals(xmrNodesFromOptions)) {
|
if (getMoneroNodes() != null && !getMoneroNodes().equals(xmrNodesFromOptions)) {
|
||||||
log.warn("The Bitcoin node(s) from the program argument and the one(s) persisted in the UI are different. " +
|
log.warn("The Monero node(s) from the program argument and the one(s) persisted in the UI are different. " +
|
||||||
"The Bitcoin node(s) {} from the program argument will be used.", xmrNodesFromOptions);
|
"The Monero node(s) {} from the program argument will be used.", xmrNodesFromOptions);
|
||||||
}
|
}
|
||||||
setMoneroNodes(xmrNodesFromOptions);
|
setMoneroNodes(xmrNodesFromOptions);
|
||||||
setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.CUSTOM.ordinal());
|
setMoneroNodesOptionOrdinal(XmrNodes.MoneroNodesOption.CUSTOM.ordinal());
|
||||||
|
@ -567,8 +567,8 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoneroNodes(String bitcoinNodes) {
|
public void setMoneroNodes(String moneroNodes) {
|
||||||
prefPayload.setMoneroNodes(bitcoinNodes);
|
prefPayload.setMoneroNodes(moneroNodes);
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -658,8 +658,8 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMoneroNodesOptionOrdinal(int bitcoinNodesOptionOrdinal) {
|
public void setMoneroNodesOptionOrdinal(int moneroNodesOptionOrdinal) {
|
||||||
prefPayload.setMoneroNodesOptionOrdinal(bitcoinNodesOptionOrdinal);
|
prefPayload.setMoneroNodesOptionOrdinal(moneroNodesOptionOrdinal);
|
||||||
requestPersistence();
|
requestPersistence();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -892,7 +892,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
|
|
||||||
void setSortMarketCurrenciesNumerically(boolean sortMarketCurrenciesNumerically);
|
void setSortMarketCurrenciesNumerically(boolean sortMarketCurrenciesNumerically);
|
||||||
|
|
||||||
void setMoneroNodes(String bitcoinNodes);
|
void setMoneroNodes(String moneroNodes);
|
||||||
|
|
||||||
void setUseCustomWithdrawalTxFee(boolean useCustomWithdrawalTxFee);
|
void setUseCustomWithdrawalTxFee(boolean useCustomWithdrawalTxFee);
|
||||||
|
|
||||||
|
@ -926,7 +926,7 @@ public final class Preferences implements PersistedDataHost, BridgeAddressProvid
|
||||||
|
|
||||||
void setUseTorForXmrOrdinal(int useTorForXmrOrdinal);
|
void setUseTorForXmrOrdinal(int useTorForXmrOrdinal);
|
||||||
|
|
||||||
void setMoneroNodesOptionOrdinal(int bitcoinNodesOption);
|
void setMoneroNodesOptionOrdinal(int moneroNodesOption);
|
||||||
|
|
||||||
void setReferralId(String referralId);
|
void setReferralId(String referralId);
|
||||||
|
|
||||||
|
|
|
@ -1545,6 +1545,7 @@ public class XmrWalletService {
|
||||||
// open wallet
|
// open wallet
|
||||||
config.setNetworkType(getMoneroNetworkType());
|
config.setNetworkType(getMoneroNetworkType());
|
||||||
config.setServer(connection);
|
config.setServer(connection);
|
||||||
|
log.info("Opening full wallet " + config.getPath() + " with monerod=" + connection.getUri());
|
||||||
walletFull = MoneroWalletFull.openWallet(config);
|
walletFull = MoneroWalletFull.openWallet(config);
|
||||||
if (walletFull.getDaemonConnection() != null) walletFull.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE);
|
if (walletFull.getDaemonConnection() != null) walletFull.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE);
|
||||||
log.info("Done opening full wallet " + config.getPath());
|
log.info("Done opening full wallet " + config.getPath());
|
||||||
|
@ -1604,7 +1605,7 @@ public class XmrWalletService {
|
||||||
if (!applyProxyUri) connection.setProxyUri(null);
|
if (!applyProxyUri) connection.setProxyUri(null);
|
||||||
|
|
||||||
// open wallet
|
// open wallet
|
||||||
log.info("Opening RPC wallet " + config.getPath() + " connected to daemon " + connection.getUri());
|
log.info("Opening RPC wallet " + config.getPath() + " with monerod=" + connection.getUri());
|
||||||
config.setServer(connection);
|
config.setServer(connection);
|
||||||
walletRpc.openWallet(config);
|
walletRpc.openWallet(config);
|
||||||
if (walletRpc.getDaemonConnection() != null) walletRpc.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE);
|
if (walletRpc.getDaemonConnection() != null) walletRpc.getDaemonConnection().setPrintStackTrace(PRINT_RPC_STACK_TRACE);
|
||||||
|
|
Loading…
Reference in a new issue