fix(merkle): use latest available version when exact contractTreeElem…#13
Merged
Merged
Conversation
…ents version is missing When totalElements crosses a 32-element batch boundary, contractTreeElements jumps by 32. If the local chairman tree hasn't merged that batch yet (e.g. due to indexer lag or sync gaps), getChairmanMerkleVersion returns undefined for the exact version — causing hybrid mode to silently skip local proof and fall back to the remote freezer service. Fix: when the exact version is unavailable, fall back to the latest stored version that still covers all requested CIDs. The returned latest_cid is adjusted to match the version actually used, so pickMerkleRootIndex finds the correct on-chain root (its search window already tolerates this offset). Verified: 12h / 550+ cycles / 356 transfers with zero proof errors on Sepolia testnet, with the remote freezer service completely unreachable. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request refactors the local Merkle proof generation logic in MerkleEngine to include a fallback mechanism. When the exact contract version is unavailable locally, the engine now attempts to use the latest local version that covers all requested CIDs. It also updates the returned latest_cid to match the version used and refines error reporting to distinguish between missing storage adapters and missing version data. I have no feedback to provide.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ents version is missing
When totalElements crosses a 32-element batch boundary, contractTreeElements jumps by 32. If the local chairman tree hasn't merged that batch yet (e.g. due to indexer lag or sync gaps), getChairmanMerkleVersion returns undefined for the exact version — causing hybrid mode to silently skip local proof and fall back to the remote freezer service.
Fix: when the exact version is unavailable, fall back to the latest stored version that still covers all requested CIDs. The returned latest_cid is adjusted to match the version actually used, so pickMerkleRootIndex finds the correct on-chain root (its search window already tolerates this offset).
Verified: 12h / 550+ cycles / 356 transfers with zero proof errors on Sepolia testnet, with the remote freezer service completely unreachable.
Summary
Brief description of changes.
Changes
Testing
pnpm run testpassespnpm run buildsucceedspnpm run type-checkpassesRelated Issues
Closes #