Skip to content

Conversation

@knst
Copy link
Collaborator

@knst knst commented Jun 21, 2025

Issue being fixed or feature implemented

Masternodes already sorted with the same modifier inside GetMNUsageBySnapshot, no need to re-sort them inside GetQuorumQuarterMembersBySnapshot.

What was done?

Removed extra sort of already sorted vectors; removed duplicated calculation of modifier, simplified GetMNUsageBySnapshot by inlining it.
Also several methods are changed to accept CDeterministicMNList instead of CDeterministicMNManager.

How Has This Been Tested?

It improves significantly performance of llmq::utils::GetAllQuorumMembers which is widely used during block validation; for many RPC calls, for processing some network messages, for masternodes participating in quorums.
Despite 25% improvement for performance of llmq::utils::GetAllQuorumMembers overall improvement for indexing is less than 1% of total CPU time (thanks to caches).

perf for PR:
image

perf for develop:
image

Breaking Changes

N/A

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added or updated relevant unit/integration/functional/e2e tests
  • I have made corresponding changes to the documentation
  • I have assigned this pull request to a milestone

@knst knst added this to the 23 milestone Jun 21, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jun 21, 2025

Walkthrough

The changes refactor quorum member selection functions to accept a CDeterministicMNList directly, instead of a manager object, making the masternode list source explicit. The ComputeQuorumMembers and related functions now require the caller to provide the masternode list for a specific block height. The logic for handling masternode usage by snapshot is simplified and integrated within GetQuorumQuarterMembersBySnapshot, removing the separate helper function. Additionally, the control flow for determining quorum members is updated to reflect these changes, with adjustments to function signatures and internal logic to accommodate the new approach. No changes are made to the core selection algorithms.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9e0f58 and b7b04e5.

