synchronize access to account age witness maps to fix missing hash
This commit is contained in:
parent
5feb487039
commit
0372af663a
@ -244,7 +244,9 @@ public class AccountAgeWitnessService {
|
|||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
public void addToMap(AccountAgeWitness accountAgeWitness) {
|
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) {
|
public void publishMyAccountAgeWitness(PaymentAccountPayload paymentAccountPayload) {
|
||||||
AccountAgeWitness accountAgeWitness = getMyWitness(paymentAccountPayload);
|
synchronized (this) {
|
||||||
P2PDataStorage.ByteArray hash = accountAgeWitness.getHashAsByteArray();
|
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.
|
// We use first our fast lookup cache. If its in accountAgeWitnessCache it is also in accountAgeWitnessMap
|
||||||
if (accountAgeWitnessCache.containsKey(hash)) {
|
// and we do not publish.
|
||||||
return;
|
if (accountAgeWitnessCache.containsKey(hash)) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
if (!accountAgeWitnessMap.containsKey(hash)) {
|
|
||||||
p2PService.addPersistableNetworkPayload(accountAgeWitness, false);
|
if (!accountAgeWitnessMap.containsKey(hash)) {
|
||||||
|
p2PService.addPersistableNetworkPayload(accountAgeWitness, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,22 +322,24 @@ public class AccountAgeWitnessService {
|
|||||||
|
|
||||||
private Optional<AccountAgeWitness> getWitnessByHash(byte[] hash) {
|
private Optional<AccountAgeWitness> getWitnessByHash(byte[] hash) {
|
||||||
P2PDataStorage.ByteArray hashAsByteArray = new P2PDataStorage.ByteArray(hash);
|
P2PDataStorage.ByteArray hashAsByteArray = new P2PDataStorage.ByteArray(hash);
|
||||||
|
synchronized (this) {
|
||||||
|
|
||||||
// First we look up in our fast lookup cache
|
// First we look up in our fast lookup cache
|
||||||
if (accountAgeWitnessCache.containsKey(hashAsByteArray)) {
|
if (accountAgeWitnessCache.containsKey(hashAsByteArray)) {
|
||||||
return Optional.of(accountAgeWitnessCache.get(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) {
|
private Optional<AccountAgeWitness> getWitnessByHashAsHex(String hashAsHex) {
|
||||||
@ -548,8 +554,8 @@ public class AccountAgeWitnessService {
|
|||||||
if (accountAgeWitnessOptional.isPresent()) {
|
if (accountAgeWitnessOptional.isPresent()) {
|
||||||
peersWitness = accountAgeWitnessOptional.get();
|
peersWitness = accountAgeWitnessOptional.get();
|
||||||
} else {
|
} else {
|
||||||
peersWitness = getNewWitness(peersPaymentAccountPayload, peersPubKeyRing);
|
|
||||||
log.warn("We did not find the peers witness data. That is expected with peers using an older version.");
|
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)
|
// Check if date in witness is not older than the release date of that feature (was added in v0.6)
|
||||||
|
@ -964,9 +964,7 @@ public class XmrWalletService {
|
|||||||
// -------------------------------- HELPERS -------------------------------
|
// -------------------------------- HELPERS -------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes internally before notifying external listeners.
|
* Relays wallet notifications to external listeners.
|
||||||
*
|
|
||||||
* TODO: no longer neccessary to execute on user thread?
|
|
||||||
*/
|
*/
|
||||||
private class XmrWalletListener extends MoneroWalletListener {
|
private class XmrWalletListener extends MoneroWalletListener {
|
||||||
|
|
||||||
|
@ -19,8 +19,6 @@ package bisq.core.payment;
|
|||||||
|
|
||||||
import bisq.core.api.model.PaymentAccountForm;
|
import bisq.core.api.model.PaymentAccountForm;
|
||||||
import bisq.core.api.model.PaymentAccountFormField;
|
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.BankUtil;
|
||||||
import bisq.core.locale.Country;
|
import bisq.core.locale.Country;
|
||||||
import bisq.core.locale.CountryUtil;
|
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.
|
* @param paymentAccountJsonString The json data representing a new payment account form.
|
||||||
* @return A populated PaymentAccount subclass instance.
|
* @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);
|
Class<? extends PaymentAccount> clazz = getPaymentAccountClassFromJson(paymentAccountJsonString);
|
||||||
Gson gson = gsonBuilder.registerTypeAdapter(clazz, new PaymentAccountTypeAdapter(clazz)).create();
|
Gson gson = gsonBuilder.registerTypeAdapter(clazz, new PaymentAccountTypeAdapter(clazz)).create();
|
||||||
return gson.fromJson(paymentAccountJsonString, clazz);
|
return gson.fromJson(paymentAccountJsonString, clazz);
|
||||||
|
@ -79,9 +79,6 @@ public class ProcessPaymentReceivedMessage extends TradeTask {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure connected to monero network
|
|
||||||
trade.checkWalletConnection();
|
|
||||||
|
|
||||||
// process payout tx unless already unlocked
|
// process payout tx unless already unlocked
|
||||||
if (!trade.isPayoutUnlocked()) processPayoutTx(message);
|
if (!trade.isPayoutUnlocked()) processPayoutTx(message);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user