avoid blocking by checking if wallet exists without lock

This commit is contained in:
woodser 2025-09-27 00:35:49 -04:00 committed by woodser
parent 1a3bee0300
commit 60ee90f53b
3 changed files with 8 additions and 6 deletions

View file

@ -70,7 +70,7 @@ public abstract class SellerTrade extends Trade {
public boolean needsToResendPaymentReceivedMessages() { public boolean needsToResendPaymentReceivedMessages() {
boolean hasNoPaymentReceivedMessages = getBuyer().getPaymentReceivedMessage() == null && getArbitrator().getPaymentReceivedMessage() == null; boolean hasNoPaymentReceivedMessages = getBuyer().getPaymentReceivedMessage() == null && getArbitrator().getPaymentReceivedMessage() == null;
if (!walletExists() && !hasNoPaymentReceivedMessages) return false; // cannot provide any updated state if (!walletExistsNoSync() && !hasNoPaymentReceivedMessages) return false; // cannot provide any updated state
return !isShutDownStarted() && getState().ordinal() >= Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG.ordinal() && !getProcessModel().isPaymentReceivedMessagesAckedOrStored() && resendPaymentReceivedMessagesEnabled() && resendPaymentReceivedMessagesWithinDuration(); return !isShutDownStarted() && getState().ordinal() >= Trade.State.SELLER_SENT_PAYMENT_RECEIVED_MSG.ordinal() && !getProcessModel().isPaymentReceivedMessagesAckedOrStored() && resendPaymentReceivedMessagesEnabled() && resendPaymentReceivedMessagesWithinDuration();
} }

View file

@ -823,7 +823,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
// Note that this function is overriden by subclasses. // Note that this function is overriden by subclasses.
public boolean isFinished() { public boolean isFinished() {
if (!isCompleted()) return false; if (!isCompleted()) return false;
if (isPayoutUnlocked() && !walletExists()) return true; if (isPayoutUnlocked() && !walletExistsNoSync()) return true;
return isPayoutFinalized(); return isPayoutFinalized();
} }
@ -909,7 +909,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
} }
} }
private boolean walletExistsNoSync() { protected boolean walletExistsNoSync() {
return xmrWalletService.walletExists(getWalletName()); return xmrWalletService.walletExists(getWalletName());
} }
@ -958,7 +958,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
public boolean isIdling() { public boolean isIdling() {
if (isPayoutUnlocked()) return true; // idle after payout unlocked if (isPayoutUnlocked()) return true; // idle after payout unlocked
return this instanceof ArbitratorTrade && isDepositsConfirmed() && walletExists() && pollNormalStartTimeMs == null; // arbitrator idles trade after deposits confirm unless overriden return this instanceof ArbitratorTrade && isDepositsConfirmed() && walletExistsNoSync() && pollNormalStartTimeMs == null; // arbitrator idles trade after deposits confirm unless overriden
} }
public boolean isSyncedWithinTolerance() { public boolean isSyncedWithinTolerance() {

View file

@ -1901,8 +1901,10 @@ public class XmrWalletService extends XmrWalletBase {
List<Trade> trades = tradeManager.getAllTrades(); List<Trade> trades = tradeManager.getAllTrades();
for (Trade trade : trades) { for (Trade trade : trades) {
tasks.add(() -> { tasks.add(() -> {
if (trade.walletExists()) { synchronized (trade.getWalletLock()) {
trade.changeWalletPassword(oldPassword, newPassword); // TODO (woodser): this unnecessarily connects and syncs unopen wallets and leaves open if (trade.walletExists()) {
trade.changeWalletPassword(oldPassword, newPassword); // TODO (woodser): this unnecessarily connects and syncs unopen wallets and leaves open
}
} }
}); });
} }