Skip to content

Commit 423c1eb

Browse files
committed
refactor: add cs annotations for accessor functions
1 parent 4080ee9 commit 423c1eb

2 files changed

Lines changed: 34 additions & 14 deletions

File tree

src/governance/governance.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,13 @@ bool CGovernanceManager::SerializeVoteForHash(const uint256& nHash, CDataStream&
203203
void CGovernanceManager::AddPostponedObject(const CGovernanceObject& govobj)
204204
{
205205
LOCK(cs);
206-
mapPostponedObjects.emplace(govobj.GetHash(), govobj);
206+
AddPostponedObjectInternal(govobj);
207+
}
208+
209+
void CGovernanceManager::AddPostponedObjectInternal(const CGovernanceObject& govobj)
210+
{
211+
AssertLockHeld(cs);
212+
mapPostponedObjects.insert(std::make_pair(govobj.GetHash(), govobj));
207213
}
208214

209215
MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman& connman, std::string_view msg_type,
@@ -289,7 +295,7 @@ MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman
289295

290296
if (!fIsValid) {
291297
if (fMissingConfirmations) {
292-
AddPostponedObject(govobj);
298+
AddPostponedObjectInternal(govobj);
293299
LogPrintf("MNGOVERNANCEOBJECT -- Not enough fee confirmations for: %s, strError = %s\n", strHash, strError);
294300
} else {
295301
LogPrint(BCLog::GOBJECT, "MNGOVERNANCEOBJECT -- Governance object is invalid - %s\n", strError);

src/governance/governance.h

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,26 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
322322

323323
// Thread-safe accessors
324324
bool GetBestSuperblock(const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet,
325-
int nBlockHeight) override EXCLUSIVE_LOCKS_REQUIRED(!cs);
326-
bool HaveObjectForHash(const uint256& nHash) const;
327-
bool HaveVoteForHash(const uint256& nHash) const;
328-
bool SerializeObjectForHash(const uint256& nHash, CDataStream& ss) const;
329-
bool SerializeVoteForHash(const uint256& nHash, CDataStream& ss) const;
330-
CGovernanceObject* FindGovernanceObject(const uint256& nHash) override EXCLUSIVE_LOCKS_REQUIRED(!cs);
331-
int GetVoteCount() const;
332-
void AddPostponedObject(const CGovernanceObject& govobj);
325+
int nBlockHeight) override
326+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
327+
bool HaveObjectForHash(const uint256& nHash) const
328+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
329+
bool HaveVoteForHash(const uint256& nHash) const
330+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
331+
bool SerializeObjectForHash(const uint256& nHash, CDataStream& ss) const
332+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
333+
bool SerializeVoteForHash(const uint256& nHash, CDataStream& ss) const
334+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
335+
CGovernanceObject* FindGovernanceObject(const uint256& nHash) override
336+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
337+
int GetVoteCount() const
338+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
339+
void AddPostponedObject(const CGovernanceObject& govobj)
340+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
333341

334342
// Thread-safe accessors for trigger management
335-
std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggers() const override EXCLUSIVE_LOCKS_REQUIRED(!cs);
343+
std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggers() const override
344+
EXCLUSIVE_LOCKS_REQUIRED(!cs);
336345

337346
void MasternodeRateUpdate(const CGovernanceObject& govobj);
338347

@@ -390,10 +399,15 @@ class CGovernanceManager : public GovernanceStore, public GovernanceSignerParent
390399

391400
private:
392401
// Internal counterparts to "Thread-safe accessors"
402+
void AddPostponedObjectInternal(const CGovernanceObject& govobj)
403+
EXCLUSIVE_LOCKS_REQUIRED(cs);
393404
bool GetBestSuperblockInternal(const CDeterministicMNList& tip_mn_list, CSuperblock_sptr& pSuperblockRet,
394-
int nBlockHeight) EXCLUSIVE_LOCKS_REQUIRED(cs);
395-
CGovernanceObject* FindGovernanceObjectInternal(const uint256& nHash) EXCLUSIVE_LOCKS_REQUIRED(cs);
396-
std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggersInternal() const EXCLUSIVE_LOCKS_REQUIRED(cs);
405+
int nBlockHeight)
406+
EXCLUSIVE_LOCKS_REQUIRED(cs);
407+
CGovernanceObject* FindGovernanceObjectInternal(const uint256& nHash)
408+
EXCLUSIVE_LOCKS_REQUIRED(cs);
409+
std::vector<std::shared_ptr<CSuperblock>> GetActiveTriggersInternal() const
410+
EXCLUSIVE_LOCKS_REQUIRED(cs);
397411

398412
void ExecuteBestSuperblock(const CDeterministicMNList& tip_mn_list, int nBlockHeight);
399413

0 commit comments

Comments
 (0)