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