[bisq-network/bisq] (7/8) Develop APIs for ProtectedStorageEntry to enable testing and code refactoring (#3583)

Julian Knutsen notifications at github.com
Fri Nov 15 17:27:30 UTC 2019


julianknutsen commented on this pull request.



> -        boolean result = storedData.getOwnerPubKey() != null && storedData.getOwnerPubKey().equals(ownerPubKey);
-        if (!result)
-            log.warn("New data entry does not match our stored data. storedData.ownerPubKey=" +
-                    (storedData.getOwnerPubKey() != null ? storedData.getOwnerPubKey().toString() : "null") +
-                    ", ownerPubKey=" + ownerPubKey);
-
-        return result;
-    }
-
-    private boolean checkIfStoredMailboxDataMatchesNewMailboxData(PublicKey receiversPubKey, ByteArray hashOfData) {
-        ProtectedStorageEntry storedData = map.get(hashOfData);
-        if (storedData instanceof ProtectedMailboxStorageEntry) {
-            ProtectedMailboxStorageEntry entry = (ProtectedMailboxStorageEntry) storedData;
-            // publicKey is not the same (stored: sender, new: receiver)
-            boolean result = entry.getReceiversPubKey().equals(receiversPubKey)
-                    && get32ByteHashAsByteArray(entry.getProtectedStoragePayload()).equals(hashOfData);

Absolutely. This one was really confusing at first and I'm happy to help explain so you can verify it is correct.

By renaming some variables it makes it a bit easier to understand:

```
private boolean checkIfStoredMailboxDataMatchesNewMailboxData(PublicKey removeEntryReceiversPubKey, ByteArray removeEntryPayloadHash) {	
        ProtectedStorageEntry existingEntry = map.get(removeEntryPayloadHash);	
        if (storedData instanceof ProtectedMailboxStorageEntry) {	
            ProtectedMailboxStorageEntry existingMailboxEntry = (ProtectedMailboxStorageEntry) existingEntry;	
            // publicKey is not the same (stored: sender, new: receiver)	
            boolean result = existingMailboxEntry.getReceiversPubKey().equals(removeEntryReceiversPubKey)	
                    && get32ByteHashAsByteArray(existingMailboxEntry.getProtectedStoragePayload()).equals(removeEntryPayloadHash);
```

So, it was verifying that the new removeEntry's payload has the same hash as the existingEntry's payload. But, the only way that we can get to this branch in the code is if the payload hashes are equal. Line 762 grabs the existingEntry based on the hash of the removeEntry's payload so they already must be identical because the existingEntry was inserted into the map based on its payload.

-- 
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/3583#discussion_r346931107
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.bisq.network/pipermail/bisq-github/attachments/20191115/16115cf6/attachment-0001.html>


More information about the bisq-github mailing list