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:
woodser 2024-06-21 10:30:27 -04:00
parent 4494af8bc0
commit 26a5ffcb31
3 changed files with 29 additions and 18 deletions

View file

@ -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 {
log.warn("Failed to fetch daemon info, trying to switch to best connection: " + e.getMessage()); // skip handling if shutting down
switchToBestConnection(); if (isShutDownStarted) return;
lastInfo = daemon.getInfo();
} catch (Exception e2) { // fallback to provided nodes if custom connection fails on startup
throw e2; // caught internally 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());
switchToBestConnection();
lastInfo = daemon.getInfo(); // caught internally if still fails
} }
// connected to daemon // connected to daemon

View file

@ -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);

View file

@ -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);