Skip to content

Conversation

@knst
Copy link
Collaborator

@knst knst commented Jan 15, 2026

Issue being fixed or feature implemented

CGovernanceManager should not be directly aware of network stuff.

What was done?

Moved usages of CNetFulfilledRequestManager from CGovernanceManager to NetGovernance where it belongs to, to follow-up #7008

How Has This Been Tested?

Run unit & functional tests.

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.1 milestone Jan 15, 2026
@github-actions
Copy link

⚠️ Potential Merge Conflicts Detected

This PR has potential conflicts with the following open PRs:

Please coordinate with the authors of these PRs to avoid merge conflicts.

@coderabbitai
Copy link

coderabbitai bot commented Jan 15, 2026

Walkthrough

This pull request refactors the dependency injection pattern for governance-related components. The CNetFulfilledRequestManager dependency is removed from the CGovernanceManager constructor and moved to the NetGovernance constructor. The fulfillment validation logic, previously located in CGovernanceManager::SyncObjects, is relocated to NetGovernance::ProcessMessage where it guards the handling of full governance object list synchronization requests. All instantiation sites in initialization code and test utilities are updated to reflect the new constructor signatures.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: removing CGovernanceManager's dependency on CNetFulfilledRequestManager.
Description check ✅ Passed The description is relevant and explains the rationale (separation of concerns), what was moved, and references a related issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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

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

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/governance/net_governance.h (1)

12-35: Clang-format CI is failing, and the new reference dependency makes lifetime correctness critical.
The injection of CNetFulfilledRequestManager& into NetGovernance is the right direction for separation, but ensure (1) clang-format is applied and (2) every construction site guarantees netfulfilledman outlives NetGovernance (esp. in tests/tools).

Proposed formatting-only tweak (likely what clang-format wants)
-    NetGovernance(PeerManagerInternal* peer_manager, CGovernanceManager& gov_manager, CMasternodeSync& node_sync, CNetFulfilledRequestManager& netfulfilledman,
-                  CConnman& connman) :
+    NetGovernance(PeerManagerInternal* peer_manager,
+                  CGovernanceManager& gov_manager,
+                  CMasternodeSync& node_sync,
+                  CNetFulfilledRequestManager& netfulfilledman,
+                  CConnman& connman) :
         NetHandler(peer_manager),
         m_gov_manager(gov_manager),
         m_node_sync(node_sync),
         m_netfulfilledman(netfulfilledman),
         m_connman(connman)
     {
     }
src/governance/governance.cpp (1)

65-77: Clang-format CI is failing here, and the ctor signature formatting is the likely culprit.
The signature change is correct for dropping the dependency, but please clang-format the file to fix CI. Also, since the anti-spam guard moved out of governance, double-check no other call paths invoke CGovernanceManager::SyncObjects without going through the new NetGovernance gating.

Proposed formatting-only tweak (likely what clang-format wants)
 CGovernanceManager::CGovernanceManager(CMasternodeMetaMan& mn_metaman,
                                        const ChainstateManager& chainman,
-                                       const std::unique_ptr<CDeterministicMNManager>& dmnman, CMasternodeSync& mn_sync) :
+                                       const std::unique_ptr<CDeterministicMNManager>& dmnman,
+                                       CMasternodeSync& mn_sync) :
     m_db{std::make_unique<db_type>("governance.dat", "magicGovernanceCache")},
     m_mn_metaman{mn_metaman},
     m_chainman{chainman},
     m_dmnman{dmnman},
     m_mn_sync{mn_sync},
     cmapVoteToObject{MAX_CACHE_SIZE},
     mapPostponedObjects{},
     mapTrigger{}
 {
 }
🤖 Fix all issues with AI agents
In `@src/governance/governance.h`:
- Around line 275-278: The constructor declaration for CGovernanceManager (and
its destructor) is misformatted relative to clang-format and must match the
definition in src/governance/governance.cpp; run clang-format on
src/governance/governance.h (and/or apply the same line breaks/spacing used in
the cpp definition) so the signature for explicit
CGovernanceManager(CMasternodeMetaMan& mn_metaman, const ChainstateManager&
chainman, const std::unique_ptr<CDeterministicMNManager>& dmnman,
CMasternodeSync& mn_sync); and ~CGovernanceManager(); exactly mirror the
formatting in the implementation, fixing spacing/line breaks to satisfy CI.
📜 Review details

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2231ac4 and 295567f.

📒 Files selected for processing (6)
  • src/governance/governance.cpp
  • src/governance/governance.h
  • src/governance/net_governance.cpp
  • src/governance/net_governance.h
  • src/init.cpp
  • src/test/util/setup_common.cpp
🧰 Additional context used
📓 Path-based instructions (5)
src/**/*.{cpp,h,hpp,cc}

📄 CodeRabbit inference engine (CLAUDE.md)

Dash Core implementation must be written in C++20, requiring at least Clang 16 or GCC 11.1

