Skip to content

Commit fb59cfb

Browse files
committed
check if trade state needs reset after wallet synced on startup
1 parent 72f8d34 commit fb59cfb

File tree

2 files changed

+27
-22
lines changed

2 files changed

+27
-22
lines changed

core/src/main/java/haveno/core/trade/Trade.java

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -639,21 +639,24 @@ public void initialize(ProcessModelServiceProvider serviceProvider) {
639639
ThreadUtils.execute(() -> onConnectionChanged(connection), getId());
640640
});
641641

642-
// reset states if no ack receive
643-
if (!isPayoutPublished()) {
644-
645-
// reset buyer's payment sent state if no ack receive
646-
if (this instanceof BuyerTrade && getState().ordinal() >= Trade.State.BUYER_CONFIRMED_PAYMENT_SENT.ordinal() && (getState().ordinal() < Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG.ordinal() || getState() == Trade.State.BUYER_SAW_ARRIVED_PAYMENT_SENT_MSG)) {
647-
log.warn("Resetting state of {} {} from {} to {} because no ack was received", getClass().getSimpleName(), getId(), getState(), Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
648-
setState(Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
649-
}
650-
651-
// reset seller's payment received state if no ack receive
652-
if (this instanceof SellerTrade && getState().ordinal() >= Trade.State.SELLER_CONFIRMED_PAYMENT_RECEIPT.ordinal() && (getState().ordinal() < Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG.ordinal() || getState() == Trade.State.SELLER_SAW_ARRIVED_PAYMENT_RECEIVED_MSG)) {
653-
log.warn("Resetting state of {} {} from {} to {} because no ack was received", getClass().getSimpleName(), getId(), getState(), Trade.State.BUYER_SENT_PAYMENT_SENT_MSG);
654-
resetToPaymentSentState();
642+
// when done with first sync, check if state needs reset
643+
wasWalletSynced.addListener((observable, oldValue, newValue) -> {
644+
if (!newValue) return;
645+
if (!isPayoutPublished()) {
646+
647+
// reset buyer's payment sent state if no ack receive
648+
if (this instanceof BuyerTrade && getState().ordinal() >= Trade.State.BUYER_CONFIRMED_PAYMENT_SENT.ordinal() && getState().ordinal() != Trade.State.BUYER_STORED_IN_MAILBOX_PAYMENT_SENT_MSG.ordinal()) {
649+
log.warn("Resetting state of {} {} from {} to {} because payout is not published", getClass().getSimpleName(), getId(), getState(), Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
650+
setState(Trade.State.DEPOSIT_TXS_UNLOCKED_IN_BLOCKCHAIN);
651+
}
652+
653+
// reset seller's payment received state if no ack receive
654+
if (this instanceof SellerTrade && getState().ordinal() >= Trade.State.SELLER_CONFIRMED_PAYMENT_RECEIPT.ordinal() && getState().ordinal() != Trade.State.SELLER_STORED_IN_MAILBOX_PAYMENT_RECEIVED_MSG.ordinal()) {
655+
log.warn("Resetting state of {} {} from {} to {} because payout is not published", getClass().getSimpleName(), getId(), getState(), Trade.State.BUYER_SENT_PAYMENT_SENT_MSG);
656+
resetToPaymentSentState();
657+
}
655658
}
656-
}
659+
});
657660

658661
// handle trade state events
659662
tradeStateSubscription = EasyBind.subscribe(stateProperty, newValue -> {
@@ -866,7 +869,7 @@ public MoneroWallet getWallet() {
866869
if (wallet != null) return wallet;
867870
if (!walletExists()) return null;
868871
if (isShutDownStarted) throw new RuntimeException("Cannot open wallet for " + getClass().getSimpleName() + " " + getId() + " because shut down is started");
869-
else wallet = xmrWalletService.openWallet(getWalletName(), xmrWalletService.isProxyApplied(wasWalletSynced));
872+
else wallet = xmrWalletService.openWallet(getWalletName(), xmrWalletService.isProxyApplied(wasWalletSynced.get()));
870873
return wallet;
871874
}
872875
}
@@ -2544,7 +2547,7 @@ protected void onConnectionChanged(MoneroRpcConnection connection) {
25442547
String oldProxyUri = wallet.getDaemonConnection() == null ? null : wallet.getDaemonConnection().getProxyUri();
25452548
String newProxyUri = connection == null ? null : connection.getProxyUri();
25462549
log.info("Setting daemon connection for trade wallet {}: uri={}, proxyUri={}", getId() , connection == null ? null : connection.getUri(), newProxyUri);
2547-
if (xmrWalletService.isProxyApplied(wasWalletSynced) && wallet instanceof MoneroWalletRpc && !StringUtils.equals(oldProxyUri, newProxyUri)) {
2550+
if (xmrWalletService.isProxyApplied(wasWalletSynced.get()) && wallet instanceof MoneroWalletRpc && !StringUtils.equals(oldProxyUri, newProxyUri)) {
25482551
log.info("Restarting trade wallet {} because proxy URI has changed, old={}, new={}", getId(), oldProxyUri, newProxyUri);
25492552
closeWallet();
25502553
wallet = getWallet();
@@ -2578,7 +2581,7 @@ private void tryInitSyncing() {
25782581
}
25792582

25802583
private void doTryInitSyncing() {
2581-
if (!wasWalletSynced) trySyncWallet(true);
2584+
if (!wasWalletSynced.get()) trySyncWallet(true);
25822585
updatePollPeriod();
25832586
startPolling();
25842587
}
@@ -2608,9 +2611,9 @@ private void syncWallet(boolean pollWallet) {
26082611
}
26092612

26102613
// apply tor after wallet synced depending on configuration
2611-
if (!wasWalletSynced) {
2612-
wasWalletSynced = true;
2613-
if (xmrWalletService.isProxyApplied(wasWalletSynced)) {
2614+
if (!wasWalletSynced.get()) {
2615+
wasWalletSynced.set(true);
2616+
if (xmrWalletService.isProxyApplied(true)) {
26142617
onConnectionChanged(xmrConnectionService.getConnection());
26152618
}
26162619
}

core/src/main/java/haveno/core/xmr/wallet/XmrWalletBase.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import haveno.core.api.XmrConnectionService;
1414
import haveno.core.trade.HavenoUtils;
1515
import haveno.core.xmr.setup.DownloadListener;
16+
import javafx.beans.property.BooleanProperty;
1617
import javafx.beans.property.LongProperty;
18+
import javafx.beans.property.SimpleBooleanProperty;
1719
import javafx.beans.property.SimpleLongProperty;
1820
import lombok.Getter;
1921
import lombok.extern.slf4j.Slf4j;
@@ -39,7 +41,7 @@ public abstract class XmrWalletBase {
3941
protected Timer saveWalletDelayTimer;
4042
@Getter
4143
protected XmrConnectionService xmrConnectionService;
42-
protected boolean wasWalletSynced;
44+
protected BooleanProperty wasWalletSynced = new SimpleBooleanProperty(false);
4345
protected final Map<String, Optional<MoneroTx>> txCache = new HashMap<String, Optional<MoneroTx>>();
4446
protected boolean isClosingWallet;
4547
protected boolean isSyncingWithProgress;
@@ -200,7 +202,7 @@ private synchronized void resetSyncProgressTimeout() {
200202
}
201203

202204
private void setWalletSyncedWithProgress() {
203-
wasWalletSynced = true;
205+
wasWalletSynced.set(true);
204206
isSyncingWithProgress = false;
205207
syncProgressTimeout.stop();
206208
}

0 commit comments

Comments
 (0)