📒 Files selected for processing (1)
  • src/llmq/utils.cpp (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/llmq/utils.cpp
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (1)
src/llmq/utils.cpp (1)

416-417: Parameter name inconsistency in function implementation.

As mentioned in the function declaration, the parameter name dmnman should be renamed to mn_list or similar to reflect that it's now a CDeterministicMNList.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ce682f2 and e9e0f58.

📒 Files selected for processing (1)
  • src/llmq/utils.cpp (7 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: arm-linux-gnueabihf / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_nowallet / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
🔇 Additional comments (5)
src/llmq/utils.cpp (5)

59-61: Function signature update looks good.

The change to accept CDeterministicMNList directly makes the masternode list source explicit and aligns with the performance optimization goals.


272-277: Explicit masternode list retrieval implementation is correct.

The logic properly determines the work block index based on V20 activation status and explicitly retrieves the masternode list before passing it to ComputeQuorumMembers.


284-297: Simplified implementation using direct masternode list.

The refactored function correctly uses the provided CDeterministicMNList directly, eliminating the need to fetch it from the manager.


315-316: Consistent pattern of explicit masternode list handling.

The code correctly retrieves the masternode list and passes it to dependent functions, maintaining consistency with the refactoring pattern.

Also applies to: 326-327


616-638: Excellent performance optimization by eliminating redundant sorting.

The refactored implementation efficiently:

  1. Sorts masternodes once with the modifier
  2. Separates them into used/unused while preserving sort order
  3. Constructs the combined list without additional sorting

This eliminates the redundant sorting that was previously done in GetMNUsageBySnapshot, achieving the ~25% performance improvement mentioned in the PR objectives.

@knst knst requested review from PastaPastaPasta and UdjinM6 June 21, 2025 14:37
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK b7b04e5

@PastaPastaPasta PastaPastaPasta merged commit e7ea396 into dashpay:develop Jul 8, 2025
31 of 32 checks passed
@knst knst deleted the perf-snapshot-mns branch July 8, 2025 06:05
knst added a commit to knst/dash that referenced this pull request Jul 8, 2025
…napshot calculation"

This reverts commit e7ea396, reversing
changes made to 2a94cc3.
knst pushed a commit to knst/dash that referenced this pull request Sep 15, 2025
…calculation

b7b04e5 fix: rename dmnman to allMns to match declaration and definition of function; and the meaning (Konstantin Akimov)
e9e0f58 refactor: inline GetMNUsageBySnapshot to simplify code (Konstantin Akimov)
46383b1 perf: optimize GetQuorumQuarterMembersBySnapshot calculation (Konstantin Akimov)
d337579 refactor: use CDeterministicMNList instead CDeterministicMNManager in GetMNUsageBySnapshot (Konstantin Akimov)
790ae0f refactor: use CDeterministicMNList instead of CDeterministicMNManager in ComputeQuorumMembers (Konstantin Akimov)
ac934eb refactor: pass CDeterministicMNList instead of CDeterministicMNManager to BuildNewQuorumQuarterMembers (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  Masternodes already sorted with the same modifier inside `GetMNUsageBySnapshot`, no need to re-sort them inside `GetQuorumQuarterMembersBySnapshot`.

  ## What was done?
  Removed extra sort of already sorted vectors; removed duplicated calculation of modifier, simplified `GetMNUsageBySnapshot` by inlining it.
  Also several methods are changed to accept CDeterministicMNList instead of CDeterministicMNManager.

  ## How Has This Been Tested?
  It improves significantly performance of `llmq::utils::GetAllQuorumMembers` which is widely used during block validation; for many RPC calls, for processing some network messages, for masternodes participating in quorums.
  Despite 25% improvement for performance of `llmq::utils::GetAllQuorumMembers` overall improvement for indexing is less than 1% of total CPU time (thanks to caches).

  `perf` for PR:
  <img width="838" alt="image" src="https://github.com/user-attachments/assets/cb98a0ef-3a4b-4d21-a674-80c300764712" />

  `perf` for develop:
  <img width="838" alt="image" src="https://github.com/user-attachments/assets/879acdac-facd-4a11-b37a-607f4cb31e48" />

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

ACKs for top commit:
  UdjinM6:
    utACK b7b04e5

Tree-SHA512: 069e2a0a2b6ad7dfb092fdfa14e289ecde5bc25a59c7cb0c2fad10a56c9dbacb207b8f4bdd5be0eb88380fd745e0ff21ffc88fe5f24103d376cd3dc83f089787
knst pushed a commit to knst/dash that referenced this pull request Sep 17, 2025
…calculation

b7b04e5 fix: rename dmnman to allMns to match declaration and definition of function; and the meaning (Konstantin Akimov)
e9e0f58 refactor: inline GetMNUsageBySnapshot to simplify code (Konstantin Akimov)
46383b1 perf: optimize GetQuorumQuarterMembersBySnapshot calculation (Konstantin Akimov)
d337579 refactor: use CDeterministicMNList instead CDeterministicMNManager in GetMNUsageBySnapshot (Konstantin Akimov)
790ae0f refactor: use CDeterministicMNList instead of CDeterministicMNManager in ComputeQuorumMembers (Konstantin Akimov)
ac934eb refactor: pass CDeterministicMNList instead of CDeterministicMNManager to BuildNewQuorumQuarterMembers (Konstantin Akimov)

Pull request description:

  ## Issue being fixed or feature implemented
  Masternodes already sorted with the same modifier inside `GetMNUsageBySnapshot`, no need to re-sort them inside `GetQuorumQuarterMembersBySnapshot`.

  ## What was done?
  Removed extra sort of already sorted vectors; removed duplicated calculation of modifier, simplified `GetMNUsageBySnapshot` by inlining it.
  Also several methods are changed to accept CDeterministicMNList instead of CDeterministicMNManager.

  ## How Has This Been Tested?
  It improves significantly performance of `llmq::utils::GetAllQuorumMembers` which is widely used during block validation; for many RPC calls, for processing some network messages, for masternodes participating in quorums.
  Despite 25% improvement for performance of `llmq::utils::GetAllQuorumMembers` overall improvement for indexing is less than 1% of total CPU time (thanks to caches).

  `perf` for PR:
  <img width="838" alt="image" src="https://github.com/user-attachments/assets/cb98a0ef-3a4b-4d21-a674-80c300764712" />

  `perf` for develop:
  <img width="838" alt="image" src="https://github.com/user-attachments/assets/879acdac-facd-4a11-b37a-607f4cb31e48" />

  ## Breaking Changes
  N/A

  ## Checklist:
  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas
  - [ ] I have added or updated relevant unit/integration/functional/e2e tests
  - [ ] I have made corresponding changes to the documentation
  - [x] I have assigned this pull request to a milestone

ACKs for top commit:
  UdjinM6:
    utACK b7b04e5

Tree-SHA512: 069e2a0a2b6ad7dfb092fdfa14e289ecde5bc25a59c7cb0c2fad10a56c9dbacb207b8f4bdd5be0eb88380fd745e0ff21ffc88fe5f24103d376cd3dc83f089787
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