Skip to content

Commit 2406e14

Browse files
committed
refactor: add cs annotations for CGovernanceObject
1 parent 780f9a7 commit 2406e14

File tree

2 files changed

+35
-11
lines changed

2 files changed

+35
-11
lines changed

src/governance/object.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ CGovernanceObject::CGovernanceObject(const CGovernanceObject& other) :
5858
bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list,
5959
const CGovernanceVote& vote, CGovernanceException& exception)
6060
{
61+
AssertLockNotHeld(cs);
62+
6163
assert(mn_metaman.IsValid());
6264

6365
LOCK(cs);
@@ -168,6 +170,7 @@ bool CGovernanceObject::ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceM
168170

169171
void CGovernanceObject::ClearMasternodeVotes(const CDeterministicMNList& tip_mn_list)
170172
{
173+
AssertLockNotHeld(cs);
171174
LOCK(cs);
172175

173176
auto it = mapCurrentMNVotes.begin();
@@ -184,6 +187,7 @@ void CGovernanceObject::ClearMasternodeVotes(const CDeterministicMNList& tip_mn_
184187

185188
std::set<uint256> CGovernanceObject::RemoveInvalidVotes(const CDeterministicMNList& tip_mn_list, const COutPoint& mnOutpoint)
186189
{
190+
AssertLockNotHeld(cs);
187191
LOCK(cs);
188192

189193
auto it = mapCurrentMNVotes.find(mnOutpoint);
@@ -532,6 +536,7 @@ bool CGovernanceObject::IsCollateralValid(const ChainstateManager& chainman, std
532536

533537
int CGovernanceObject::CountMatchingVotes(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) const
534538
{
539+
AssertLockNotHeld(cs);
535540
LOCK(cs);
536541

537542
int nCount = 0;
@@ -554,31 +559,37 @@ int CGovernanceObject::CountMatchingVotes(const CDeterministicMNList& tip_mn_lis
554559

555560
int CGovernanceObject::GetAbsoluteYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
556561
{
562+
AssertLockNotHeld(cs);
557563
return GetYesCount(tip_mn_list, eVoteSignalIn) - GetNoCount(tip_mn_list, eVoteSignalIn);
558564
}
559565

560566
int CGovernanceObject::GetAbsoluteNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
561567
{
568+
AssertLockNotHeld(cs);
562569
return GetNoCount(tip_mn_list, eVoteSignalIn) - GetYesCount(tip_mn_list, eVoteSignalIn);
563570
}
564571

565572
int CGovernanceObject::GetYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
566573
{
574+
AssertLockNotHeld(cs);
567575
return CountMatchingVotes(tip_mn_list, eVoteSignalIn, VOTE_OUTCOME_YES);
568576
}
569577

570578
int CGovernanceObject::GetNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
571579
{
580+
AssertLockNotHeld(cs);
572581
return CountMatchingVotes(tip_mn_list, eVoteSignalIn, VOTE_OUTCOME_NO);
573582
}
574583

575584
int CGovernanceObject::GetAbstainCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
576585
{
586+
AssertLockNotHeld(cs);
577587
return CountMatchingVotes(tip_mn_list, eVoteSignalIn, VOTE_OUTCOME_ABSTAIN);
578588
}
579589

580590
bool CGovernanceObject::GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint, vote_rec_t& voteRecord) const
581591
{
592+
AssertLockNotHeld(cs);
582593
LOCK(cs);
583594

584595
auto it = mapCurrentMNVotes.find(mnCollateralOutpoint);
@@ -591,6 +602,8 @@ bool CGovernanceObject::GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint,
591602

592603
void CGovernanceObject::UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list)
593604
{
605+
AssertLockNotHeld(cs);
606+
594607
// CALCULATE MINIMUM SUPPORT LEVELS REQUIRED
595608

596609
int nWeightedMnCount = (int)tip_mn_list.GetValidWeightedMNsCount();

src/governance/object.h

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ class CGovernanceObject
192192
void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman)
193193
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
194194

195-
void UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list);
195+
void UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list)
196+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
196197

197198
void PrepareDeletion(int64_t nDeletionTime_) EXCLUSIVE_LOCKS_REQUIRED(!cs)
198199
{
@@ -213,15 +214,22 @@ class CGovernanceObject
213214

214215
// GET VOTE COUNT FOR SIGNAL
215216

216-
int CountMatchingVotes(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) const;
217+
int CountMatchingVotes(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) const
218+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
217219

218-
int GetAbsoluteYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
219-
int GetAbsoluteNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
220-
int GetYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
221-
int GetNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
222-
int GetAbstainCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
220+
int GetAbsoluteYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
221+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
222+
int GetAbsoluteNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
223+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
224+
int GetYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
225+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
226+
int GetNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
227+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
228+
int GetAbstainCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
229+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
223230

224-
bool GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint, vote_rec_t& voteRecord) const;
231+
bool GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint, vote_rec_t& voteRecord) const
232+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
225233

226234
// FUNCTIONS FOR DEALING WITH DATA STRING
227235

@@ -261,16 +269,19 @@ class CGovernanceObject
261269
void GetData(UniValue& objResult) const;
262270

263271
bool ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list,
264-
const CGovernanceVote& vote, CGovernanceException& exception);
272+
const CGovernanceVote& vote, CGovernanceException& exception)
273+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
265274

266275
/// Called when MN's which have voted on this object have been removed
267-
void ClearMasternodeVotes(const CDeterministicMNList& tip_mn_list);
276+
void ClearMasternodeVotes(const CDeterministicMNList& tip_mn_list)
277+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
268278

269279
// Revalidate all votes from this MN and delete them if validation fails.
270280
// This is the case for DIP3 MNs that changed voting or operator keys and
271281
// also for MNs that were removed from the list completely.
272282
// Returns deleted vote hashes.
273-
std::set<uint256> RemoveInvalidVotes(const CDeterministicMNList& tip_mn_list, const COutPoint& mnOutpoint);
283+
std::set<uint256> RemoveInvalidVotes(const CDeterministicMNList& tip_mn_list, const COutPoint& mnOutpoint)
284+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
274285
};
275286

276287
#endif // BITCOIN_GOVERNANCE_OBJECT_H

0 commit comments

Comments
 (0)