Skip to content

Commit

Permalink
fixes checking for missing wallet data
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jul 20, 2024
1 parent 09fd871 commit 9b26682
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions core/src/main/java/haveno/core/trade/Trade.java
Original file line number Diff line number Diff line change
Expand Up @@ -2578,7 +2578,7 @@ else if (hasFailedTx && isPayoutPublished()) {
if (isConnectionRefused) forceRestartTradeWallet();
else {
boolean isWalletConnected = isWalletConnectedToDaemon();
if (!isShutDownStarted && wallet != null && isWalletConnected) {
if (wallet != null && !isShutDownStarted && isWalletConnected) {
log.warn("Error polling trade wallet for {} {}, errorMessage={}. Monerod={}", getClass().getSimpleName(), getShortId(), e.getMessage(), getXmrWalletService().getConnectionService().getConnection());
requestSwitchToNextBestConnection();
//e.printStackTrace();
Expand Down Expand Up @@ -2622,6 +2622,9 @@ private void recoverIfMissingWalletData() {
// force restart wallet
forceRestartTradeWallet();

// skip if payout published in the meantime
if (isPayoutPublished()) return;

// rescan blockchain with global daemon lock
synchronized (HavenoUtils.getDaemonLock()) {
Long timeout = null;
Expand Down Expand Up @@ -2651,11 +2654,14 @@ private void recoverIfMissingWalletData() {
// import multisig hex
log.warn("Importing multisig hex to recover wallet data for {} {}", getClass().getSimpleName(), getShortId());
importMultisigHex();

// poll wallet
doPollWallet();

// check again if missing data
if (isWalletMissingData()) throw new IllegalStateException("Wallet is still missing data after attempting recovery for " + getClass().getSimpleName() + " " + getShortId());
}
}

// check again after releasing lock
if (isWalletMissingData()) throw new IllegalStateException("Wallet is still missing data after attempting recovery for " + getClass().getSimpleName() + " " + getShortId());
}

private boolean isWalletMissingData() {
Expand All @@ -2670,6 +2676,8 @@ private boolean isWalletMissingData() {
return true;
}
if (wallet.getBalance().equals(BigInteger.ZERO)) {
doPollWallet(); // poll once more to be sure
if (isPayoutPublished()) return false; // payout can become published while checking balance
log.warn("Wallet balance is zero for {} {}", getClass().getSimpleName(), getId());
return true;
}
Expand Down

0 comments on commit 9b26682

Please sign in to comment.