-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor: move all network operations out of CGovernanceManager
#7106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
refactor: move all network operations out of CGovernanceManager
#7106
Conversation
…thods Replace SyncObjects() and SyncSingleObjVotes() with pure data accessors: - GetSyncableObjectInvs(): returns inventory of syncable governance objects - GetSyncableVoteInvs(): returns inventory of syncable votes for an object Move network message construction (SYNCSTATUSCOUNT) to NetGovernance, following the established pattern in NetSigning and NetInstantSend. This improves separation of concerns: - CGovernanceManager handles data access only - NetGovernance handles network protocol operations Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Complete separation of network operations from CGovernanceManager by moving RequestGovernanceObject functionality to the appropriate network layer classes. Changes to CGovernanceManager (data access only): - Add GetVoteBloomFilter() to build bloom filter for sync requests - Add GetOrphanVoteObjectHashes() to get object hashes for orphan votes - Modify ProcessVote() to use output param hashToRequest instead of doing network operations internally - Remove RequestGovernanceObject() and RequestOrphanObjects() Changes to SyncManager: - Add SendGovernanceObjectSyncRequest() for vote sync requests - Update RequestGovernanceObjectVotes() to use new method Changes to NetGovernance: - Handle orphan vote requests in ProcessMessage() after ProcessVote - Move RequestOrphanObjects logic into Schedule() for periodic requests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
WalkthroughThe changes decouple governance data collection from network I/O by replacing several network-performing methods with pure getters: SyncObjects → GetSyncableObjectInvs, SyncSingleObjVotes → GetSyncableVoteInvs, RequestGovernanceObject → GetVoteBloomFilter, and RequestOrphanObjects → GetOrphanVoteObjectHashes. ProcessVote now returns an output Sequence Diagram(s)sequenceDiagram
participant SyncMgr as SyncManager
participant GovMgr as CGovernanceManager
participant Connman as CConnman/Peers
SyncMgr->>GovMgr: GetSyncableObjectInvs()
GovMgr-->>SyncMgr: vector<CInv> (objects)
SyncMgr->>Connman: Send SYNCSTATUSCOUNT (GOVOBJ)
SyncMgr->>Connman: Relay invs for each CInv
sequenceDiagram
participant Peer as RemotePeer
participant NetGov as NetGovernance
participant GovMgr as CGovernanceManager
participant SyncMgr as SyncManager
participant Connman as CConnman/Peers
Peer->>NetGov: MNGOVERNANCEOBJECTVOTE (vote)
NetGov->>GovMgr: ProcessVote(peer, vote, exception, hashToRequest)
GovMgr-->>NetGov: bool accepted, hashToRequest (maybe zero)
alt vote rejected && hashToRequest != 0
NetGov->>SyncMgr: SendGovernanceObjectSyncRequest(peer, hashToRequest, useFilter=true)
SyncMgr->>Connman: Push MNGOVERNANCESYNC (hashToRequest, bloom filter)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
knst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM overall, consider further improvements (2 commits attached to my comments); nits are minor
src/governance/governance.cpp
Outdated
| CBloomFilter filter; | ||
| auto pObj = FindConstGovernanceObjectInternal(nHash); | ||
| if (!pObj) { | ||
| return CBloomFilter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: CBloomFilter{}
src/node/sync_manager.cpp
Outdated
|
|
||
| LogPrint(BCLog::GOBJECT, "SyncManager::%s -- nHash %s peer=%d\n", __func__, nHash.ToString(), pnode->GetId()); | ||
|
|
||
| CBloomFilter filter = fUseFilter ? m_gov_manager.GetVoteBloomFilter(nHash) : CBloomFilter(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: CBloomFilter{}
src/governance/governance.cpp
Outdated
| uint256& hashToRequest) | ||
| { | ||
| AssertLockNotHeld(cs_store); | ||
| hashToRequest = uint256(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: uint256{}
| if (cmmapOrphanVotes.Insert(nHashGovobj, vote_time_pair_t(vote, count_seconds(GetTime<std::chrono::seconds>() + | ||
| GOVERNANCE_ORPHAN_EXPIRATION_TIME)))) { | ||
| LEAVE_CRITICAL_SECTION(cs_store); | ||
| RequestGovernanceObject(pfrom, nHashGovobj, connman); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can drop manual LEAVE_CRITICAL_SECTION after this change, see: knst@3966b84
src/governance/net_governance.cpp
Outdated
|
|
||
| MessageProcessingResult ret; | ||
| ret.m_inventory = std::move(invs); | ||
| m_peer_manager->PeerPostProcessMessage(std::move(ret)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MessageProocessingResult wrapper is not necessary in context of NetHandler. See bc88147
✅ No Merge Conflicts DetectedThis PR currently has no conflicts with other open PRs. |
knst
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 32b761b
Issue being fixed or feature implemented
Move all network operations from
CGovernanceManagerto the appropriate network layer classes (SyncManagerandNetGovernance).What was done?
Refactor only, see individual commits
How Has This Been Tested?
Run tests, sync gov data on mainnet node
Breaking Changes
n/a
Checklist: