process trade state notifications off UserThread

This commit is contained in:
woodser 2024-01-02 07:53:06 -05:00
parent 43bbb29384
commit e7371d1299
3 changed files with 71 additions and 56 deletions

View File

@ -263,8 +263,11 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
// wait to sign and publish payout tx if defer flag set // wait to sign and publish payout tx if defer flag set
if (disputeClosedMessage.isDeferPublishPayout()) { if (disputeClosedMessage.isDeferPublishPayout()) {
log.info("Deferring signing and publishing dispute payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId()); log.info("Deferring signing and publishing dispute payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS); for (int i = 0; i < 5; i++) {
if (!trade.isPayoutUnlocked()) trade.syncAndPollWallet(); if (trade.isPayoutPublished()) break;
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS / 5);
}
if (!trade.isPayoutPublished()) trade.syncAndPollWallet();
} }
// sign and publish dispute payout tx if peer still has not published // sign and publish dispute payout tx if peer still has not published

View File

@ -621,14 +621,17 @@ public abstract class Trade implements Tradable, Model {
// handle trade state events // handle trade state events
tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> { tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> {
HavenoUtils.submitToThread(() -> {
if (newValue == Trade.State.MULTISIG_COMPLETED) { if (newValue == Trade.State.MULTISIG_COMPLETED) {
updateWalletRefreshPeriod(); updateWalletRefreshPeriod();
startPolling(); startPolling();
} }
}, getId());
}); });
// handle trade phase events // handle trade phase events
tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> { tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> {
HavenoUtils.submitToThread(() -> {
if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod(); if (isDepositsPublished() && !isPayoutUnlocked()) updateWalletRefreshPeriod();
if (isPaymentReceived()) { if (isPaymentReceived()) {
UserThread.execute(() -> { UserThread.execute(() -> {
@ -638,10 +641,12 @@ public abstract class Trade implements Tradable, Model {
} }
}); });
} }
}, getId());
}); });
// handle payout events // handle payout events
payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> { payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> {
HavenoUtils.submitToThread(() -> {
if (isPayoutPublished()) updateWalletRefreshPeriod(); if (isPayoutPublished()) updateWalletRefreshPeriod();
// handle when payout published // handle when payout published
@ -672,6 +677,7 @@ public abstract class Trade implements Tradable, Model {
if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) { if (newValue == Trade.PayoutState.PAYOUT_UNLOCKED) {
if (!isInitialized) return; if (!isInitialized) return;
log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId()); log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId());
HavenoUtils.submitToThread(() -> {
deleteWallet(); deleteWallet();
maybeClearProcessData(); maybeClearProcessData();
if (idlePayoutSyncer != null) { if (idlePayoutSyncer != null) {
@ -684,7 +690,10 @@ public abstract class Trade implements Tradable, Model {
payoutStateSubscription = null; payoutStateSubscription = null;
} }
}); });
}, getId());
} }
}, getId());
}); });
// arbitrator syncs idle wallet when payout unlock expected // arbitrator syncs idle wallet when payout unlock expected

View File

@ -128,8 +128,11 @@ public class ProcessPaymentReceivedMessage extends TradeTask {
boolean deferSignAndPublish = trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout(); boolean deferSignAndPublish = trade instanceof ArbitratorTrade && !isSigned && message.isDeferPublishPayout();
if (deferSignAndPublish) { if (deferSignAndPublish) {
log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId()); log.info("Deferring signing and publishing payout tx for {} {}", trade.getClass().getSimpleName(), trade.getId());
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS); for (int i = 0; i < 5; i++) {
if (!trade.isPayoutUnlocked()) trade.syncAndPollWallet(); if (trade.isPayoutPublished()) break;
GenUtils.waitFor(Trade.DEFER_PUBLISH_MS / 5);
}
if (!trade.isPayoutPublished()) trade.syncAndPollWallet();
} }
// verify and publish payout tx // verify and publish payout tx