Skip to content

fix(core): make Merkle root hashing deterministic#386

Open
wuyua9 wants to merge 1 commit into
zilliztech:masterfrom
wuyua9:devb/deterministic-merkle-root
Open

fix(core): make Merkle root hashing deterministic#386
wuyua9 wants to merge 1 commit into
zilliztech:masterfrom
wuyua9:devb/deterministic-merkle-root

Conversation

@wuyua9

@wuyua9 wuyua9 commented May 27, 2026

Copy link
Copy Markdown

Summary

  • build the Merkle DAG root hash from sorted file paths instead of Map insertion order
  • add a regression test that builds identical file-hash maps in different insertion orders and checks the root id stays stable

Why

buildMerkleDAG() already adds child nodes in sortedPaths order, but the root node data was still built from the unsorted Map key order. When the same file hashes are inserted in a different traversal order, the root id can change even though the files did not.

MerkleDAG.compare() treats changed node ids as added/removed, so an insertion-order-only root change can make the synchronizer do unnecessary file-state comparisons and snapshot writes.

Tests

  • cd packages/core && node_modules/.bin/jest src/sync/synchronizer.test.ts --runInBand
  • ./node_modules/.bin/tsc --build packages/core --force
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant