diff --git a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java index 9af214c8..4802d7c8 100644 --- a/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java +++ b/core/src/main/java/haveno/core/support/dispute/arbitration/ArbitrationManager.java @@ -263,8 +263,11 @@ public final class ArbitrationManager extends DisputeManager { - if (newValue == Trade.State.MULTISIG_COMPLETED) { - updateWalletRefreshPeriod(); - startPolling(); - } + HavenoUtils.submitToThread(() -> { + if (newValue == Trade.State.MULTISIG_COMPLETED) { + updateWalletRefreshPeriod(); + startPolling(); + } + }, getId()); }); // handle trade phase events tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> { - if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod(); - if (isPaymentReceived()) { - UserThread.execute(() -> { - if (tradePhaseSubscription != null) { - tradePhaseSubscription.unsubscribe(); - tradePhaseSubscription = null; - } - }); - } + HavenoUtils.submitToThread(() -> { + if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod(); + if (isPaymentReceived()) { + UserThread.execute(() -> { + if (tradePhaseSubscription != null) { + tradePhaseSubscription.unsubscribe(); + tradePhaseSubscription = null; + } + }); + } + }, getId()); }); // handle payout events payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> { - if (isPayoutPublished()) updateWalletRefreshPeriod(); + HavenoUtils.submitToThread(() -> { + if (isPayoutPublished()) updateWalletRefreshPeriod(); - // handle when payout published - if (newValue == Trade.PayoutState.PAYOUT_PUBLISHED) { - log.info("Payout published for {} {}", getClass().getSimpleName(), getId()); + // handle when payout published + if (newValue == Trade.PayoutState.PAYOUT_PUBLISHED) { + log.info("Payout published for {} {}", getClass().getSimpleName(), getId()); - // sync main wallet to update pending balance - new Thread(() -> { - GenUtils.waitFor(1000); - if (isShutDownStarted) return; - if (Boolean.TRUE.equals(xmrConnectionService.isConnected())) xmrWalletService.syncWallet(xmrWalletService.getWallet()); - }).start(); + // sync main wallet to update pending balance + new Thread(() -> { + GenUtils.waitFor(1000); + if (isShutDownStarted) return; + if (Boolean.TRUE.equals(xmrConnectionService.isConnected())) xmrWalletService.syncWallet(xmrWalletService.getWallet()); + }).start(); - // complete disputed trade - if (getDisputeState().isArbitrated() && !getDisputeState().isClosed()) { - processModel.getTradeManager().closeDisputedTrade(getId(), Trade.DisputeState.DISPUTE_CLOSED); - if (!isArbitrator()) for (Dispute dispute : getDisputes()) dispute.setIsClosed(); // auto close trader tickets - } - - // auto complete arbitrator trade - if (isArbitrator() && !isCompleted()) processModel.getTradeManager().onTradeCompleted(this); - - // reset address entries - processModel.getXmrWalletService().resetAddressEntriesForTrade(getId()); - } - - // handle when payout unlocks - if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) { - if (!isInitialized) return; - log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId()); - deleteWallet(); - maybeClearProcessData(); - if (idlePayoutSyncer != null) { - xmrWalletService.removeWalletListener(idlePayoutSyncer); - idlePayoutSyncer = null; - } - UserThread.execute(() -> { - if (payoutStateSubscription != null) { - payoutStateSubscription.unsubscribe(); - payoutStateSubscription = null; + // complete disputed trade + if (getDisputeState().isArbitrated() && !getDisputeState().isClosed()) { + processModel.getTradeManager().closeDisputedTrade(getId(), Trade.DisputeState.DISPUTE_CLOSED); + if (!isArbitrator()) for (Dispute dispute : getDisputes()) dispute.setIsClosed(); // auto close trader tickets } - }); - } + + // auto complete arbitrator trade + if (isArbitrator() && !isCompleted()) processModel.getTradeManager().onTradeCompleted(this); + + // reset address entries + processModel.getXmrWalletService().resetAddressEntriesForTrade(getId()); + } + + // handle when payout unlocks + if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) { + if (!isInitialized) return; + log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId()); + HavenoUtils.submitToThread(() -> { + deleteWallet(); + maybeClearProcessData(); + if (idlePayoutSyncer != null) { + xmrWalletService.removeWalletListener(idlePayoutSyncer); + idlePayoutSyncer = null; + } + UserThread.execute(() -> { + if (payoutStateSubscription != null) { + payoutStateSubscription.unsubscribe(); + payoutStateSubscription = null; + } + }); + }, getId()); + + } + }, getId()); }); // arbitrator syncs idle wallet when payout unlock expected diff --git a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java index 77eda0a1..5e5c8776 100644 --- a/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java +++ b/core/src/main/java/haveno/core/trade/protocol/tasks/ProcessPaymentReceivedMessage.java @@ -128,8 +128,11 @@ public class ProcessPaymentReceivedMessage extends TradeTask { boolean deferSignAndPublish = trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout(); if (deferSignAndPublish) { log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId()); - GenUtils.waitFor(Trade.DEFER_PUBLISH_MS); - if (!trade.isPayoutUnlocked()) trade.syncAndPollWallet(); + for (int i = 0; i < 5; i++) { + if (trade.isPayoutPublished()) break; + GenUtils.waitFor(Trade.DEFER_PUBLISH_MS / 5); + } + if (!trade.isPayoutPublished()) trade.syncAndPollWallet(); } // verify and publish payout tx