Skip to content

Use LfmbTree for locks, introducing LockIndex and an index from LockId - #1652

Merged
limemloh merged 7 commits into
release/p11from
limemloh/cor-2295-locks-real-state-implementation
Jun 8, 2026
Merged

Use LfmbTree for locks, introducing LockIndex and an index from LockId#1652
limemloh merged 7 commits into
release/p11from
limemloh/cor-2295-locks-real-state-implementation

Conversation

@limemloh

@limemloh limemloh commented Jun 3, 2026

Copy link
Copy Markdown
Collaborator

Purpose

Implements the real persistent state model for protocol-level locks, replacing the dummy in-memory BTreeMap-backed implementation. Closes COR-2295.

Changes

  • Introduced LockIndex: a sequential internal key type for the lock LfmbTree, consistent with how TokenIndex works for tokens. It is intentionally internal and must never appear in the public API, events, or state hashing.

  • Replaced BTreeMap<LockId, PersistentLockP11> with LfmbTree<LockIndex, Option<PersistentLockP11>>: the tree uses None entries as tombstones for deleted (cancelled) locks. A companion im::HashMap<LockId, LockIndex> serves as a derived in-memory
    reverse index, rebuilt on every load from the blob store by scanning the tree and reading each live lock's configuration.

  • Embedded LockId inside LockConfiguration: the create_lock call no longer takes a separate lock_id argument — the ID is extracted from the configuration. This avoids dual-passing and makes the configuration self-contained.

  • Changed delete_lock to return bool: the return type changed from Option<LockP11> (the deleted lock) to bool (whether a lock was deleted). All callers already held a LockP11 reference and only needed to know whether deletion occurred.

  • PersistentLockP11::configuration stored as HashedCacheableRef: the lock configuration is now stored as a blob-store reference rather than inlined, consistent with how token configuration is stored.

  • Fixed lock_list ordering and documented the lack of guarantee: the switch from BTreeMap to im::HashMap for the internal index means lock_list no longer returns lock IDs in sorted order. The trait doc now explicitly states no ordering guarantee and
    warns callers not to drive state-mutating scheduler operations from the unordered iterator without first sorting, to preserve consensus safety.

Checklist

  • My code follows the style of this project.
  • The code compiles without warnings.
  • I have performed a self-review of the changes.
  • I have documented my code, in particular the intent of the
    hard-to-understand areas.
  • (If necessary) I have updated the CHANGELOG.

CLA acceptance

_Remove if not applicable.

By submitting the contribution I accept the terms and conditions of the
Contributor License Agreement v1.0

@limemloh
limemloh force-pushed the limemloh/cor-2295-locks-real-state-implementation branch 2 times, most recently from 669dacc to ceb53a6 Compare June 3, 2026 14:40
@codecov

codecov Bot commented Jun 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.43396% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 64.14%. Comparing base (404cb8f) to head (4addeb1).
⚠️ Report is 3 commits behind head on release/p11.

Files with missing lines Patch % Lines
...block-state/src/entity/protocol_level_locks/p11.rs 82.45% 10 Missing ⚠️
plt/plt-block-state/src/block_state.rs 28.57% 5 Missing ⚠️
plt/plt-block-state/src/persistent/cacheable.rs 0.00% 5 Missing ⚠️
plt/plt-block-state/src/persistent/blob_store.rs 84.21% 3 Missing ⚠️
...k-state/src/persistent/protocol_level_locks/p11.rs 94.73% 3 Missing ⚠️
plt/plt-block-state/src/persistent/hash.rs 80.00% 1 Missing ⚠️
plt/plt-scheduler/src/scheduler/plt_scheduler.rs 96.29% 1 Missing ⚠️
Additional details and impacted files
@@               Coverage Diff               @@
##           release/p11    #1652      +/-   ##
===============================================
+ Coverage        64.07%   64.14%   +0.06%     
===============================================
  Files              376      376              
  Lines            75007    75150     +143     
  Branches          3013     3014       +1     
===============================================
+ Hits             48064    48208     +144     
+ Misses           23930    23928       -2     
- Partials          3013     3014       +1     
Files with missing lines Coverage Δ
...cordiumTests/EndToEnd/CredentialDeploymentTests.hs 82.26% <100.00%> (ø)
...mTests/EndToEnd/TransactionTableIntegrationTest.hs 91.50% <100.00%> (ø)
...s/consensus/ConcordiumTests/KonsensusV1/CatchUp.hs 82.15% <100.00%> (ø)
...us/ConcordiumTests/KonsensusV1/Consensus/Blocks.hs 76.02% <100.00%> (ø)
plt/plt-block-state/src/entity/block_state/p11.rs 98.30% <100.00%> (ø)
.../plt-block-state/src/persistent/block_state/p11.rs 97.64% <100.00%> (+0.30%) ⬆️
plt/plt-scheduler/src/locks/lock_configuration.rs 92.95% <100.00%> (ø)
plt/plt-block-state/src/persistent/hash.rs 94.73% <80.00%> (-5.27%) ⬇️
plt/plt-scheduler/src/scheduler/plt_scheduler.rs 79.86% <96.29%> (+0.31%) ⬆️
plt/plt-block-state/src/persistent/blob_store.rs 78.78% <84.21%> (+7.53%) ⬆️
... and 4 more

... and 6 files with indirect coverage changes

@limemloh
limemloh force-pushed the limemloh/cor-2295-locks-real-state-implementation branch from ceb53a6 to 5870058 Compare June 3, 2026 14:46
Comment thread plt/plt-scheduler/src/scheduler/plt_scheduler.rs
@limemloh
limemloh requested review from allanbrondum and soerenbf June 3, 2026 14:52
Comment thread plt/plt-block-state/src/entity/protocol_level_locks/p11.rs
Comment thread plt/plt-block-state/src/persistent/protocol_level_locks/p11.rs Outdated
@limemloh
limemloh force-pushed the limemloh/cor-2295-locks-real-state-implementation branch from 2ea498a to 7762f5e Compare June 4, 2026 13:02
Comment thread plt/plt-block-state/tests/block_state_p11.rs
Comment thread plt/plt-block-state/src/persistent/protocol_level_locks/p11.rs Outdated
Comment thread plt/plt-block-state/src/persistent/protocol_level_locks/p11.rs
Comment thread plt/plt-block-state/src/persistent/protocol_level_locks/p11.rs Outdated
Comment thread plt/plt-block-state/src/persistent/protocol_level_locks/p11.rs
Base automatically changed from lock-transfer to release/p11 June 4, 2026 19:47
@limemloh
limemloh merged commit 8f60d31 into release/p11 Jun 8, 2026
8 checks passed
@limemloh
limemloh deleted the limemloh/cor-2295-locks-real-state-implementation branch June 8, 2026 20:19
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.

3 participants