Files:

  • src/governance/governance.h
  • src/governance/net_governance.h
  • src/governance/governance.cpp
  • src/governance/net_governance.cpp
  • src/test/util/setup_common.cpp
  • src/init.cpp
src/{masternode,evo,llmq,governance,coinjoin}/**/*.{cpp,h}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Dash-specific database implementations: CFlatDB for persistent storage (MasternodeMetaStore, GovernanceStore, SporkStore, NetFulfilledRequestStore) and CDBWrapper extensions for Evolution/DKG/InstantSend/Quorum/RecoveredSigs data

Files:

  • src/governance/governance.h
  • src/governance/net_governance.h
  • src/governance/governance.cpp
  • src/governance/net_governance.cpp
src/governance/**/*.{cpp,h}

📄 CodeRabbit inference engine (CLAUDE.md)

Governance implementation must support governance objects (proposals, triggers, superblock management) and on-chain voting with tallying

Files:

  • src/governance/governance.h
  • src/governance/net_governance.h
  • src/governance/governance.cpp
  • src/governance/net_governance.cpp
src/{masternode,llmq,evo,coinjoin,governance}/**/*.{cpp,h}

📄 CodeRabbit inference engine (CLAUDE.md)

Use unordered_lru_cache for efficient caching with LRU eviction in Dash-specific data structures

Files:

  • src/governance/governance.h
  • src/governance/net_governance.h
  • src/governance/governance.cpp
  • src/governance/net_governance.cpp
src/{test,wallet/test}/**/*.{cpp,h}

📄 CodeRabbit inference engine (CLAUDE.md)

Unit tests in src/test/ and src/wallet/test/ must use Boost::Test framework

Files:

  • src/test/util/setup_common.cpp
🧠 Learnings (10)
📓 Common learnings
Learnt from: kwvg
Repo: dashpay/dash PR: 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
Repo: dashpay/dash PR: 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.
📚 Learning: 2025-11-24T16:41:22.457Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:41:22.457Z
Learning: Applies to src/governance/**/*.{cpp,h} : Governance implementation must support governance objects (proposals, triggers, superblock management) and on-chain voting with tallying

Applied to files:

  • src/governance/governance.h
  • src/governance/governance.cpp
  • src/governance/net_governance.cpp
  • src/init.cpp
📚 Learning: 2025-11-24T16:41:22.457Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:41:22.457Z
Learning: Applies to src/evo/evodb/**/*.{cpp,h} : Evolution Database (CEvoDb) must handle masternode snapshots, quorum state, governance objects with efficient differential updates for masternode lists

Applied to files:

  • src/governance/governance.h
  • src/governance/governance.cpp
📚 Learning: 2025-11-24T16:41:22.457Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:41:22.457Z
Learning: Applies to src/{masternode,evo,llmq,governance,coinjoin}/**/*.{cpp,h} : Use Dash-specific database implementations: CFlatDB for persistent storage (MasternodeMetaStore, GovernanceStore, SporkStore, NetFulfilledRequestStore) and CDBWrapper extensions for Evolution/DKG/InstantSend/Quorum/RecoveredSigs data

Applied to files:

  • src/governance/governance.h
📚 Learning: 2025-11-24T16:41:22.457Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:41:22.457Z
Learning: Applies to src/{masternode,llmq}/**/*.{cpp,h} : BLS integration must be used for cryptographic foundation of advanced masternode features

Applied to files:

  • src/governance/governance.h
  • src/governance/governance.cpp
📚 Learning: 2025-12-22T15:42:48.595Z
Learnt from: kwvg
Repo: dashpay/dash PR: 7068
File: src/qt/guiutil_font.h:68-77
Timestamp: 2025-12-22T15:42:48.595Z
Learning: In C++/Qt codebases, use fail-fast asserts in setters to enforce invariants (e.g., ensuring internal maps contain necessary keys). Prefer assert() for programmer errors that should be caught in development and debugging, rather than defensive runtime checks with fallbacks. This helps catch invariant violations early during development. Apply to header and source files where invariant-driven state mutations occur, especially in setters like SetWeightBold/SetWeightNormal that assume established relationships or preconditions.

Applied to files:

  • src/governance/governance.h
  • src/governance/net_governance.h
📚 Learning: 2025-11-24T16:41:22.457Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:41:22.457Z
Learning: Applies to src/{validation,consensus,net_processing}/**/*.{cpp,h} : ValidationInterface callbacks must be used for event-driven architecture to coordinate subsystems during block/transaction processing

Applied to files:

  • src/governance/governance.cpp
📚 Learning: 2025-11-25T10:53:37.523Z
Learnt from: knst
Repo: dashpay/dash PR: 7008
File: src/masternode/sync.h:17-18
Timestamp: 2025-11-25T10:53:37.523Z
Learning: The file src/masternode/sync.h containing `CMasternodeSync` is misnamed and misplaced—it has nothing to do with "masternode" functionality. It should eventually be renamed to `NodeSyncing` or `NodeSyncStatus` and moved to src/node/sync.h as a future refactoring.

