Skip to content

Conversation

@knst
Copy link
Collaborator

@knst knst commented Jun 21, 2025

Issue being fixed or feature implemented

Addressed some exception for circular dependencies.

What was done?

See each commit. Most changes here are just moving functions between files, git diff --color-moved=zebra may help to review it.

Though, GetAllQuorumMembers() is now called by BuildNewListFromBlock() compared to current behavior in develop branch.

How Has This Been Tested?

Removed these exception from linter:

-    "core_io -> evo/cbtx -> evo/simplifiedmns -> core_io",
-    "evo/cbtx -> evo/simplifiedmns -> evo/cbtx",
-    "evo/deterministicmns -> llmq/commitment -> evo/deterministicmns",
-    "evo/deterministicmns -> llmq/commitment -> validation -> evo/deterministicmns",
-    "evo/deterministicmns -> llmq/commitment -> validation -> txmempool -> evo/deterministicmns",
-    "evo/deterministicmns -> llmq/utils -> evo/deterministicmns",
-    "evo/deterministicmns -> llmq/utils -> llmq/snapshot -> evo/simplifiedmns -> evo/deterministicmns",
-    "evo/deterministicmns -> llmq/utils -> net -> evo/deterministicmns",
-    "evo/deterministicmns -> validationinterface -> evo/deterministicmns",
-    "evo/deterministicmns -> validationinterface -> governance/vote -> evo/deterministicmns",
+    "core_io -> evo/assetlocktx -> llmq/signing -> net_processing -> evo/simplifiedmns -> core_io",

New one appeared in the list because it is a longer circular dependency that always has been here but has been hidden by shorter loop: core_io -> evo/cbtx -> evo/simplifiedmns -> core_io.

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

This set of changes refactors the management and validation of deterministic masternode lists and chainlocks by relocating key logic from the deterministic masternode manager to the special transaction processor. The methods for building new masternode lists from blocks and handling quorum commitments are removed from the deterministic masternode manager and implemented in the special transaction processor. Functions related to simplified masternode list Merkle root calculation and chainlock validation are removed from evo/cbtx and reintroduced or newly implemented in other modules such as specialtxman and simplifiedmns. The interface for validating coinbase special transactions is simplified by removing parameters related to the masternode list and chainlock handler. Miner and test code are updated to use the special transaction manager’s interface for building masternode lists. Obsolete includes, forward declarations, and member variables are removed accordingly. The expected circular dependency list is updated to reflect the new module dependencies. No fundamental block or transaction validation logic outside these refactorings is changed.


📜 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 d2fff7d and 86c3dad.

📒 Files selected for processing (9)
  • src/evo/deterministicmns.cpp (2 hunks)
  • src/evo/deterministicmns.h (0 hunks)
  • src/evo/dmnstate.cpp (0 hunks)
  • src/evo/specialtxman.cpp (6 hunks)
  • src/evo/specialtxman.h (3 hunks)
  • src/node/miner.cpp (3 hunks)
  • src/node/miner.h (0 hunks)
  • src/test/util/setup_common.cpp (2 hunks)
  • test/lint/lint-circular-dependencies.py (1 hunks)
💤 Files with no reviewable changes (3)
  • src/evo/dmnstate.cpp
  • src/node/miner.h
  • src/evo/deterministicmns.h
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/evo/specialtxman.h
  • src/test/util/setup_common.cpp
  • test/lint/lint-circular-dependencies.py
  • src/node/miner.cpp
  • src/evo/specialtxman.cpp
