Skip to content

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

Merged
zc277584121 merged 1 commit into
zilliztech:masterfrom
wuyua9:devb/deterministic-merkle-root
Jul 14, 2026
Merged

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

Conversation

@wuyua9

@wuyua9 wuyua9 commented May 27, 2026

Copy link
Copy Markdown
Contributor

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

@zc277584121
zc277584121 merged commit d0a2eff into zilliztech:master Jul 14, 2026
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.

2 participants