mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-24 23:18:17 +01:00
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:
parent
2bb4bff41d
commit
766b1e2e1e
1 changed files with 17 additions and 5 deletions
|
@ -108,11 +108,11 @@ public final class AddressEntryList implements UserThreadMappedPersistableEnvelo
|
|||
Set<AddressEntry> toBeRemoved = new HashSet<>();
|
||||
entrySet.forEach(addressEntry -> {
|
||||
DeterministicKey keyFromPubHash = (DeterministicKey) wallet.findKeyFromPubKeyHash(
|
||||
addressEntry.getPubKeyHash(),
|
||||
Script.ScriptType.P2PKH);
|
||||
addressEntry.getPubKeyHash(),
|
||||
Script.ScriptType.P2PKH);
|
||||
if (keyFromPubHash != null) {
|
||||
Address addressFromKey = LegacyAddress.fromKey(Config.baseCurrencyNetworkParameters(),
|
||||
keyFromPubHash);
|
||||
keyFromPubHash);
|
||||
// We want to ensure key and address matches in case we have address in entry available already
|
||||
if (addressEntry.getAddress() == null || addressFromKey.equals(addressEntry.getAddress())) {
|
||||
addressEntry.setDeterministicKey(keyFromPubHash);
|
||||
|
@ -173,6 +173,18 @@ public final class AddressEntryList implements UserThreadMappedPersistableEnvelo
|
|||
}
|
||||
|
||||
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);
|
||||
if (setChangedByAdd)
|
||||
persist();
|
||||
|
@ -181,7 +193,7 @@ public final class AddressEntryList implements UserThreadMappedPersistableEnvelo
|
|||
public void swapToAvailable(AddressEntry addressEntry) {
|
||||
boolean setChangedByRemove = entrySet.remove(addressEntry);
|
||||
boolean setChangedByAdd = entrySet.add(new AddressEntry(addressEntry.getKeyPair(),
|
||||
AddressEntry.Context.AVAILABLE));
|
||||
AddressEntry.Context.AVAILABLE));
|
||||
if (setChangedByRemove || setChangedByAdd) {
|
||||
persist();
|
||||
}
|
||||
|
@ -215,7 +227,7 @@ public final class AddressEntryList implements UserThreadMappedPersistableEnvelo
|
|||
.filter(Objects::nonNull)
|
||||
.filter(this::isAddressNotInEntries)
|
||||
.map(address -> (DeterministicKey) wallet.findKeyFromPubKeyHash(address.getHash(),
|
||||
Script.ScriptType.P2PKH))
|
||||
Script.ScriptType.P2PKH))
|
||||
.filter(Objects::nonNull)
|
||||
.map(deterministicKey -> new AddressEntry(deterministicKey, AddressEntry.Context.AVAILABLE))
|
||||
.forEach(this::addAddressEntry);
|
||||
|
|
Loading…
Add table
Reference in a new issue