From fb4e00fb6bf6c6fbac536292d3b930f3c04cacf0 Mon Sep 17 00:00:00 2001 From: ghubstan <36207203+ghubstan@users.noreply.github.com> Date: Wed, 18 Aug 2021 14:27:20 -0300 Subject: [PATCH] Fix OfferBookService bug causing extra check in OfferBook.onRemoved Hash of protectedStorageEntry (should be offerPayload) was sometimes resulting in incorrect hash being sent to OfferBook listener methods onAdded(offer, hashOfPayload, sequenceNumber), and onRemoved(offer, hashOfPayload, sequenceNumber). Hash of OfferPayload is correctly passed to listener with this change. Sending the correct hash allows removal of a dubious code block that removed a book view list item when hash compare failed, and no matching offer existed in the OfferBookService. See https://github.com/bisq-network/bisq/pull/5659#discussion_r689634240 --- .../bisq/core/offer/OfferBookService.java | 4 ++-- .../main/offer/offerbook/OfferBook.java | 19 ------------------- 2 files changed, 2 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/bisq/core/offer/OfferBookService.java b/core/src/main/java/bisq/core/offer/OfferBookService.java index 61a7d781b7b..a589e187452 100644 --- a/core/src/main/java/bisq/core/offer/OfferBookService.java +++ b/core/src/main/java/bisq/core/offer/OfferBookService.java @@ -94,7 +94,7 @@ public void onAdded(Collection protectedStorageEntries) { OfferPayload offerPayload = (OfferPayload) protectedStorageEntry.getProtectedStoragePayload(); Offer offer = new Offer(offerPayload); offer.setPriceFeedService(priceFeedService); - P2PDataStorage.ByteArray hashOfPayload = get32ByteHashAsByteArray(protectedStorageEntry); + P2PDataStorage.ByteArray hashOfPayload = get32ByteHashAsByteArray(offerPayload); listener.onAdded(offer, hashOfPayload, protectedStorageEntry.getSequenceNumber()); } })); @@ -107,7 +107,7 @@ public void onRemoved(Collection protectedStorageEntries) OfferPayload offerPayload = (OfferPayload) protectedStorageEntry.getProtectedStoragePayload(); Offer offer = new Offer(offerPayload); offer.setPriceFeedService(priceFeedService); - P2PDataStorage.ByteArray hashOfPayload = get32ByteHashAsByteArray(protectedStorageEntry); + P2PDataStorage.ByteArray hashOfPayload = get32ByteHashAsByteArray(offerPayload); listener.onRemoved(offer, hashOfPayload, protectedStorageEntry.getSequenceNumber()); } })); diff --git a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java index b6904639a6f..351550e3930 100644 --- a/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java +++ b/desktop/src/main/java/bisq/desktop/main/offer/offerbook/OfferBook.java @@ -166,25 +166,6 @@ public void removeOffer(Offer offer, P2PDataStorage.ByteArray hashOfPayload, int offer.getId(), hashOfPayload == null ? "null" : hashOfPayload.getHex()); } - - // The OfferBookListItem with a null or matching payload-hash was not found. - // However, when the API's CLI is used to edit and deactivate an offer - // in the same command, the edited offer is not re-published (and cannot be - // found in local storage). In this case, we need to remove the deactivated - // offer from the list if the local store does not contain an offer with a - // matching offerId. - if (!isStoredLocally(offer)) { - Optional viewItem = getOfferBookListItem(offer); - viewItem.ifPresent((item) -> { - offerBookListItems.remove(item); - if (log.isDebugEnabled()) { - log.debug("Storage does not contain an offer with id {} either;" - + " it is removed from UI view list.", - offer.getId()); - } - }); - } - return; }