Skip to content

Commit e224991

Browse files
committed
governance: add lock annotations for cs_relay
1 parent df589c7 commit e224991

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

src/governance/governance.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ bool CGovernanceManager::LoadCache(bool load_cache)
117117

118118
void CGovernanceManager::RelayObject(const CGovernanceObject& obj)
119119
{
120+
AssertLockNotHeld(cs_relay);
120121
if (!m_mn_sync.IsSynced()) {
121122
LogPrint(BCLog::GOBJECT, "%s -- won't relay until fully synced\n", __func__);
122123
return;
@@ -128,6 +129,7 @@ void CGovernanceManager::RelayObject(const CGovernanceObject& obj)
128129

129130
void CGovernanceManager::RelayVote(const CGovernanceVote& vote)
130131
{
132+
AssertLockNotHeld(cs_relay);
131133
if (!m_mn_sync.IsSynced()) {
132134
LogPrint(BCLog::GOBJECT, "%s -- won't relay until fully synced\n", __func__);
133135
return;
@@ -193,6 +195,7 @@ void CGovernanceManager::AddPostponedObject(const CGovernanceObject& govobj)
193195

194196
MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
195197
{
198+
AssertLockNotHeld(cs_relay);
196199
if (!IsValid()) return {};
197200
if (!m_mn_sync.IsBlockchainSynced()) return {};
198201

@@ -335,6 +338,7 @@ MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman
335338

336339
void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj)
337340
{
341+
AssertLockNotHeld(cs_relay);
338342
uint256 nHash = govobj.GetHash();
339343
std::vector<vote_time_pair_t> vecVotePairs;
340344
cmmapOrphanVotes.GetAll(nHash, vecVotePairs);
@@ -361,6 +365,7 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj)
361365

362366
void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, const CNode* pfrom)
363367
{
368+
AssertLockNotHeld(cs_relay);
364369
uint256 nHash = govobj.GetHash();
365370
std::string strHash = nHash.ToString();
366371

@@ -897,6 +902,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
897902

898903
bool CGovernanceManager::ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman)
899904
{
905+
AssertLockNotHeld(cs_relay);
900906
bool fOK = ProcessVote(/*pfrom=*/nullptr, vote, exception, connman);
901907
if (fOK) {
902908
RelayVote(vote);
@@ -959,6 +965,7 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
959965

960966
void CGovernanceManager::CheckPostponedObjects()
961967
{
968+
AssertLockNotHeld(cs_relay);
962969
if (!m_mn_sync.IsSynced()) return;
963970

964971
LOCK2(::cs_main, cs);
@@ -1308,6 +1315,7 @@ UniValue CGovernanceManager::ToJson() const
13081315

13091316
void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex)
13101317
{
1318+
AssertLockNotHeld(cs_relay);
13111319
// Note this gets called from ActivateBestChain without cs_main being held
13121320
// so it should be safe to lock our mutex here without risking a deadlock
13131321
// On the other hand it should be safe for us to access pindex without holding a lock

src/governance/governance.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,8 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
287287

288288
bool IsValid() const override { return is_valid; }
289289

290-
void RelayObject(const CGovernanceObject& obj);
291-
void RelayVote(const CGovernanceVote& vote);
290+
void RelayObject(const CGovernanceObject& obj) EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
291+
void RelayVote(const CGovernanceVote& vote) EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
292292

293293
/**
294294
* This is called by AlreadyHave in net_processing.cpp as part of the inventory
@@ -300,7 +300,8 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
300300
[[nodiscard]] MessageProcessingResult SyncSingleObjVotes(CNode& peer, const uint256& nProp, const CBloomFilter& filter, CConnman& connman);
301301
[[nodiscard]] MessageProcessingResult SyncObjects(CNode& peer, CConnman& connman) const;
302302

303-
[[nodiscard]] MessageProcessingResult ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv);
303+
[[nodiscard]] MessageProcessingResult ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type, CDataStream& vRecv)
304+
EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
304305

305306
void DoMaintenance(CConnman& connman);
306307

@@ -313,13 +314,14 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
313314
std::vector<CGovernanceVote> GetCurrentVotes(const uint256& nParentHash, const COutPoint& mnCollateralOutpointFilter) const;
314315
void GetAllNewerThan(std::vector<CGovernanceObject>& objs, int64_t nMoreThanTime) const;
315316

316-
void AddGovernanceObject(CGovernanceObject& govobj, const CNode* pfrom = nullptr) override;
317+
void AddGovernanceObject(CGovernanceObject& govobj, const CNode* pfrom = nullptr) override
318+
EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
317319

318320
void CheckAndRemove();
319321

320322
UniValue ToJson() const;
321323

322-
void UpdatedBlockTip(const CBlockIndex* pindex);
324+
void UpdatedBlockTip(const CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
323325
int64_t GetLastDiffTime() const { return nTimeLastDiff; }
324326
void UpdateLastDiffTime(int64_t nTimeIn) { nTimeLastDiff = nTimeIn; }
325327

@@ -344,9 +346,10 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
344346

345347
bool MasternodeRateCheck(const CGovernanceObject& govobj, bool fUpdateFailStatus, bool fForce, bool& fRateCheckBypassed);
346348

347-
bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman) override;
349+
bool ProcessVoteAndRelay(const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman) override
350+
EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
348351

349-
void CheckPostponedObjects();
352+
void CheckPostponedObjects() EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
350353

351354
bool AreRateChecksEnabled() const
352355
{
@@ -413,7 +416,7 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
413416
/// Called to indicate a requested object or vote has been received
414417
bool AcceptMessage(const uint256& nHash);
415418

416-
void CheckOrphanVotes(CGovernanceObject& govobj);
419+
void CheckOrphanVotes(CGovernanceObject& govobj) EXCLUSIVE_LOCKS_REQUIRED(!cs_relay);
417420

418421
void RebuildIndexes();
419422

0 commit comments

Comments
 (0)