@@ -119,6 +119,7 @@ void CGovernanceManager::Schedule(CScheduler& scheduler, CConnman& connman, Peer
119119
120120bool CGovernanceManager::LoadCache (bool load_cache)
121121{
122+ AssertLockNotHeld (cs);
122123 assert (m_db != nullptr );
123124 is_valid = load_cache ? m_db->Load (*this ) : m_db->Store (*this );
124125 if (is_valid && load_cache) {
@@ -215,6 +216,7 @@ void CGovernanceManager::AddPostponedObjectInternal(const CGovernanceObject& gov
215216MessageProcessingResult CGovernanceManager::ProcessMessage (CNode& peer, CConnman& connman, std::string_view msg_type,
216217 CDataStream& vRecv)
217218{
219+ AssertLockNotHeld (cs);
218220 AssertLockNotHeld (cs_relay);
219221 if (!IsValid ()) return {};
220222 if (!m_mn_sync.IsBlockchainSynced ()) return {};
@@ -233,6 +235,7 @@ MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman
233235 vRecv >> filter;
234236
235237 LogPrint (BCLog::GOBJECT, " MNGOVERNANCESYNC -- syncing governance objects to our peer %s\n " , peer.GetLogString ());
238+ LOCK (cs);
236239 if (nProp == uint256 ()) {
237240 return SyncObjects (peer, connman);
238241 } else {
@@ -288,7 +291,8 @@ MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman
288291 bool fMissingConfirmations = false ;
289292 bool fIsValid = govobj.IsValidLocally (tip_mn_list, m_chainman, strError, fMissingConfirmations , true );
290293
291- if (fRateCheckBypassed && fIsValid && !MasternodeRateCheck (govobj, true )) {
294+ bool unused_rcb;
295+ if (fRateCheckBypassed && fIsValid && !MasternodeRateCheck (govobj, true , true , unused_rcb)) {
292296 LogPrint (BCLog::GOBJECT, " MNGOVERNANCEOBJECT -- masternode rate check failed (after signature verification) - %s - (current block height %d)\n " , strHash, nCachedBlockHeight);
293297 return ret;
294298 }
@@ -358,9 +362,9 @@ MessageProcessingResult CGovernanceManager::ProcessMessage(CNode& peer, CConnman
358362
359363void CGovernanceManager::CheckOrphanVotes (CGovernanceObject& govobj)
360364{
361- LOCK (cs);
362-
365+ AssertLockHeld (cs);
363366 AssertLockNotHeld (cs_relay);
367+
364368 uint256 nHash = govobj.GetHash ();
365369 std::vector<vote_time_pair_t > vecVotePairs;
366370 cmmapOrphanVotes.GetAll (nHash, vecVotePairs);
@@ -448,6 +452,7 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, const CN
448452
449453void CGovernanceManager::CheckAndRemove ()
450454{
455+ AssertLockNotHeld (cs);
451456 assert (m_mn_metaman.IsValid ());
452457
453458 // Return on initial sync, spammed the debug.log and provided no use
@@ -707,15 +712,14 @@ bool CGovernanceManager::ConfirmInventoryRequest(const CInv& inv)
707712
708713MessageProcessingResult CGovernanceManager::SyncSingleObjVotes (CNode& peer, const uint256& nProp, const CBloomFilter& filter, CConnman& connman)
709714{
715+ AssertLockHeld (cs);
710716 // do not provide any data until our node is synced
711717 if (!m_mn_sync.IsSynced ()) return {};
712718
713719 // SYNC GOVERNANCE OBJECTS WITH OTHER CLIENT
714720
715721 LogPrint (BCLog::GOBJECT, " CGovernanceManager::%s -- syncing single object to peer=%d, nProp = %s\n " , __func__, peer.GetId (), nProp.ToString ());
716722
717- LOCK (cs);
718-
719723 // single valid object and its valid votes
720724 auto it = mapObjects.find (nProp);
721725 if (it == mapObjects.end ()) {
@@ -758,6 +762,7 @@ MessageProcessingResult CGovernanceManager::SyncSingleObjVotes(CNode& peer, cons
758762
759763MessageProcessingResult CGovernanceManager::SyncObjects (CNode& peer, CConnman& connman) const
760764{
765+ AssertLockHeld (cs);
761766 assert (m_netfulfilledman.IsValid ());
762767
763768 // do not provide any data until our node is synced
@@ -774,8 +779,6 @@ MessageProcessingResult CGovernanceManager::SyncObjects(CNode& peer, CConnman& c
774779
775780 LogPrint (BCLog::GOBJECT, " CGovernanceManager::%s -- syncing all objects to peer=%d\n " , __func__, peer.GetId ());
776781
777- LOCK (cs);
778-
779782 // all valid objects, no votes
780783 MessageProcessingResult ret{};
781784 for (const auto & objPair : mapObjects) {
@@ -806,9 +809,9 @@ MessageProcessingResult CGovernanceManager::SyncObjects(CNode& peer, CConnman& c
806809
807810void CGovernanceManager::MasternodeRateUpdate (const CGovernanceObject& govobj)
808811{
809- if (govobj. GetObjectType () != GovernanceObject::TRIGGER) return ;
812+ AssertLockHeld (cs) ;
810813
811- LOCK (cs) ;
814+ if (govobj. GetObjectType () != GovernanceObject::TRIGGER) return ;
812815
813816 const COutPoint& masternodeOutpoint = govobj.GetMasternodeOutpoint ();
814817 auto it = mapLastMasternodeObject.find (masternodeOutpoint);
@@ -830,13 +833,14 @@ void CGovernanceManager::MasternodeRateUpdate(const CGovernanceObject& govobj)
830833
831834bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, bool fUpdateFailStatus )
832835{
836+ LOCK (cs);
833837 bool fRateCheckBypassed ;
834838 return MasternodeRateCheck (govobj, fUpdateFailStatus , true , fRateCheckBypassed );
835839}
836840
837841bool CGovernanceManager::MasternodeRateCheck (const CGovernanceObject& govobj, bool fUpdateFailStatus , bool fForce , bool & fRateCheckBypassed )
838842{
839- LOCK (cs);
843+ AssertLockHeld (cs);
840844
841845 fRateCheckBypassed = false ;
842846
@@ -900,6 +904,7 @@ bool CGovernanceManager::MasternodeRateCheck(const CGovernanceObject& govobj, bo
900904
901905bool CGovernanceManager::ProcessVoteAndRelay (const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman)
902906{
907+ AssertLockNotHeld (cs);
903908 AssertLockNotHeld (cs_relay);
904909 bool fOK = ProcessVote (/* pfrom=*/ nullptr , vote, exception, connman);
905910 if (fOK ) {
@@ -910,6 +915,7 @@ bool CGovernanceManager::ProcessVoteAndRelay(const CGovernanceVote& vote, CGover
910915
911916bool CGovernanceManager::ProcessVote (CNode* pfrom, const CGovernanceVote& vote, CGovernanceException& exception, CConnman& connman)
912917{
918+ AssertLockNotHeld (cs);
913919 ENTER_CRITICAL_SECTION (cs);
914920 uint256 nHashVote = vote.GetHash ();
915921 uint256 nHashGovobj = vote.GetParentHash ();
@@ -964,10 +970,11 @@ bool CGovernanceManager::ProcessVote(CNode* pfrom, const CGovernanceVote& vote,
964970
965971void CGovernanceManager::CheckPostponedObjects ()
966972{
973+ AssertLockHeld (cs);
967974 AssertLockNotHeld (cs_relay);
968975 if (!m_mn_sync.IsSynced ()) return ;
969976
970- LOCK2 (::cs_main, cs );
977+ LOCK (::cs_main);
971978
972979 // Check postponed proposals
973980 for (auto it = mapPostponedObjects.begin (); it != mapPostponedObjects.end ();) {
@@ -1032,6 +1039,7 @@ void CGovernanceManager::CheckPostponedObjects()
10321039
10331040void CGovernanceManager::RequestGovernanceObject (CNode* pfrom, const uint256& nHash, CConnman& connman, bool fUseFilter ) const
10341041{
1042+ AssertLockNotHeld (cs);
10351043 if (!pfrom) {
10361044 return ;
10371045 }
@@ -1186,6 +1194,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
11861194
11871195bool CGovernanceManager::AcceptMessage (const uint256& nHash)
11881196{
1197+ AssertLockNotHeld (cs);
11891198 LOCK (cs);
11901199 auto it = m_requested_hash_time.find (nHash);
11911200 if (it == m_requested_hash_time.end ()) {
@@ -1199,7 +1208,7 @@ bool CGovernanceManager::AcceptMessage(const uint256& nHash)
11991208
12001209void CGovernanceManager::RebuildIndexes ()
12011210{
1202- LOCK (cs);
1211+ AssertLockHeld (cs);
12031212
12041213 cmapVoteToObject.Clear ();
12051214 for (auto & objPair : mapObjects) {
@@ -1213,7 +1222,7 @@ void CGovernanceManager::RebuildIndexes()
12131222
12141223void CGovernanceManager::AddCachedTriggers ()
12151224{
1216- LOCK (cs);
1225+ AssertLockHeld (cs);
12171226
12181227 int64_t nNow = GetTime<std::chrono::seconds>().count ();
12191228
@@ -1325,6 +1334,7 @@ UniValue CGovernanceManager::ToJson() const
13251334
13261335void CGovernanceManager::UpdatedBlockTip (const CBlockIndex* pindex)
13271336{
1337+ AssertLockNotHeld (cs);
13281338 AssertLockNotHeld (cs_relay);
13291339 // Note this gets called from ActivateBestChain without cs_main being held
13301340 // so it should be safe to lock our mutex here without risking a deadlock
@@ -1338,6 +1348,7 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex)
13381348 nCachedBlockHeight = pindex->nHeight ;
13391349 LogPrint (BCLog::GOBJECT, " CGovernanceManager::UpdatedBlockTip -- nCachedBlockHeight: %d\n " , nCachedBlockHeight);
13401350
1351+ LOCK (cs);
13411352 if (DeploymentDIP0003Enforced (pindex->nHeight , Params ().GetConsensus ())) {
13421353 RemoveInvalidVotes ();
13431354 }
@@ -1349,12 +1360,13 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex* pindex)
13491360
13501361void CGovernanceManager::RequestOrphanObjects (CConnman& connman)
13511362{
1363+ AssertLockNotHeld (cs);
13521364 const CConnman::NodesSnapshot snap{connman, /* cond = */ CConnman::FullyConnectedOnly};
13531365
13541366 std::vector<uint256> vecHashesFiltered;
13551367 {
1356- std::vector<uint256> vecHashes;
13571368 LOCK (cs);
1369+ std::vector<uint256> vecHashes;
13581370 cmmapOrphanVotes.GetKeys (vecHashes);
13591371 for (const uint256& nHash : vecHashes) {
13601372 if (mapObjects.find (nHash) == mapObjects.end ()) {
@@ -1394,12 +1406,12 @@ void CGovernanceManager::CleanOrphanObjects()
13941406
13951407void CGovernanceManager::RemoveInvalidVotes ()
13961408{
1409+ AssertLockHeld (cs);
1410+
13971411 if (!m_mn_sync.IsSynced ()) {
13981412 return ;
13991413 }
14001414
1401- LOCK (cs);
1402-
14031415 const auto tip_mn_list = Assert (m_dmnman)->GetListAtChainTip ();
14041416 auto diff = lastMNListForVotingKeys->BuildDiff (tip_mn_list);
14051417
@@ -1733,7 +1745,7 @@ bool CGovernanceManager::IsValidSuperblock(const CChain& active_chain, const CDe
17331745
17341746void CGovernanceManager::ExecuteBestSuperblock (const CDeterministicMNList& tip_mn_list, int nBlockHeight)
17351747{
1736- LOCK (cs);
1748+ AssertLockHeld (cs);
17371749
17381750 CSuperblock_sptr pSuperblock;
17391751 if (GetBestSuperblockInternal (tip_mn_list, pSuperblock, nBlockHeight)) {
0 commit comments