Skip to content

Commit b465d0f

Browse files
committed
Refactor update method in MerkleTree to improve root hash comparison logic
1 parent f9ea8f6 commit b465d0f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/io/pwrlabs/database/rocksdb/MerkleTree.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,14 @@ public void update(MerkleTree sourceTree) throws RocksDBException, IOException {
514514
throw new IllegalArgumentException("Source tree cannot be null");
515515
}
516516

517-
if(Arrays.equals(getRootHashSavedOnDisk(), sourceTree.getRootHashSavedOnDisk())) {
517+
byte[] rootHashSavedOnDisk = getRootHashSavedOnDisk();
518+
byte[] sourceRootHashSavedOnDisk = sourceTree.getRootHashSavedOnDisk();
519+
if (
520+
(rootHashSavedOnDisk == null && sourceRootHashSavedOnDisk == null)
521+
||
522+
(rootHashSavedOnDisk != null && sourceRootHashSavedOnDisk != null)
523+
&& Arrays.equals(getRootHashSavedOnDisk(), sourceTree.getRootHashSavedOnDisk())
524+
) {
518525
//This means that this tree is already a copy of the source tree and we only need to replace the cache
519526
copyCache(sourceTree);
520527
} else {

0 commit comments

Comments
 (0)