Skip to content

Dual-write logic duplication#1969

Draft
cursor[bot] wants to merge 2 commits intomasterfrom
cursor/dual-write-logic-duplication-6182
Draft

Dual-write logic duplication#1969
cursor[bot] wants to merge 2 commits intomasterfrom
cursor/dual-write-logic-duplication-6182

Conversation

@cursor
Copy link
Contributor

@cursor cursor bot commented Feb 12, 2026

sync_sim: Refactor apply_storage_op to reuse insert_entity_with_metadata

Description

Refactored apply_storage_op to delegate to self.insert_entity_with_metadata for 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 the entity_metadata cache if the dual-write logic were to be modified in only one place.

Test plan

The existing sync_sim tests were run using cargo 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.


xilosada and others added 2 commits February 12, 2026 11:56
…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
Copy link
Contributor Author

cursor bot commented Feb 12, 2026

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@github-actions
Copy link

Your PR title does not adhere to the Conventional Commits convention:

<type>(<scope>): <subject>

Common errors to avoid:

  1. The title must be in lower case.
  2. Allowed type values are: build, ci, docs, feat, fix, perf, refactor, test.

Copy link

@meroreviewer meroreviewer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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

Base automatically changed from feat/sim-storage-infra to master February 12, 2026 11:53
@github-actions
Copy link

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.

@github-actions github-actions bot added the Stale label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants