Skip to content

Commit

Permalink
Fix OfferBookService bug causing extra check in OfferBook.onRemoved
Browse files Browse the repository at this point in the history
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 #5659 (comment)
  • Loading branch information
ghubstan committed Aug 18, 2021
1 parent 859a5ab commit fb4e00f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 21 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/bisq/core/offer/OfferBookService.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void onAdded(Collection<ProtectedStorageEntry> 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());
}
}));
Expand All @@ -107,7 +107,7 @@ public void onRemoved(Collection<ProtectedStorageEntry> 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());
}
}));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OfferBookListItem> 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;
}

Expand Down

0 comments on commit fb4e00f

Please sign in to comment.