🧰 Additional context used
🧠 Learnings (2)
📓 Common learnings
Learnt from: kwvg
PR: dashpay/dash#6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
PR: dashpay/dash#6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: knst
PR: dashpay/dash#6511
File: src/evo/deterministicmns.cpp:1369-1373
Timestamp: 2025-01-07T18:50:44.838Z
Learning: The functions `MigrateDBIfNeeded` and `MigrateDBIfNeeded2` in `src/evo/deterministicmns.cpp` are temporary and will be removed in a future version. Refactoring suggestions for these functions should be avoided.
Learnt from: kwvg
PR: dashpay/dash#6665
File: src/evo/providertx.h:82-82
Timestamp: 2025-06-06T11:53:09.094Z
Learning: In ProTx serialization code (SERIALIZE_METHODS), version checks should use hardcoded maximum flags (/*is_basic_scheme_active=*/true, /*is_extended_addr=*/true) rather than deployment-based flags. This is because serialization code should be able to deserialize any structurally valid ProTx up to the maximum version the code knows how to handle, regardless of current consensus validity. Validation code, not serialization code, is responsible for checking whether a ProTx version is consensus-valid based on deployment status.
src/evo/deterministicmns.cpp (5)
Learnt from: knst
PR: dashpay/dash#6511
File: src/evo/deterministicmns.cpp:1369-1373
Timestamp: 2025-01-07T18:50:44.838Z
Learning: The functions `MigrateDBIfNeeded` and `MigrateDBIfNeeded2` in `src/evo/deterministicmns.cpp` are temporary and will be removed in a future version. Refactoring suggestions for these functions should be avoided.
Learnt from: kwvg
PR: dashpay/dash#6718
File: test/functional/test_framework/test_framework.py:2102-2102
Timestamp: 2025-06-09T16:43:20.996Z
Learning: In the test framework consolidation PR (#6718), user kwvg prefers to limit functional changes to those directly related to MasternodeInfo, avoiding scope creep even for minor improvements like error handling consistency.
Learnt from: kwvg
PR: dashpay/dash#6543
File: src/wallet/receive.cpp:240-251
Timestamp: 2025-02-06T14:34:30.466Z
Learning: Pull request #6543 is focused on move-only changes and refactoring, specifically backporting from Bitcoin. Behavior changes should be proposed in separate PRs.
Learnt from: kwvg
PR: dashpay/dash#6665
File: src/evo/providertx.h:82-82
Timestamp: 2025-06-06T11:53:09.094Z
Learning: In ProTx serialization code (SERIALIZE_METHODS), version checks should use hardcoded maximum flags (/*is_basic_scheme_active=*/true, /*is_extended_addr=*/true) rather than deployment-based flags. This is because serialization code should be able to deserialize any structurally valid ProTx up to the maximum version the code knows how to handle, regardless of current consensus validity. Validation code, not serialization code, is responsible for checking whether a ProTx version is consensus-valid based on deployment status.
Learnt from: kwvg
PR: dashpay/dash#6530
File: src/validation.cpp:360-362
Timestamp: 2025-01-14T08:37:16.955Z
Learning: The UpdateTransactionsFromBlock() method in txmempool.cpp takes parameters in the order: vHashUpdate, ancestor_size_limit, ancestor_count_limit. The size limit comes before the count limit.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (5)
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: x86_64-pc-linux-gnu / Build depends
  • GitHub Check: x86_64-pc-linux-gnu_multiprocess / Build depends
  • GitHub Check: x86_64-w64-mingw32 / Build depends
  • GitHub Check: x86_64-apple-darwin / Build depends
🔇 Additional comments (2)
src/evo/deterministicmns.cpp (2)

23-23: LGTM: Include addition supports existing range-based usage.

The <util/irange.h> include is correctly added to support the irange::range calls used in methods like GetProjectedMNPayees (lines 229, 240, 247).


591-592: LGTM: Method signature simplification aligns with refactoring objectives.

The removal of const CCoinsViewCache& view and llmq::CQuorumSnapshotManager& qsnapman parameters from ProcessBlock is consistent with moving the complex masternode list building logic to specialtxman.cpp. This helps break circular dependencies as intended.

✨ 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: 0

🧹 Nitpick comments (3)
src/node/miner.cpp (1)

122-179: Consider optimizing duplicate call to GetBestChainLock()

At line 175, chainlock_handler.GetBestChainLock().getSig() is called again instead of reusing best_clsig.getSig(). This is a minor inefficiency that could be avoided.

         // Inserting our best CL
         bestCLHeightDiff = pindexPrev->nHeight - best_clsig.getHeight();
-        bestCLSignature = chainlock_handler.GetBestChainLock().getSig();
+        bestCLSignature = best_clsig.getSig();
src/evo/cbtx.h (1)

66-68: Consider clarifying the comment about block processing requirement.

The comment states "This can only be done after the block has been fully processed" but doesn't specify what "fully processed" means in this context. Consider being more explicit about the requirement.

-// This can only be done after the block has been fully processed, as otherwise we won't have the finished MN list
+// This can only be done after the block has been fully processed (i.e., after BuildNewListFromBlock has been called),
+// as otherwise we won't have the finished MN list required for validation
src/evo/specialtxman.cpp (1)

424-427: Remove redundant condition in collateral check.

The condition dmn->collateralOutpoint == in.prevout is redundant because GetMNByCollateral(in.prevout) already ensures this equality when it returns a non-null result.

             auto dmn = newList.GetMNByCollateral(in.prevout);
-            if (dmn && dmn->collateralOutpoint == in.prevout) {
+            if (dmn) {
                 newList.RemoveMN(dmn->proTxHash);
📜 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 48431e5.

📒 Files selected for processing (13)
  • src/evo/cbtx.cpp (1 hunks)
  • src/evo/cbtx.h (1 hunks)
  • src/evo/deterministicmns.cpp (2 hunks)
  • src/evo/deterministicmns.h (0 hunks)
  • src/evo/dmnstate.cpp (0 hunks)
  • src/evo/simplifiedmns.cpp (1 hunks)
  • src/evo/simplifiedmns.h (1 hunks)
  • src/evo/specialtxman.cpp (6 hunks)
  • src/evo/specialtxman.h (2 hunks)
  • src/node/miner.cpp (3 hunks)
  • src/node/miner.h (0 hunks)
  • src/test/util/setup_common.cpp (2 hunks)
  • test/lint/lint-circular-dependencies.py (1 hunks)
💤 Files with no reviewable changes (3)
  • src/evo/dmnstate.cpp
  • src/node/miner.h
  • src/evo/deterministicmns.h
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: mac-build / Build source
  • GitHub Check: linux64_tsan-build / Build source
  • GitHub Check: linux64_multiprocess-build / Build source
  • GitHub Check: linux64_nowallet-build / Build source
  • GitHub Check: arm-linux-build / Build source
  • GitHub Check: linux64_sqlite-build / Build source
  • GitHub Check: linux64_ubsan-build / Build source
  • GitHub Check: linux64-build / Build source
  • GitHub Check: linux64_fuzz-build / Build source
🔇 Additional comments (13)
src/evo/simplifiedmns.h (1)

182-183: LGTM: Well-designed function signature for merkle root calculation.

The function signature follows established validation patterns with proper error reporting via BlockValidationState and uses move semantics for the input list to optimize performance.

test/lint/lint-circular-dependencies.py (1)

47-47: Expected addition of newly exposed circular dependency.

This aligns with the PR objectives - the refactoring revealed a previously hidden circular dependency that was masked by the removed cycles. Adding it to the expected list is appropriate for this refactoring-focused PR.

src/evo/simplifiedmns.cpp (1)

406-448: Excellent implementation with thread safety and performance optimizations.

The function demonstrates several best practices:

  • Thread-safe caching with proper mutex protection
  • Performance benchmarking for monitoring
  • Validation of merkle tree mutations
  • Proper exception handling with detailed error states
  • Efficient use of move semantics for cache updates

The caching strategy will provide significant performance benefits for repeated calculations.

src/test/util/setup_common.cpp (1)

493-493: Correct update to use new special transaction manager interface.

This change appropriately updates the test infrastructure to use the refactored BuildNewListFromBlock method that was moved from CDeterministicMNManager to CSpecialTxProcessor, maintaining test functionality after the architectural changes.

src/evo/specialtxman.h (2)

8-9: Good additions for new functionality.

The new includes (gsl/pointers.h for parameter safety, optional for return values) and forward declaration properly support the new BuildNewListFromBlock method while minimizing compilation dependencies.

Also applies to: 19-19


75-80: Well-designed method signature with clear documentation.

The BuildNewListFromBlock method signature demonstrates good practices:

  • Uses gsl::not_null to express non-null parameter requirements
  • Proper thread safety annotation with EXCLUSIVE_LOCKS_REQUIRED(cs_main)
  • Clear documentation about the block hash limitation
  • Appropriate parameter types for the masternode list building functionality
src/node/miner.cpp (1)

288-314: LGTM! Clean refactoring of masternode list building.

The changes properly move the masternode list building responsibility from CDeterministicMNManager to CSpecialTxProcessor, and the integration of the new CalcCbTxBestChainlock helper function is well done.

src/evo/cbtx.cpp (1)

45-60: LGTM! Clean separation of concerns.

The simplification of CheckCbTxMerkleRoots to only handle quorum merkle root validation is consistent with the refactoring goals. The removal of MN list and chainlock validation logic properly breaks the circular dependencies.

src/evo/deterministicmns.cpp (1)

584-586: LGTM! Clean removal of circular dependencies.

The simplification of the ProcessBlock signature and removal of BuildNewListFromBlock and HandleQuorumCommitment methods successfully breaks the circular dependencies as intended.

src/evo/specialtxman.cpp (4)

29-94: Well-implemented chainlock validation with effective caching.

The CheckCbTxBestChainlock function properly validates chainlock signatures with good performance optimizations through caching. The logic correctly handles all cases including null chainlocks and enforces proper chainlock progression rules.


156-171: LGTM! Proper handling of DKG participation failures.

The function correctly punishes masternodes that fail DKG participation with an appropriate 66% penalty, which aligns with the comment about banning after 3 failures within a payment cycle.


521-527: Good addition of CCbTx requirement validation.

The check ensures that a coinbase special transaction is present when DIP0003 is active and merkle root checks are enabled, which is essential for maintaining consensus rules.


583-615: LGTM! Clean integration of masternode list building.

The integration of BuildNewListFromBlock and merkle root calculation is well-implemented with proper error handling and performance logging.

@knst knst force-pushed the fix-circular-deterministicmn branch from 48431e5 to 3ee1a1b Compare June 21, 2025 14:41
@knst knst requested review from PastaPastaPasta and UdjinM6 June 24, 2025 13:37
@knst knst requested a review from kwvg July 1, 2025 15:19
Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

Can confirm that 5090031 and 9b33044 are mostly move-only with git log -p -n1 --color-moved=dimmed_zebra. Minor comments.

@knst knst requested a review from kwvg July 1, 2025 18:44
kwvg
kwvg previously approved these changes Jul 1, 2025
Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

utACK 2727a68

UdjinM6
UdjinM6 previously approved these changes Jul 3, 2025
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 2727a68

@github-actions
Copy link

github-actions bot commented Jul 4, 2025

This pull request has conflicts, please rebase.

@knst knst dismissed stale reviews from UdjinM6 and kwvg via 566ac0f July 5, 2025 13:03
@knst knst force-pushed the fix-circular-deterministicmn branch from 2727a68 to 566ac0f Compare July 5, 2025 13:03
@knst knst requested review from UdjinM6 and kwvg July 5, 2025 13:07
kwvg
kwvg previously approved these changes Jul 6, 2025
Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

utACK 566ac0f

UdjinM6
UdjinM6 previously approved these changes Jul 6, 2025
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 566ac0f

@github-actions
Copy link

github-actions bot commented Jul 7, 2025

This pull request has conflicts, please rebase.

@knst knst dismissed stale reviews from UdjinM6 and kwvg via d2fff7d July 7, 2025 11:16
@knst knst force-pushed the fix-circular-deterministicmn branch from 566ac0f to d2fff7d Compare July 7, 2025 11:16
}

=======
>>>>>>> a67cfae449 (refactor: remove dependency of evo/deterministicmns on llmq/utils and llmq/commitment)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Leftover conflict indicator

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

should be OK now

@knst knst force-pushed the fix-circular-deterministicmn branch from d2fff7d to 86c3dad Compare July 7, 2025 19:13
@knst knst requested a review from kwvg July 7, 2025 19:17
Copy link
Collaborator

@kwvg kwvg left a comment

Choose a reason for hiding this comment

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

utACK 86c3dad

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.

rebase looks clean

re-utACK 86c3dad

@PastaPastaPasta PastaPastaPasta merged commit 4e7b5ac into dashpay:develop Jul 9, 2025
55 of 60 checks passed
@knst knst deleted the fix-circular-deterministicmn branch July 16, 2025 08:13
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.

4 participants