mirror of
https://github.com/haveno-dex/haveno.git
synced 2024-12-28 16:59:44 -05:00
add and remove offers on user thread to fix illegal state #1031
This commit is contained in:
parent
26a5ffcb31
commit
cb0b6665f7
@ -115,6 +115,7 @@ public class OfferBookService {
|
|||||||
p2PService.addHashSetChangedListener(new HashMapChangedListener() {
|
p2PService.addHashSetChangedListener(new HashMapChangedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAdded(Collection<ProtectedStorageEntry> protectedStorageEntries) {
|
public void onAdded(Collection<ProtectedStorageEntry> protectedStorageEntries) {
|
||||||
|
UserThread.execute(() -> {
|
||||||
protectedStorageEntries.forEach(protectedStorageEntry -> {
|
protectedStorageEntries.forEach(protectedStorageEntry -> {
|
||||||
if (protectedStorageEntry.getProtectedStoragePayload() instanceof OfferPayload) {
|
if (protectedStorageEntry.getProtectedStoragePayload() instanceof OfferPayload) {
|
||||||
OfferPayload offerPayload = (OfferPayload) protectedStorageEntry.getProtectedStoragePayload();
|
OfferPayload offerPayload = (OfferPayload) protectedStorageEntry.getProtectedStoragePayload();
|
||||||
@ -128,10 +129,12 @@ public class OfferBookService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRemoved(Collection<ProtectedStorageEntry> protectedStorageEntries) {
|
public void onRemoved(Collection<ProtectedStorageEntry> protectedStorageEntries) {
|
||||||
|
UserThread.execute(() -> {
|
||||||
protectedStorageEntries.forEach(protectedStorageEntry -> {
|
protectedStorageEntries.forEach(protectedStorageEntry -> {
|
||||||
if (protectedStorageEntry.getProtectedStoragePayload() instanceof OfferPayload) {
|
if (protectedStorageEntry.getProtectedStoragePayload() instanceof OfferPayload) {
|
||||||
OfferPayload offerPayload = (OfferPayload) protectedStorageEntry.getProtectedStoragePayload();
|
OfferPayload offerPayload = (OfferPayload) protectedStorageEntry.getProtectedStoragePayload();
|
||||||
@ -145,6 +148,7 @@ public class OfferBookService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -278,9 +282,11 @@ public class OfferBookService {
|
|||||||
keyImagePoller.addListener(new XmrKeyImageListener() {
|
keyImagePoller.addListener(new XmrKeyImageListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onSpentStatusChanged(Map<String, MoneroKeyImageSpentStatus> spentStatuses) {
|
public void onSpentStatusChanged(Map<String, MoneroKeyImageSpentStatus> spentStatuses) {
|
||||||
|
UserThread.execute(() -> {
|
||||||
for (String keyImage : spentStatuses.keySet()) {
|
for (String keyImage : spentStatuses.keySet()) {
|
||||||
updateAffectedOffers(keyImage);
|
updateAffectedOffers(keyImage);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -301,12 +307,8 @@ public class OfferBookService {
|
|||||||
if (offer.getOfferPayload().getReserveTxKeyImages().contains(keyImage)) {
|
if (offer.getOfferPayload().getReserveTxKeyImages().contains(keyImage)) {
|
||||||
synchronized (offerBookChangedListeners) {
|
synchronized (offerBookChangedListeners) {
|
||||||
offerBookChangedListeners.forEach(listener -> {
|
offerBookChangedListeners.forEach(listener -> {
|
||||||
|
|
||||||
// notify off thread to avoid deadlocking
|
|
||||||
new Thread(() -> {
|
|
||||||
listener.onRemoved(offer);
|
listener.onRemoved(offer);
|
||||||
listener.onAdded(offer);
|
listener.onAdded(offer);
|
||||||
}).start();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,8 @@ package haveno.desktop.main.market.offerbook;
|
|||||||
|
|
||||||
import com.google.common.math.LongMath;
|
import com.google.common.math.LongMath;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
|
|
||||||
|
import haveno.common.UserThread;
|
||||||
import haveno.core.account.witness.AccountAgeWitnessService;
|
import haveno.core.account.witness.AccountAgeWitnessService;
|
||||||
import haveno.core.locale.CurrencyUtil;
|
import haveno.core.locale.CurrencyUtil;
|
||||||
import haveno.core.locale.GlobalSettings;
|
import haveno.core.locale.GlobalSettings;
|
||||||
@ -135,10 +137,12 @@ class OfferBookChartViewModel extends ActivatableViewModel {
|
|||||||
|
|
||||||
currenciesUpdatedListener = (observable, oldValue, newValue) -> {
|
currenciesUpdatedListener = (observable, oldValue, newValue) -> {
|
||||||
if (!isAnyPriceAbsent()) {
|
if (!isAnyPriceAbsent()) {
|
||||||
|
UserThread.execute(() -> {
|
||||||
offerBook.fillOfferBookListItems();
|
offerBook.fillOfferBookListItems();
|
||||||
updateChartData();
|
updateChartData();
|
||||||
var self = this;
|
var self = this;
|
||||||
priceFeedService.updateCounterProperty().removeListener(self.currenciesUpdatedListener);
|
priceFeedService.updateCounterProperty().removeListener(self.currenciesUpdatedListener);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user