Skip to content

Commit 009f5cb

Browse files
committed
refactor: add cs annotations for CGovernanceObject
1 parent 2ee408f commit 009f5cb

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

src/governance/object.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,26 +554,31 @@ int CGovernanceObject::CountMatchingVotes(const CDeterministicMNList& tip_mn_lis
554554

555555
int CGovernanceObject::GetAbsoluteYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
556556
{
557+
AssertLockNotHeld(cs);
557558
return GetYesCount(tip_mn_list, eVoteSignalIn) - GetNoCount(tip_mn_list, eVoteSignalIn);
558559
}
559560

560561
int CGovernanceObject::GetAbsoluteNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
561562
{
563+
AssertLockNotHeld(cs);
562564
return GetNoCount(tip_mn_list, eVoteSignalIn) - GetYesCount(tip_mn_list, eVoteSignalIn);
563565
}
564566

565567
int CGovernanceObject::GetYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
566568
{
569+
AssertLockNotHeld(cs);
567570
return CountMatchingVotes(tip_mn_list, eVoteSignalIn, VOTE_OUTCOME_YES);
568571
}
569572

570573
int CGovernanceObject::GetNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
571574
{
575+
AssertLockNotHeld(cs);
572576
return CountMatchingVotes(tip_mn_list, eVoteSignalIn, VOTE_OUTCOME_NO);
573577
}
574578

575579
int CGovernanceObject::GetAbstainCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
576580
{
581+
AssertLockNotHeld(cs);
577582
return CountMatchingVotes(tip_mn_list, eVoteSignalIn, VOTE_OUTCOME_ABSTAIN);
578583
}
579584

@@ -591,6 +596,8 @@ bool CGovernanceObject::GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint,
591596

592597
void CGovernanceObject::UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list)
593598
{
599+
AssertLockNotHeld(cs);
600+
594601
// CALCULATE MINIMUM SUPPORT LEVELS REQUIRED
595602

596603
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
@@ -189,7 +189,8 @@ class CGovernanceObject
189189
void UpdateLocalValidity(const CDeterministicMNList& tip_mn_list, const ChainstateManager& chainman)
190190
EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
191191

192-
void UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list);
192+
void UpdateSentinelVariables(const CDeterministicMNList& tip_mn_list)
193+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
193194

194195
void PrepareDeletion(int64_t nDeletionTime_) EXCLUSIVE_LOCKS_REQUIRED(!cs)
195196
{
@@ -209,15 +210,22 @@ class CGovernanceObject
209210

210211
// GET VOTE COUNT FOR SIGNAL
211212

212-
int CountMatchingVotes(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) const;
213+
int CountMatchingVotes(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn, vote_outcome_enum_t eVoteOutcomeIn) const
214+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
213215

214-
int GetAbsoluteYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
215-
int GetAbsoluteNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
216-
int GetYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
217-
int GetNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
218-
int GetAbstainCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const;
216+
int GetAbsoluteYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
217+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
218+
int GetAbsoluteNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
219+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
220+
int GetYesCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
221+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
222+
int GetNoCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
223+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
224+
int GetAbstainCount(const CDeterministicMNList& tip_mn_list, vote_signal_enum_t eVoteSignalIn) const
225+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
219226

220-
bool GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint, vote_rec_t& voteRecord) const;
227+
bool GetCurrentMNVotes(const COutPoint& mnCollateralOutpoint, vote_rec_t& voteRecord) const
228+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
221229

222230
// FUNCTIONS FOR DEALING WITH DATA STRING
223231

@@ -257,16 +265,19 @@ class CGovernanceObject
257265
void GetData(UniValue& objResult) const;
258266

259267
bool ProcessVote(CMasternodeMetaMan& mn_metaman, CGovernanceManager& govman, const CDeterministicMNList& tip_mn_list,
260-
const CGovernanceVote& vote, CGovernanceException& exception);
268+
const CGovernanceVote& vote, CGovernanceException& exception)
269+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
261270

262271
/// Called when MN's which have voted on this object have been removed
263-
void ClearMasternodeVotes(const CDeterministicMNList& tip_mn_list);
272+
void ClearMasternodeVotes(const CDeterministicMNList& tip_mn_list)
273+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
264274

265275
// Revalidate all votes from this MN and delete them if validation fails.
266276
// This is the case for DIP3 MNs that changed voting or operator keys and
267277
// also for MNs that were removed from the list completely.
268278
// Returns deleted vote hashes.
269-
std::set<uint256> RemoveInvalidVotes(const CDeterministicMNList& tip_mn_list, const COutPoint& mnOutpoint);
279+
std::set<uint256> RemoveInvalidVotes(const CDeterministicMNList& tip_mn_list, const COutPoint& mnOutpoint)
280+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
270281
};
271282

272283
#endif // BITCOIN_GOVERNANCE_OBJECT_H

0 commit comments

Comments
 (0)