Skip to content

Commit

Permalink
fixes to sync with progress start and target height
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Aug 7, 2024
1 parent e10f764 commit 0644d0b
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions core/src/main/java/haveno/core/xmr/wallet/XmrWalletBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ public void syncWithProgress(boolean repeatSyncToLatestHeight) {
// set initial state
isSyncingWithProgress = true;
syncProgressError = null;
updateSyncProgress(walletHeight.get());
long targetHeightAtStart = xmrConnectionService.getTargetHeight();
syncStartHeight = walletHeight.get();
updateSyncProgress(syncStartHeight, targetHeightAtStart);

// test connection changing on startup before wallet synced
if (testReconnectOnStartup) {
Expand All @@ -88,7 +89,8 @@ public void syncWithProgress(boolean repeatSyncToLatestHeight) {
wallet.sync(new MoneroWalletListener() {
@Override
public void onSyncProgress(long height, long startHeight, long endHeight, double percentDone, String message) {
updateSyncProgress(height);
long appliedTargetHeight = repeatSyncToLatestHeight ? xmrConnectionService.getTargetHeight() : targetHeightAtStart;
updateSyncProgress(height, appliedTargetHeight);
}
});
setWalletSyncedWithProgress();
Expand All @@ -111,8 +113,9 @@ public void onSyncProgress(long height, long startHeight, long endHeight, double
syncProgressLatch.countDown();
return;
}
updateSyncProgress(height);
if (height >= (repeatSyncToLatestHeight ? xmrConnectionService.getTargetHeight() : targetHeightAtStart)) {
long appliedTargetHeight = repeatSyncToLatestHeight ? xmrConnectionService.getTargetHeight() : targetHeightAtStart;
updateSyncProgress(height, appliedTargetHeight);
if (height >= appliedTargetHeight) {
setWalletSyncedWithProgress();
syncProgressLatch.countDown();
}
Expand All @@ -132,7 +135,7 @@ public void onSyncProgress(long height, long startHeight, long endHeight, double
}
}

private void updateSyncProgress(long height) {
private void updateSyncProgress(long height, long targetHeight) {
resetSyncProgressTimeout();
UserThread.execute(() -> {

Expand All @@ -141,12 +144,11 @@ private void updateSyncProgress(long height) {

// new wallet reports height 1 before synced
if (height == 1) {
downloadListener.progress(0, xmrConnectionService.getTargetHeight() - height, null);
downloadListener.progress(0, targetHeight - height, null);
return;
}

// set progress
long targetHeight = xmrConnectionService.getTargetHeight();
long blocksLeft = targetHeight - walletHeight.get();
if (syncStartHeight == null) syncStartHeight = walletHeight.get();
double percent = Math.min(1.0, targetHeight == syncStartHeight ? 1.0 : ((double) walletHeight.get() - syncStartHeight) / (double) (targetHeight - syncStartHeight));
Expand Down

0 comments on commit 0644d0b

Please sign in to comment.