Dual-write logic duplication#1969
Conversation
…tocol testing Replaces the flat `DigestCache` HashMap in `SimNode` with `SimStorage`, which uses the real `calimero-storage::Index<MainStorage>` implementation backed by `InMemoryDB`. This enables accurate simulation of sync protocols that depend on tree structure (e.g., HashComparison). Key changes: - Add `SimStorage` with in-memory Merkle tree using `Store + InMemoryDB` - Add `RuntimeEnv` bridge to connect storage Key operations - Update `SimNode` to use hybrid storage: real tree + metadata cache - Add `insert_entity_hierarchical()` for creating proper tree depth - Make `Index::get_index()` and `get_children_of()` public for traversal - Add tree structure verification tests for protocol selection - Fix: prevent self-referencing cycle in hierarchical insertion The entity counting now correctly excludes intermediate tree nodes, and `iter_entities()` returns only "real" entities (with metadata). Tree depth now affects protocol selection: - SubtreePrefetch scenarios have max_depth > 3 - LevelWise scenarios have max_depth <= 2 Spec reference: Simulation Framework Spec §5, §7, §11 Co-authored-by: cursor[bot] <cursor@calimero.network>
Remove duplicated dual-write logic in apply_storage_op by delegating to insert_entity_with_metadata for Insert/Update operations. This ensures the Merkle tree and entity_metadata cache stay in lockstep, preventing future bugs from divergent implementations.
|
Cursor Agent can help with this pull request. Just |
|
Your PR title does not adhere to the Conventional Commits convention: Common errors to avoid:
|
There was a problem hiding this comment.
🤖 AI Code Reviewer
Reviewed by 3 agents | Quality score: 95% | Review time: 117.9s
✅ No Issues Found
All agents reviewed the code and found no issues. LGTM! 🎉
🤖 Generated by AI Code Reviewer | Review ID: review-9e7eef31
|
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
|
"This pull request has been automatically closed because it has been inactive for more than 7 days. Please reopen and see this PR through its review if it is essential." |
sync_sim: Refactorapply_storage_opto reuseinsert_entity_with_metadataDescription
Refactored
apply_storage_opto delegate toself.insert_entity_with_metadatafor Insert/Update operations. This fixes a bug (c8b01083-74ac-4bc1-b56f-4397d8eeff1d) where identical dual-write logic for the Merkle tree and metadata cache was duplicated across both methods. The change eliminates code duplication, reducing the risk of inconsistencies between the Merkle tree and theentity_metadatacache if the dual-write logic were to be modified in only one place.Test plan
The existing
sync_simtests were run usingcargo test. All 13 tests passed successfully after the change. This refactoring is within test utilities and does not affect the user interface or require new end-to-end tests.Documentation update
No public or internal documentation updates are required.