Skip to content

Commit

Permalink
skip wallet polls if daemon not synced (#1080)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser authored Jun 30, 2024
1 parent c3b93b6 commit 1debdde
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion core/src/main/java/haveno/core/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -2404,8 +2404,10 @@ private void doPollWallet() {
// skip if deposit txs unknown or not requested
if (processModel.getMaker().getDepositTxHash() == null || processModel.getTaker().getDepositTxHash() == null || !isDepositRequested()) return;

// skip if daemon not synced
if (xmrConnectionService.getTargetHeight() == null || !xmrConnectionService.isSyncedWithinTolerance()) return;

// sync if wallet too far behind daemon
if (xmrConnectionService.getTargetHeight() == null) return;
if (walletHeight.get() < xmrConnectionService.getTargetHeight() - SYNC_EVERY_NUM_BLOCKS) syncWallet(false);

// update deposit txs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1803,12 +1803,18 @@ private void doPollWallet(boolean updateTxs) {
pollInProgress = true;
try {

// switch to best connection if daemon is too far behind
// skip if daemon not synced
MoneroDaemonInfo lastInfo = xmrConnectionService.getLastInfo();
if (lastInfo == null) {
log.warn("Last daemon info is null");
return;
}
if (!xmrConnectionService.isSyncedWithinTolerance()) {
log.warn("Monero daemon is not synced within tolerance, height={}, targetHeight={}", xmrConnectionService.chainHeightProperty().get(), xmrConnectionService.getTargetHeight());
return;
}

// switch to best connection if wallet is too far behind
if (wasWalletSynced && walletHeight.get() < xmrConnectionService.getTargetHeight() - NUM_BLOCKS_BEHIND_TOLERANCE && !Config.baseCurrencyNetwork().isTestnet()) {
log.warn("Updating connection because main wallet is {} blocks behind monerod, wallet height={}, monerod height={}", xmrConnectionService.getTargetHeight() - walletHeight.get(), walletHeight.get(), lastInfo.getHeight());
xmrConnectionService.switchToBestConnection();
Expand Down

0 comments on commit 1debdde

Please sign in to comment.