Skip to content

perf(dash)!: share masternode and quorum maps between masternode lists - #1066

Merged
ZocoLini merged 1 commit into
devfrom
perf/masternode-shared-list-maps
Sep 25, 2026
Merged

ZocoLini merged 1 commit into
devfrom
perf/masternode-shared-list-maps

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Every apply_diff cloned the base list's masternode and quorum maps whole, so the engine held a full copy of the list per block it applied. On mainnet the list changes in about 290 of every 4608 blocks, so nearly all of those copies were identical.

MasternodeList::masternodes and quorums become Arc<MasternodeMap> and Arc<QuorumMap>, with every entry behind its own Arc:

  • a diff that touches no masternode shares the base list's masternode map, and one that touches no quorum (nor carries ChainLock signatures) shares its quorum map;
  • a diff that does change a map copies it on write, and the copy still shares every entry it kept;
  • a quorum status change goes through set_quorum_status_in_lists, which writes it once per distinct map, so lists that shared a map before the change keep sharing the updated one instead of splitting into copies.

The status update loops in apply_diff, verify_non_rotating_masternode_list_quorums and the rotated cycle paths go through that helper; what they compute is unchanged.

Measured on the mainnet list at 2_227_096 (3147 masternodes) with one empty diff per block for a 288-block cycle, release build, RSS growth for 288 lists: dev 311.6 MiB (~1.08 MiB per block, unbounded), this branch 1.3 MiB.

BREAKING CHANGE: MasternodeList::masternodes is Arc<BTreeMap<ProTxHash, Arc<QualifiedMasternodeListEntry>>> and quorums is Arc<BTreeMap<LLMQType, BTreeMap<QuorumHash, Arc<QualifiedQuorumEntry>>>>. Reads through .values()/.get() deref as before; writers go through Arc::make_mut. serde gains its rc feature.

Verified: fmt, clippy --workspace --all-features --all-targets -D warnings, dashcore 618 (2 new: an empty diff shares both maps; a status change keeps three lists on one map), dash-spv 570 + dashd_masternode 10 + dashd_sync 32, dash-spv-ffi 49 + dashd_sync 7.

PR Hygiene · 0b2cf4c

  • Bots — coderabbitai ✓
  • Self-review — post /self-reviewed
  • Within your 5 open PRs
  • Build failed
  • Approvals
    • files with no dedicated owner (dash/Cargo.toml, dash/src/sml/masternode_list/apply_diff.rs, dash/src/sml/masternode_list/builder.rs and 7 more) — QuantumExplorer or xdustinface

When every box is checked the PR Hygiene check passes and this can merge.

Summary by CodeRabbit

  • Bug Fixes

    • Quorum verification status updates now propagate across affected masternode lists, including rotating quorums.
    • Lists with missing quorums or unchanged statuses are handled without disrupting updates to other lists.
  • Improvements

    • Masternode list updates can reuse unchanged data, reducing unnecessary copying during updates.

@github-actions github-actions Bot added the merge-conflict The PR conflicts with the target branch. label Sep 25, 2026
@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: dashpay/rust-dashcore/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 54948269-d8eb-4667-b547-ff7f4b65d91c

📥 Commits

Reviewing files that changed from the base of the PR and between de7c18d and 0b2cf4c.

📒 Files selected for processing (10)
  • dash/Cargo.toml
  • dash/src/sml/masternode_list/apply_diff.rs
  • dash/src/sml/masternode_list/builder.rs
  • dash/src/sml/masternode_list/from_diff.rs
  • dash/src/sml/masternode_list/mod.rs
  • dash/src/sml/masternode_list/quorum_helpers.rs
  • dash/src/sml/masternode_list/rotated_quorums_info.rs
  • dash/src/sml/masternode_list/scores_for_quorum.rs
  • dash/src/sml/masternode_list_engine/helpers.rs
  • dash/src/sml/masternode_list_engine/mod.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

Masternode lists now store shared maps and entries using Arc. Diff application uses copy-on-write updates. The engine propagates quorum status changes across affected lists and includes tests for map sharing and status updates.

Changes

Shared List State

Layer / File(s) Summary
Shared map contracts and construction
dash/Cargo.toml, dash/src/sml/masternode_list/mod.rs, dash/src/sml/masternode_list/builder.rs, dash/src/sml/masternode_list/from_diff.rs
MasternodeList and its builder use shared map types with Arc-wrapped entries. Diff conversion constructs these shared maps. The optional Serde dependency enables the rc feature.
Copy-on-write diff application and access
dash/src/sml/masternode_list/apply_diff.rs, dash/src/sml/masternode_list/quorum_helpers.rs, dash/src/sml/masternode_list/rotated_quorums_info.rs, dash/src/sml/masternode_list/scores_for_quorum.rs
Diff application clones map handles and obtains mutable access when changes require it. Quorum lookup and masternode iteration access the underlying entries.
Quorum status propagation and validation
dash/src/sml/masternode_list_engine/helpers.rs, dash/src/sml/masternode_list_engine/mod.rs
The engine routes quorum status changes through a shared helper. Validation and revalidation collect changes before propagating them across affected lists. Tests check map sharing and quorum status updates.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Refactor

Suggested reviewers: quantumexplorer

Merge Risk: ⚪ Minimal · up to 0b2cf

No actionable issue remains from the inspected changes; the PR is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to 0b2cf

Shared list state affects quorum verification across blocks and changes a public API. The reviewed paths retain key validation controls, but the breadth of the state change and incomplete downstream coverage warrant a design review.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Peer-supplied list data can reach a dash-spv consumer and the list engine; an erroneous shared-status transition could affect multiple locally retained block lists rather than only one snapshot.

