From 26ea53883c3269137e33b2aaa158ef148472db18 Mon Sep 17 00:00:00 2001 From: woodser Date: Fri, 15 Dec 2023 16:18:00 -0500 Subject: [PATCH] republish offers awaits prices and runs off UserThread --- .../java/haveno/core/offer/OpenOfferManager.java | 8 ++++++-- .../haveno/core/provider/price/PriceFeedService.java | 12 ++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/haveno/core/offer/OpenOfferManager.java b/core/src/main/java/haveno/core/offer/OpenOfferManager.java index 997ab1a5..5a46de8c 100644 --- a/core/src/main/java/haveno/core/offer/OpenOfferManager.java +++ b/core/src/main/java/haveno/core/offer/OpenOfferManager.java @@ -863,7 +863,7 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe // on error, create split output tx if not already created if (openOffer.getSplitOutputTxHash() == null) { int offerSubaddress = xmrWalletService.getOrCreateAddressEntry(openOffer.getId(), XmrAddressEntry.Context.OFFER_FUNDING).getSubaddressIndex(); - log.warn("Splitting new output because spending scheduled output(s) failed for offer {}. Split output tx subaddresses={}. Offer funding subadress={}", openOffer.getId(), splitOutputTx.getOutgoingTransfer().getSubaddressIndices(), offerSubaddress); + log.warn("Splitting new output because spending scheduled output(s) failed for offer {}. Offer funding subadress={}", openOffer.getId(), offerSubaddress); splitOrSchedule(openOffers, openOffer, offerReserveAmount); resultHandler.handleResult(null); } else { @@ -1569,7 +1569,11 @@ public class OpenOfferManager implements PeerManager.Listener, DecryptedDirectMe stopPeriodicRefreshOffersTimer(); - processListForRepublishOffers(getOpenOffers()); + priceFeedService.awaitPrices(); + + new Thread(() -> { + processListForRepublishOffers(getOpenOffers()); + }).start(); } private void processListForRepublishOffers(List list) { diff --git a/core/src/main/java/haveno/core/provider/price/PriceFeedService.java b/core/src/main/java/haveno/core/provider/price/PriceFeedService.java index 9dce9067..71909bae 100644 --- a/core/src/main/java/haveno/core/provider/price/PriceFeedService.java +++ b/core/src/main/java/haveno/core/provider/price/PriceFeedService.java @@ -137,6 +137,18 @@ public class PriceFeedService { request(false); } + /** + * Awaits prices to be available, but does not request them. + */ + public void awaitPrices() { + if (hasPrices()) return; + CountDownLatch latch = new CountDownLatch(1); + ChangeListener listener = (observable, oldValue, newValue) -> { latch.countDown(); }; + updateCounter.addListener(listener); + HavenoUtils.awaitLatch(latch); + updateCounter.removeListener(listener); + } + public boolean hasPrices() { return !cache.isEmpty(); }