We do not need to lookup in getSignedWitnessMapValues

anymore as we maintain the signedWitnessSetByAccountAgeWitnessHash
at each add/remove operation.
This commit is contained in:
chimp1984 2020-12-20 10:28:28 -05:00
parent b6a01d0ac7
commit aea904d24f
No known key found for this signature in database
GPG key ID: 9801B4EC591F90E3

View file

@ -353,22 +353,9 @@ public class SignedWitnessService {
}
}
private Set<SignedWitness> getSignedWitnessSet(AccountAgeWitness accountAgeWitness) {
byte[] accountAgeWitnessHash = accountAgeWitness.getHash();
P2PDataStorage.ByteArray key = new P2PDataStorage.ByteArray(accountAgeWitnessHash);
// In case we get a new entry added to signedWitnessMap with our hash we remove the entry from the cache so
// that we use the updated signedWitnessMap to fill the cache new.
if (signedWitnessSetByAccountAgeWitnessHash.containsKey(key)) {
return signedWitnessSetByAccountAgeWitnessHash.get(key);
}
Set<SignedWitness> result = getSignedWitnessMapValues().stream()
.filter(signedWitness -> Arrays.equals(signedWitness.getAccountAgeWitnessHash(), accountAgeWitnessHash))
.collect(Collectors.toSet());
signedWitnessSetByAccountAgeWitnessHash.put(key, result);
return result;
public Set<SignedWitness> getSignedWitnessSet(AccountAgeWitness accountAgeWitness) {
P2PDataStorage.ByteArray key = new P2PDataStorage.ByteArray(accountAgeWitness.getHash());
return signedWitnessSetByAccountAgeWitnessHash.getOrDefault(key, new HashSet<>());
}
// SignedWitness objects signed by arbitrators