Applied to files:

  • src/governance/governance.cpp
📚 Learning: 2025-11-24T16:41:22.457Z
Learnt from: CR
Repo: dashpay/dash PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-24T16:41:22.457Z
Learning: Applies to src/{validation,txmempool}/**/*.{cpp,h} : Block validation and mempool handling must use extensions to Bitcoin Core mechanisms for special transaction validation and enhanced transaction relay

Applied to files:

  • src/governance/governance.cpp
📚 Learning: 2025-06-09T16:43:20.996Z
Learnt from: kwvg
Repo: dashpay/dash PR: 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.

Applied to files:

  • src/test/util/setup_common.cpp
🧬 Code graph analysis (2)
src/governance/governance.h (1)
src/governance/governance.cpp (2)
  • CGovernanceManager (65-77)
  • CGovernanceManager (79-83)
src/governance/net_governance.h (1)
src/net_processing.h (3)
  • NetHandler (76-99)
  • NetHandler (80-83)
  • PeerManagerInternal (61-74)
🪛 GitHub Actions: Clang Diff Format Check
src/governance/governance.h

[error] 1-1: Clang-format differences detected in governance.h. Run 'clang-format -i' to fix formatting.

src/governance/net_governance.h

[error] 1-1: Clang-format differences detected in net_governance.h. Run 'clang-format -i' to fix formatting.

src/governance/governance.cpp

[error] 1-1: Clang-format differences detected in governance.cpp. Run 'clang-format -i' to fix formatting.

🔇 Additional comments (4)
src/init.cpp (1)

1984-1987: Wiring refactoring is complete and correct. CGovernanceManager no longer depends on netfulfilledman (lines 1986-1987), while NetGovernance receives it explicitly (line 2262). There is only one NetGovernance constructor call site in the codebase and it matches the refactored signature. SyncObjects calls are properly guarded with HasFulfilledRequest checks.

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

289-290: Updated test setup wiring looks consistent with the new CGovernanceManager constructor.

Verification confirms both constructor call sites (src/init.cpp and the test setup) use the same updated 4-parameter signature, with no remaining calls using the removed parameter.

src/governance/net_governance.cpp (2)

13-13: LGTM!

Include added for the new CNetFulfilledRequestManager dependency.


64-73: LGTM - fulfillment tracking correctly relocated.

The logic properly prevents peers from repeatedly requesting full governance object sync. The misbehavior penalty of 20 is consistent with other penalties in this file.

The assert(m_netfulfilledman.IsValid()) is appropriate here: m_netfulfilledman is a reference initialized at construction and its is_valid flag is set during startup via LoadCache() in init.cpp before the node processes any messages. The assert validates this invariant—if ProcessMessage somehow runs before initialization completes, that's a programming error that should fail loudly in debug builds.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

Comment on lines +275 to 278
explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman,
const ChainstateManager& chainman,
const std::unique_ptr<CDeterministicMNManager>& dmnman, CMasternodeSync& mn_sync);
~CGovernanceManager();
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Clang-format CI is failing for this constructor declaration (and it’s the only changed hunk here).
The signature change aligns with the refactor goal; please run clang-format (CI currently fails) and ensure the declaration matches the definition in src/governance/governance.cpp.

Proposed formatting-only tweak (likely what clang-format wants)
-    explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman,
-                                const ChainstateManager& chainman,
-                                const std::unique_ptr<CDeterministicMNManager>& dmnman, CMasternodeSync& mn_sync);
+    explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman,
+                                const ChainstateManager& chainman,
+                                const std::unique_ptr<CDeterministicMNManager>& dmnman,
+                                CMasternodeSync& mn_sync);
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman,
const ChainstateManager& chainman,
const std::unique_ptr<CDeterministicMNManager>& dmnman, CMasternodeSync& mn_sync);
~CGovernanceManager();
explicit CGovernanceManager(CMasternodeMetaMan& mn_metaman,
const ChainstateManager& chainman,
const std::unique_ptr<CDeterministicMNManager>& dmnman,
CMasternodeSync& mn_sync);
~CGovernanceManager();
🤖 Prompt for AI Agents
In `@src/governance/governance.h` around lines 275 - 278, The constructor
declaration for CGovernanceManager (and its destructor) is misformatted relative
to clang-format and must match the definition in src/governance/governance.cpp;
run clang-format on src/governance/governance.h (and/or apply the same line
breaks/spacing used in the cpp definition) so the signature for explicit
CGovernanceManager(CMasternodeMetaMan& mn_metaman, const ChainstateManager&
chainman, const std::unique_ptr<CDeterministicMNManager>& dmnman,
CMasternodeSync& mn_sync); and ~CGovernanceManager(); exactly mirror the
formatting in the implementation, fixing spacing/line breaks to satisfy CI.

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 295567f

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 295567f

@PastaPastaPasta PastaPastaPasta merged commit 0bbc3a5 into dashpay:develop Jan 15, 2026
75 of 82 checks passed
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