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
This commit is contained in:
ghubstan 2021-08-18 14:27:20 -03:00
parent 859a5ab4e4
commit fb4e00fb6b
No known key found for this signature in database
GPG Key ID: E35592D6800A861E
2 changed files with 2 additions and 21 deletions

View File

@ -94,7 +94,7 @@ public class OfferBookService {
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 class OfferBookService {
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());
}
}));

View File

@ -166,25 +166,6 @@ public class OfferBook {
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;
}