check if dispute payout published on submit failure, thread fixes

This commit is contained in:
woodser 2024-04-30 11:17:00 -04:00
parent a3f2cd875c
commit 467b678ea7
3 changed files with 14 additions and 10 deletions

View file

@ -758,6 +758,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
// create dispute closed message // create dispute closed message
TradePeer receiverPeer = receiver == trade.getBuyer() ? trade.getSeller() : trade.getBuyer(); TradePeer receiverPeer = receiver == trade.getBuyer() ? trade.getSeller() : trade.getBuyer();
boolean deferPublishPayout = !exists && receiver.getUnsignedPayoutTxHex() != null && receiverPeer.getUpdatedMultisigHex() != null && trade.getDisputeState().ordinal() >= Trade.DisputeState.ARBITRATOR_SAW_ARRIVED_DISPUTE_CLOSED_MSG.ordinal(); boolean deferPublishPayout = !exists && receiver.getUnsignedPayoutTxHex() != null && receiverPeer.getUpdatedMultisigHex() != null && trade.getDisputeState().ordinal() >= Trade.DisputeState.ARBITRATOR_SAW_ARRIVED_DISPUTE_CLOSED_MSG.ordinal();
log.info("deferPublishPayout = {} = {} && {} && {} && {}", deferPublishPayout, !exists, receiver.getUnsignedPayoutTxHex() != null, receiverPeer.getUpdatedMultisigHex() != null, trade.getDisputeState().ordinal() >= Trade.DisputeState.ARBITRATOR_SAW_ARRIVED_DISPUTE_CLOSED_MSG.ordinal());
DisputeClosedMessage disputeClosedMessage = new DisputeClosedMessage(disputeResult, DisputeClosedMessage disputeClosedMessage = new DisputeClosedMessage(disputeResult,
p2PService.getAddress(), p2PService.getAddress(),
UUID.randomUUID().toString(), UUID.randomUUID().toString(),
@ -856,7 +857,7 @@ public abstract class DisputeManager<T extends DisputeList<Dispute>> extends Sup
if (!trade.isPayoutPublished()) { if (!trade.isPayoutPublished()) {
// create unsigned dispute payout tx // create unsigned dispute payout tx
log.info("Creating unsigned dispute payout tx for trade {}", trade.getId()); if (updateState) log.info("Creating unsigned dispute payout tx for trade {}", trade.getId());
try { try {
// trade wallet must be synced // trade wallet must be synced

View file

@ -477,6 +477,7 @@ public final class ArbitrationManager extends DisputeManager<ArbitrationDisputeL
disputeTxSet.getTxs().get(0).setHash(txHashes.get(0)); // manually update hash which is known after signed disputeTxSet.getTxs().get(0).setHash(txHashes.get(0)); // manually update hash which is known after signed
break; break;
} catch (Exception e) { } catch (Exception e) {
if (trade.isPayoutPublished()) throw new IllegalStateException("Payout tx already published for " + trade.getClass().getSimpleName() + " " + trade.getShortId());
log.warn("Failed to submit dispute payout tx, attempt={}/{}, tradeId={}, error={}", i + 1, TradeProtocol.MAX_ATTEMPTS, trade.getShortId(), e.getMessage()); log.warn("Failed to submit dispute payout tx, attempt={}/{}, tradeId={}, error={}", i + 1, TradeProtocol.MAX_ATTEMPTS, trade.getShortId(), e.getMessage());
if (i == TradeProtocol.MAX_ATTEMPTS - 1) throw e; if (i == TradeProtocol.MAX_ATTEMPTS - 1) throw e;
HavenoUtils.waitFor(TradeProtocol.REPROCESS_DELAY_MS); // wait before retrying HavenoUtils.waitFor(TradeProtocol.REPROCESS_DELAY_MS); // wait before retrying

View file

@ -641,7 +641,7 @@ public abstract class Trade implements Tradable, Model {
// handle trade phase events // handle trade phase events
tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> { tradePhaseSubscription = EasyBind.subscribe(phaseProperty, newValue -> {
if (!isInitialized || isShutDownStarted) return; if (!isInitialized || isShutDownStarted) return;
ThreadUtils.execute(() -> { ThreadUtils.submitToPool(() -> {
if (newValue == Trade.Phase.DEPOSIT_REQUESTED) startPolling(); if (newValue == Trade.Phase.DEPOSIT_REQUESTED) startPolling();
if (isDepositsPublished() && !isPayoutUnlocked()) updatePollPeriod(); if (isDepositsPublished() && !isPayoutUnlocked()) updatePollPeriod();
if (isPaymentReceived()) { if (isPaymentReceived()) {
@ -652,13 +652,13 @@ public abstract class Trade implements Tradable, Model {
} }
}); });
} }
}, getId()); });
}); });
// handle payout events // handle payout events
payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> { payoutStateSubscription = EasyBind.subscribe(payoutStateProperty, newValue -> {
if (!isInitialized || isShutDownStarted) return; if (!isInitialized || isShutDownStarted) return;
ThreadUtils.execute(() -> { ThreadUtils.submitToPool(() -> {
if (isPayoutPublished()) updatePollPeriod(); if (isPayoutPublished()) updatePollPeriod();
// handle when payout published // handle when payout published
@ -666,11 +666,13 @@ public abstract class Trade implements Tradable, Model {
log.info("Payout published for {} {}", getClass().getSimpleName(), getId()); log.info("Payout published for {} {}", getClass().getSimpleName(), getId());
// sync main wallet to update pending balance // sync main wallet to update pending balance
new Thread(() -> { if (!isPayoutConfirmed()) {
HavenoUtils.waitFor(1000); new Thread(() -> {
if (isShutDownStarted) return; HavenoUtils.waitFor(1000);
if (xmrConnectionService.isConnected()) xmrWalletService.syncWallet(); if (isShutDownStarted) return;
}).start(); if (xmrConnectionService.isConnected()) syncAndPollWallet();
}).start();
}
// complete disputed trade // complete disputed trade
if (getDisputeState().isArbitrated() && !getDisputeState().isClosed()) { if (getDisputeState().isArbitrated() && !getDisputeState().isClosed()) {
@ -691,7 +693,7 @@ public abstract class Trade implements Tradable, Model {
log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId()); log.info("Payout unlocked for {} {}, deleting multisig wallet", getClass().getSimpleName(), getId());
clearAndShutDown(); clearAndShutDown();
} }
}, getId()); });
}); });
// arbitrator syncs idle wallet when payout unlock expected // arbitrator syncs idle wallet when payout unlock expected