make deposits finalized state consistent with trade period

This commit is contained in:
woodser 2025-12-09 07:12:53 -05:00
parent 1027b613d3
commit d21897789e
No known key found for this signature in database
GPG key ID: 55A10DD48ADEE5EF

View file

@ -511,7 +511,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
private String payoutTxKey; private String payoutTxKey;
private long payoutTxFee; private long payoutTxFee;
private Long payoutHeight; private Long payoutHeight;
private IdlePayoutSyncer idlePayoutSyncer; private IdleSyncer idleSyncer;
@Getter @Getter
private boolean isCompleted; private boolean isCompleted;
@Getter @Getter
@ -765,9 +765,9 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
}); });
}); });
// listen to wallet events to sync when idling // listen to wallet events to sync while idling
idlePayoutSyncer = new IdlePayoutSyncer(); idleSyncer = new IdleSyncer();
xmrWalletService.addWalletListener(idlePayoutSyncer); xmrWalletService.addWalletListener(idleSyncer);
// TODO: buyer's payment sent message state property became unsynced if shut down while awaiting ack from seller. fixed mismatch in v1.0.19, but can this check be removed? // TODO: buyer's payment sent message state property became unsynced if shut down while awaiting ack from seller. fixed mismatch in v1.0.19, but can this check be removed?
if (isBuyer()) { if (isBuyer()) {
@ -1926,9 +1926,12 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
} }
private Long getDepositsNumConfirmations() { private Long getDepositsNumConfirmations() {
Long depositsConfirmedHeight = getDepositsConfirmedHeight(); MoneroTxWallet makerDepositTx = getMakerDepositTx();
if (depositsConfirmedHeight == null) return null; MoneroTxWallet takerDepositTx = getTakerDepositTx();
return walletHeight.get() - depositsConfirmedHeight + 1; if (makerDepositTx == null || (takerDepositTx == null && !hasBuyerAsTakerWithoutDeposit())) return null;
if (Boolean.TRUE.equals(makerDepositTx.isFailed()) || (takerDepositTx != null && Boolean.TRUE.equals(takerDepositTx.isFailed()))) return null;
if (makerDepositTx.getHeight() == null || (takerDepositTx != null && takerDepositTx.getHeight() == null)) return null;
return hasBuyerAsTakerWithoutDeposit() ? makerDepositTx.getNumConfirmations() : Math.min(makerDepositTx.getNumConfirmations(), takerDepositTx.getNumConfirmations());
} }
private Long getDepositsConfirmedHeight() { private Long getDepositsConfirmedHeight() {
@ -2096,9 +2099,9 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
} }
// de-initialize // de-initialize
if (idlePayoutSyncer != null) { if (idleSyncer != null) {
xmrWalletService.removeWalletListener(idlePayoutSyncer); xmrWalletService.removeWalletListener(idleSyncer);
idlePayoutSyncer = null; idleSyncer = null;
} }
UserThread.execute(() -> { UserThread.execute(() -> {
if (tradeStateSubscription != null) tradeStateSubscription.unsubscribe(); if (tradeStateSubscription != null) tradeStateSubscription.unsubscribe();
@ -2747,8 +2750,9 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
Thread.dumpStack(); Thread.dumpStack();
} }
return true; return true;
} else {
return numDepositsConfirmations >= NUM_BLOCKS_DEPOSITS_FINALIZED;
} }
return numDepositsConfirmations >= NUM_BLOCKS_DEPOSITS_FINALIZED;
} }
} }
@ -3843,9 +3847,9 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
/** /**
* Listen to block notifications from the main wallet in order to sync * Listen to block notifications from the main wallet in order to sync
* idling trade wallets awaiting the payout to confirm or unlock. * idling trade wallets if necessary.
*/ */
private class IdlePayoutSyncer extends MoneroWalletListener { private class IdleSyncer extends MoneroWalletListener {
boolean processing = false; boolean processing = false;
@ -3857,8 +3861,8 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
if (processing) return; if (processing) return;
processing = true; processing = true;
// skip if not idling and not waiting for payout to finalize // skip if not idling or not waiting for finalization
if (!isIdling() || !isPayoutPublished() || isPayoutFinalized()) { if (!isIdling() || (isDepositsFinalized() && (!isPayoutPublished() || isPayoutFinalized()))) {
processing = false; processing = false;
return; return;
} }
@ -3874,10 +3878,12 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
// sync wallet if confirm, unlock, or finalize expected // sync wallet if confirm, unlock, or finalize expected
long currentHeight = xmrWalletService.getMonerod().getHeight(); long currentHeight = xmrWalletService.getMonerod().getHeight();
if (!isPayoutConfirmed() || (payoutHeight != null && if (!isPayoutConfirmed() ||
(!isDepositsFinalized() && (currentHeight - getDepositsConfirmedHeight() >= NUM_BLOCKS_DEPOSITS_FINALIZED)) ||
(payoutHeight != null &&
((!isPayoutUnlocked() && currentHeight >= payoutHeight + XmrWalletService.NUM_BLOCKS_UNLOCK) || ((!isPayoutUnlocked() && currentHeight >= payoutHeight + XmrWalletService.NUM_BLOCKS_UNLOCK) ||
(!isPayoutFinalized() && currentHeight >= payoutHeight + NUM_BLOCKS_PAYOUT_FINALIZED)))) { (!isPayoutFinalized() && currentHeight >= payoutHeight + NUM_BLOCKS_PAYOUT_FINALIZED)))) {
log.info("Syncing idle trade wallet to update payout for {} {}", getTrade().getClass().getSimpleName(), getId()); log.info("Syncing idle trade wallet for {} {}", getTrade().getClass().getSimpleName(), getId());
syncAndPollWallet(); syncAndPollWallet();
} }
processing = false; processing = false;