synchronize setting and getting trade start time (#1956)

This commit is contained in:
woodser 2025-09-14 23:52:30 -04:00 committed by GitHub
parent 46ccb9b925
commit 9aca42578f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -482,6 +482,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
private long lockTime;
@Setter
private long startTime; // added for haveno
private final Object startTimeLock = new Object();
@Getter
@Nullable
private RefundResultState refundResultState = RefundResultState.UNDEFINED_REFUND_RESULT;
@ -2334,6 +2335,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
}
public void maybeUpdateTradePeriod() {
synchronized (startTimeLock) {
if (startTime > 0) return; // already set
if (getTakeOfferDate() == null) return; // trade not started yet
if (!isDepositsFinalized()) return; // deposits not finalized yet
@ -2357,6 +2359,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
log.debug("We set the start for the trade period to {}. Trade started at: {}. Block got mined at: {}",
new Date(startTime), new Date(tradeTime), new Date(finalizeTime));
}
}
private long getDepositsFinalizedHeight() {
MoneroTxWallet makerDepositTx = getMakerDepositTx();
@ -2386,8 +2389,10 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
* Returns the current time until the deposits are finalized.
*/
private long getEffectiveStartTime() {
synchronized (startTimeLock) {
return startTime > 0 ? startTime : System.currentTimeMillis();
}
}
public boolean hasFailed() {
return errorMessageProperty().get() != null;
@ -2453,7 +2458,7 @@ public abstract class Trade extends XmrWalletBase implements Tradable, Model {
else {
Long minDepositTxConfirmations = getMinDepositTxConfirmations();
// TODO: state can be past finalized (e.g. payment_sent) before the deposits are finalized, ideally use separate enum for deposits
// TODO: state can be past finalized (e.g. payment_sent) before the deposits are finalized, ideally use separate enum for deposits, or a single published state + num confirmations
if (minDepositTxConfirmations == null) {
log.warn("Assuming that deposit txs are finalized for trade {} {} because trade is in phase {} but has unknown confirmations", getClass().getSimpleName(), getShortId(), getState().getPhase());
return true;