Trust Boundaries and Controls

  • observed — The reviewed synchronization caller enables QR-info verification, new diff quorum entries start unverified, and rotated-cycle storage requires every supplied entry to be Verified.

Resilience and Maintainability Implications

  • inferred — Copy-on-write confines failed lower-level diff construction to local map handles before publication; direct tests of repeated application and divergent-branch recovery were not established in the focused evidence.

Hardening Proposals

  • proposed — Exercise replay and divergent-block transitions in which lists first share a quorum map and later diverge, checking that verification status follows the intended branch and cannot be inherited as stale Verified state.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 56.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 9 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: sharing masternode and quorum maps between masternode lists for performance. The breaking-change marker is appropriate because public map …
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 56.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 9 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🛠️ Fix failing CI checks 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

This PR has merge conflicts with the base branch. Please rebase or merge the base branch into your branch to resolve them.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Sep 25, 2026
@ZocoLini
ZocoLini force-pushed the perf/masternode-shared-list-maps branch from 74a91f2 to b099486 Compare September 25, 2026 16:04
@github-actions github-actions Bot removed merge-conflict The PR conflicts with the target branch. labels Sep 25, 2026
Every `apply_diff` cloned the base list's masternode and quorum maps whole,
so the engine held a full copy of the list per block it applied. On mainnet
the list changes in about 290 of every 4608 blocks, so nearly all of those
copies were identical.

`MasternodeList::masternodes` and `quorums` become `Arc<MasternodeMap>` and
`Arc<QuorumMap>`, with every entry behind its own `Arc`:

- a diff that touches no masternode shares the base list's masternode map,
  and one that touches no quorum (nor carries ChainLock signatures) shares
  its quorum map;
- a diff that does change a map copies it on write, and the copy still
  shares every entry it kept;
- a quorum status change goes through `set_quorum_status_in_lists`, which
  writes it once per distinct map, so lists that shared a map before the
  change keep sharing the updated one instead of splitting into copies.

The status update loops in `apply_diff`, `verify_non_rotating_masternode_list_quorums`
and the rotated cycle paths go through that helper; what they compute is
unchanged.

Measured on the mainnet list at 2_227_096 (3147 masternodes) with one empty
diff per block for a 288-block cycle, release build, RSS growth for 288 lists:
dev 311.6 MiB (~1.08 MiB per block, unbounded), this branch 1.3 MiB.

BREAKING CHANGE: `MasternodeList::masternodes` is `Arc<BTreeMap<ProTxHash,
Arc<QualifiedMasternodeListEntry>>>` and `quorums` is
`Arc<BTreeMap<LLMQType, BTreeMap<QuorumHash, Arc<QualifiedQuorumEntry>>>>`.
Reads through `.values()`/`.get()` deref as before; writers go through
`Arc::make_mut`. `serde` gains its `rc` feature.

Verified: fmt, clippy --workspace --all-features --all-targets -D warnings,
dashcore 618 (2 new: an empty diff shares both maps; a status change keeps
three lists on one map), dash-spv 570 + dashd_masternode 10 + dashd_sync 32,
dash-spv-ffi 49 + dashd_sync 7.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ZocoLini
ZocoLini force-pushed the perf/masternode-shared-list-maps branch from b099486 to 0b2cf4c Compare September 25, 2026 16:34
@codecov

codecov Bot commented Sep 25, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.19651% with 11 lines in your changes missing coverage. Please review.
✅ Project coverage is 77.39%. Comparing base (de7c18d) to head (0b2cf4c).

Files with missing lines Patch % Lines
dash/src/sml/masternode_list_engine/mod.rs 93.47% 6 Missing ⚠️
dash/src/sml/masternode_list/quorum_helpers.rs 33.33% 4 Missing ⚠️
dash/src/sml/masternode_list_engine/helpers.rs 98.95% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1066      +/-   ##
==========================================
- Coverage   77.53%   77.39%   -0.14%     
==========================================
  Files         317      317              
  Lines       80681    80742      +61     
==========================================
- Hits        62552    62493      -59     
- Misses      18129    18249     +120     
Flag Coverage Δ
core 78.91% <95.19%> (+0.07%) ⬆️
ffi 50.65% <ø> (-1.34%) ⬇️
rpc 20.00% <ø> (ø)
spv 92.10% <ø> (+0.07%) ⬆️
wallet 80.22% <ø> (ø)
Files with missing lines Coverage Δ
dash/src/sml/masternode_list/apply_diff.rs 95.03% <100.00%> (+0.54%) ⬆️
dash/src/sml/masternode_list/builder.rs 76.92% <100.00%> (ø)
dash/src/sml/masternode_list/from_diff.rs 94.28% <100.00%> (ø)
dash/src/sml/masternode_list/mod.rs 91.66% <100.00%> (ø)
...sh/src/sml/masternode_list/rotated_quorums_info.rs 97.87% <100.00%> (+0.04%) ⬆️
dash/src/sml/masternode_list/scores_for_quorum.rs 100.00% <100.00%> (ø)
dash/src/sml/masternode_list_engine/helpers.rs 96.13% <98.95%> (+1.85%) ⬆️
dash/src/sml/masternode_list/quorum_helpers.rs 23.65% <33.33%> (+0.06%) ⬆️
dash/src/sml/masternode_list_engine/mod.rs 89.21% <93.47%> (+0.20%) ⬆️

... and 22 files with indirect coverage changes

@github-actions

github-actions Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Sep 25, 2026
@ZocoLini

Copy link
Copy Markdown
Collaborator Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Sep 25, 2026
@ZocoLini
ZocoLini merged commit df1edff into dev Sep 25, 2026
83 of 89 checks passed
@ZocoLini
ZocoLini deleted the perf/masternode-shared-list-maps branch September 25, 2026 22:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant