synchronize access to account age witness maps to fix missing hash

This commit is contained in:
woodser 2023-02-07 14:07:26 -05:00
parent 5feb487039
commit 0372af663a
4 changed files with 35 additions and 36 deletions

View file

@ -244,7 +244,9 @@ public class AccountAgeWitnessService {
@VisibleForTesting
public void addToMap(AccountAgeWitness accountAgeWitness) {
accountAgeWitnessMap.putIfAbsent(accountAgeWitness.getHashAsByteArray(), accountAgeWitness);
synchronized (this) {
accountAgeWitnessMap.putIfAbsent(accountAgeWitness.getHashAsByteArray(), accountAgeWitness);
}
}
@ -253,17 +255,19 @@ public class AccountAgeWitnessService {
///////////////////////////////////////////////////////////////////////////////////////////
public void publishMyAccountAgeWitness(PaymentAccountPayload paymentAccountPayload) {
AccountAgeWitness accountAgeWitness = getMyWitness(paymentAccountPayload);
P2PDataStorage.ByteArray hash = accountAgeWitness.getHashAsByteArray();
// We use first our fast lookup cache. If its in accountAgeWitnessCache it is also in accountAgeWitnessMap
// and we do not publish.
if (accountAgeWitnessCache.containsKey(hash)) {
return;
}
if (!accountAgeWitnessMap.containsKey(hash)) {
p2PService.addPersistableNetworkPayload(accountAgeWitness, false);
synchronized (this) {
AccountAgeWitness accountAgeWitness = getMyWitness(paymentAccountPayload);
P2PDataStorage.ByteArray hash = accountAgeWitness.getHashAsByteArray();
// We use first our fast lookup cache. If its in accountAgeWitnessCache it is also in accountAgeWitnessMap
// and we do not publish.
if (accountAgeWitnessCache.containsKey(hash)) {
return;
}
if (!accountAgeWitnessMap.containsKey(hash)) {
p2PService.addPersistableNetworkPayload(accountAgeWitness, false);
}
}
}
@ -318,22 +322,24 @@ public class AccountAgeWitnessService {
private Optional<AccountAgeWitness> getWitnessByHash(byte[] hash) {
P2PDataStorage.ByteArray hashAsByteArray = new P2PDataStorage.ByteArray(hash);
synchronized (this) {
// First we look up in our fast lookup cache
if (accountAgeWitnessCache.containsKey(hashAsByteArray)) {
return Optional.of(accountAgeWitnessCache.get(hashAsByteArray));
// First we look up in our fast lookup cache
if (accountAgeWitnessCache.containsKey(hashAsByteArray)) {
return Optional.of(accountAgeWitnessCache.get(hashAsByteArray));
}
if (accountAgeWitnessMap.containsKey(hashAsByteArray)) {
AccountAgeWitness accountAgeWitness = accountAgeWitnessMap.get(hashAsByteArray);
// We add it to our fast lookup cache
accountAgeWitnessCache.put(hashAsByteArray, accountAgeWitness);
return Optional.of(accountAgeWitness);
}
return Optional.empty();
}
if (accountAgeWitnessMap.containsKey(hashAsByteArray)) {
AccountAgeWitness accountAgeWitness = accountAgeWitnessMap.get(hashAsByteArray);
// We add it to our fast lookup cache
accountAgeWitnessCache.put(hashAsByteArray, accountAgeWitness);
return Optional.of(accountAgeWitness);
}
return Optional.empty();
}
private Optional<AccountAgeWitness> getWitnessByHashAsHex(String hashAsHex) {
@ -548,8 +554,8 @@ public class AccountAgeWitnessService {
if (accountAgeWitnessOptional.isPresent()) {
peersWitness = accountAgeWitnessOptional.get();
} else {
peersWitness = getNewWitness(peersPaymentAccountPayload, peersPubKeyRing);
log.warn("We did not find the peers witness data. That is expected with peers using an older version.");
peersWitness = getNewWitness(peersPaymentAccountPayload, peersPubKeyRing);
}
// Check if date in witness is not older than the release date of that feature (was added in v0.6)

View file

@ -964,9 +964,7 @@ public class XmrWalletService {
// -------------------------------- HELPERS -------------------------------
/**
* Processes internally before notifying external listeners.
*
* TODO: no longer neccessary to execute on user thread?
* Relays wallet notifications to external listeners.
*/
private class XmrWalletListener extends MoneroWalletListener {

View file

@ -19,8 +19,6 @@ package bisq.core.payment;
import bisq.core.api.model.PaymentAccountForm;
import bisq.core.api.model.PaymentAccountFormField;
import bisq.core.api.model.PaymentAccountFormField.Component;
import bisq.core.api.model.PaymentAccountFormField.FieldId;
import bisq.core.locale.BankUtil;
import bisq.core.locale.Country;
import bisq.core.locale.CountryUtil;
@ -335,7 +333,7 @@ public abstract class PaymentAccount implements PersistablePayload {
* @param paymentAccountJsonString The json data representing a new payment account form.
* @return A populated PaymentAccount subclass instance.
*/
public static PaymentAccount fromJson(String paymentAccountJsonString) {
public static synchronized PaymentAccount fromJson(String paymentAccountJsonString) {
Class<? extends PaymentAccount> clazz = getPaymentAccountClassFromJson(paymentAccountJsonString);
Gson gson = gsonBuilder.registerTypeAdapter(clazz, new PaymentAccountTypeAdapter(clazz)).create();
return gson.fromJson(paymentAccountJsonString, clazz);

View file

@ -79,9 +79,6 @@ public class ProcessPaymentReceivedMessage extends TradeTask {
}
}
// ensure connected to monero network
trade.checkWalletConnection();
// process payout tx unless already unlocked
if (!trade.isPayoutUnlocked()) processPayoutTx(message);