Skip to content

Commit

Permalink
call wallet.sync() on startup after background sync with progress
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Dec 9, 2023
1 parent af2691d commit e4ddf58
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions core/src/main/java/haveno/core/xmr/wallet/XmrWalletService.java
Original file line number Diff line number Diff line change
Expand Up @@ -737,9 +737,13 @@ private void maybeInitMainWallet(boolean sync, int numAttempts) {
long time = System.currentTimeMillis();
syncWalletWithProgress(); // blocking
log.info("Done syncing main wallet in " + (System.currentTimeMillis() - time) + " ms");
wallet.startSyncing(xmrConnectionService.getRefreshPeriodMs());
wallet.getTxs(new MoneroTxQuery().setIsLocked(true)); // TODO: main wallet's balance does update on startup with 0 conf PaymentReceivedMessage until pool txs fetched?
if (getMoneroNetworkType() != MoneroNetworkType.MAINNET) log.info("Monero wallet balance={}, unlocked balance={}", wallet.getBalance(0), wallet.getUnlockedBalance(0));

// log wallet balances
if (getMoneroNetworkType() != MoneroNetworkType.MAINNET) {
BigInteger balance = wallet.getBalance();
BigInteger unlockedBalance = wallet.getUnlockedBalance();
log.info("Monero wallet unlocked balance={}, pending balance={}, total balance={}", unlockedBalance, balance.subtract(unlockedBalance), balance);
}

// reapply connection after wallet synced
onConnectionChanged(xmrConnectionService.getConnection());
Expand Down Expand Up @@ -782,14 +786,15 @@ private void maybeInitMainWallet(boolean sync, int numAttempts) {

private void syncWalletWithProgress() {
updateSyncProgress();
wallet.startSyncing();
wallet.startSyncing(xmrConnectionService.getRefreshPeriodMs());
CountDownLatch latch = new CountDownLatch(1);
syncLooper = new TaskLooper(() -> {
if (wallet.getHeight() < xmrConnectionService.getTargetHeight()) updateSyncProgress();
else {
syncLooper.stop();
wallet.sync(); // necessary to fully sync
wasWalletSynced = true;
updateSyncProgress();
syncLooper.stop();
latch.countDown();
}
});
Expand Down

0 comments on commit e4ddf58

Please sign in to comment.