restart attempts to sync main wallet on init failure
This commit is contained in:
parent
371504b849
commit
22ddf0999f
@ -653,13 +653,14 @@ public class XmrWalletService {
|
||||
private void initialize() {
|
||||
|
||||
// initialize main wallet if connected or previously created
|
||||
maybeInitMainWallet();
|
||||
maybeInitMainWallet(true);
|
||||
|
||||
// set and listen to daemon connection
|
||||
connectionsService.addConnectionListener(newConnection -> onConnectionChanged(newConnection));
|
||||
}
|
||||
|
||||
private synchronized void maybeInitMainWallet() {
|
||||
private void maybeInitMainWallet(boolean sync) {
|
||||
synchronized (walletLock) {
|
||||
|
||||
// open or create wallet main wallet
|
||||
if (wallet == null) {
|
||||
@ -673,12 +674,12 @@ public class XmrWalletService {
|
||||
}
|
||||
}
|
||||
|
||||
// sync wallet if open
|
||||
// sync wallet and register listener
|
||||
if (wallet != null) {
|
||||
log.info("Monero wallet uri={}, path={}", wallet.getRpcConnection().getUri(), wallet.getPath());
|
||||
int numAttempts = 0;
|
||||
if (sync) {
|
||||
int maxAttempts = 3;
|
||||
while (!HavenoUtils.havenoSetup.getWalletInitialized().get()) {
|
||||
for (int i = 0; i < maxAttempts; i++) {
|
||||
try {
|
||||
|
||||
// sync main wallet
|
||||
@ -699,17 +700,25 @@ public class XmrWalletService {
|
||||
|
||||
// save but skip backup on initialization
|
||||
saveMainWallet(false);
|
||||
break;
|
||||
} catch (Exception e) {
|
||||
log.warn("Error syncing main wallet: {}", e.getMessage());
|
||||
numAttempts++;
|
||||
if (numAttempts < maxAttempts) {
|
||||
log.warn("Trying again in {} seconds", connectionsService.getRefreshPeriodMs() / 1000);
|
||||
GenUtils.waitFor(connectionsService.getRefreshPeriodMs());
|
||||
} else {
|
||||
if (i == maxAttempts - 1) {
|
||||
log.warn("Failed to sync main wallet after {} attempts. Opening app without syncing", maxAttempts);
|
||||
HavenoUtils.havenoSetup.getWalletInitialized().set(true);
|
||||
saveMainWallet(false);
|
||||
break;
|
||||
|
||||
// reschedule to init main wallet
|
||||
UserThread.runAfter(() -> {
|
||||
new Thread(() -> {
|
||||
log.warn("Restarting attempts to sync main wallet");
|
||||
maybeInitMainWallet(true);
|
||||
});
|
||||
}, connectionsService.getRefreshPeriodMs() / 1000);
|
||||
} else {
|
||||
log.warn("Trying again in {} seconds", connectionsService.getRefreshPeriodMs() / 1000);
|
||||
GenUtils.waitFor(connectionsService.getRefreshPeriodMs());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -718,6 +727,7 @@ public class XmrWalletService {
|
||||
wallet.addListener(new XmrWalletListener());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private MoneroWalletRpc createWalletRpc(MoneroWalletConfig config, Integer port) {
|
||||
|
||||
@ -823,11 +833,11 @@ public class XmrWalletService {
|
||||
log.info("Setting main wallet daemon connection: " + (connection == null ? null : connection.getUri()));
|
||||
String oldProxyUri = wallet == null || wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getProxyUri();
|
||||
String newProxyUri = connection == null ? null : connection.getProxyUri();
|
||||
if (wallet == null) maybeInitMainWallet();
|
||||
if (wallet == null) maybeInitMainWallet(false);
|
||||
else if (wallet instanceof MoneroWalletRpc && !StringUtils.equals(oldProxyUri, newProxyUri)) {
|
||||
log.info("Restarting main wallet because proxy URI has changed");
|
||||
closeMainWallet(true);
|
||||
maybeInitMainWallet();
|
||||
maybeInitMainWallet(false);
|
||||
} else {
|
||||
wallet.setDaemonConnection(connection);
|
||||
}
|
||||
@ -907,8 +917,6 @@ public class XmrWalletService {
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------- LEGACY APP -------------------------------
|
||||
|
||||
public synchronized XmrAddressEntry getNewAddressEntry() {
|
||||
return getNewAddressEntryAux(null, XmrAddressEntry.Context.AVAILABLE);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user