<p></p>
<p><b>@sqrrm</b> commented on this pull request.</p>

<hr>

<p>In <a href="https://github.com/bisq-network/bisq/pull/4953#discussion_r544697931">core/src/main/java/bisq/core/account/sign/SignedWitnessService.java</a>:</p>
<pre style='color:#555'>>      private final Map<P2PDataStorage.ByteArray, SignedWitness> signedWitnessMap = new HashMap<>();
+
+    // The getSignedWitnessSet is called very often and is a bit expensive. We cache the result in that map but we
+    // remove the cache entry if we get a matching SignedWitness added to the signedWitnessMap.
+    private final Map<P2PDataStorage.ByteArray, Set<SignedWitness>> getSignedWitnessSetCache = new ConcurrentHashMap<>();
</pre>
<p>The name is a bit off for a map, just <code>signedWitnessSetCache</code> would be more natural.</p>

<hr>

<p>In <a href="https://github.com/bisq-network/bisq/pull/4953#discussion_r544702522">core/src/main/java/bisq/core/account/sign/SignedWitnessService.java</a>:</p>
<pre style='color:#555'>> @@ -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);
</pre>
<p>This looks redundant, it's removing the same item from the cache again. <code>hash</code> is calculated as <code>new P2PDataStorage.ByteArray(signedWitness.getAccountAgeWitnessHash())</code> when following the calls to signedWitness.</p>

<hr>

<p>In <a href="https://github.com/bisq-network/bisq/pull/4953#discussion_r544703887">core/src/main/java/bisq/core/account/sign/SignedWitnessService.java</a>:</p>
<pre style='color:#555'>> +        getSignedWitnessMapValues()
+                .forEach(signedWitness -> p2PService.addPersistableNetworkPayload(signedWitness, true));
+    }
+
+    @VisibleForTesting
+    public void removeSignedWitness(SignedWitness signedWitness) {
+        P2PDataStorage.ByteArray hash = signedWitness.getHashAsByteArray();
+        signedWitnessMap.remove(hash);
+
+        // Need to remove the entry matching signedWitness.getAccountAgeWitnessHash() (test would fail otherwise)
+        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);
</pre>
<p>This seems redundant, same reason as earlier comment</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/bisq-network/bisq/pull/4953#pullrequestreview-554168385">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJFFTNR5URV7LEPDIE2AOTLSVFBURANCNFSM4U32MFNA">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AJFFTNQDSBWEXI4224W4LKTSVFBURA5CNFSM4U32MFNKYY3PNVWWK3TUL52HS4DFWFIHK3DMKJSXC5LFON2FEZLWNFSXPKTDN5WW2ZLOORPWSZGOEED7AQI.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/bisq-network/bisq/pull/4953#pullrequestreview-554168385",
"url": "https://github.com/bisq-network/bisq/pull/4953#pullrequestreview-554168385",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>