[bisq-network/bisq] Cache results in account witness domain (#4953)

chimp1984 notifications at github.com
Sun Dec 20 15:37:56 CET 2020


@chimp1984 commented on this pull request.



> @@ -487,8 +509,18 @@ private boolean verifyDate(SignedWitness signedWitness, long childSignedWitnessD
     ///////////////////////////////////////////////////////////////////////////////////////////
 
     @VisibleForTesting
-    void addToMap(SignedWitness signedWitness) {
-        signedWitnessMap.putIfAbsent(signedWitness.getHashAsByteArray(), signedWitness);
+    public void addToMap(SignedWitness signedWitness) {
+        P2PDataStorage.ByteArray hash = signedWitness.getHashAsByteArray();
+        signedWitnessMap.putIfAbsent(hash, signedWitness);
+
+        // We remove the entry with that hash in case we have cached it, so at the next getSignedWitnessSet
+        // call we use the updated signedWitnessMap to re-fill our cache.
+        getSignedWitnessSetCache.remove(new P2PDataStorage.ByteArray(signedWitness.getAccountAgeWitnessHash()));
+
+        // Not sure if that is needed as well, tests did succeed in both cases, but seems to be more safe to remove
+        // potential entries with hash as well. A removed item in getSignedWitnessSetCache carries no risk, though a
+        // remaining item would.
+        getSignedWitnessSetCache.remove(hash);

I looked up in the code and both fields are different!
```
byte[] data = Utilities.concatenateByteArrays(accountAgeWitnessHash, signature);
data = Utilities.concatenateByteArrays(data, signerPubKey);
hash = Hash.getSha256Ripemd160hash(data);
        
public P2PDataStorage.ByteArray getHashAsByteArray() {
        return new P2PDataStorage.ByteArray(hash);
}
```

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/bisq-network/bisq/pull/4953#discussion_r546385492
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20201220/187cccd1/attachment.htm>


More information about the bisq-github mailing list