Add check to not add a duplicate address entry with same offer ID and context.

In debugging trade protocol and taking same offer I could generate problems where the multisig entry was twice but with diff. keys, so take offer failed. I remember the error log to have seen in the past and I assume this was a rare bug we encountered when users took again the same offer which failed with an uncritical state earlier.
This commit is contained in:
chimp1984 2020-09-26 12:42:17 -05:00
parent 2bb4bff41d
commit 766b1e2e1e
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3

View file

@ -173,6 +173,18 @@ public final class AddressEntryList implements UserThreadMappedPersistableEnvelo
} }
public void addAddressEntry(AddressEntry addressEntry) { public void addAddressEntry(AddressEntry addressEntry) {
boolean entryWithSameOfferIdAndContextAlreadyExist = entrySet.stream().anyMatch(e -> {
if (addressEntry.getOfferId() != null) {
return addressEntry.getOfferId().equals(e.getOfferId()) && addressEntry.getContext() == e.getContext();
}
return false;
});
if (entryWithSameOfferIdAndContextAlreadyExist) {
log.error("We have an address entry with the same offer ID and context. We do not add the new one. " +
"addressEntry={}, entrySet={}", addressEntry, entrySet);
return;
}
boolean setChangedByAdd = entrySet.add(addressEntry); boolean setChangedByAdd = entrySet.add(addressEntry);
if (setChangedByAdd) if (setChangedByAdd)
persist(); persist();