Skip to content

Commit 2f5339d

Browse files
committed
more 14193: fix governence vs mempool deadlock v2
1 parent 48af52c commit 2f5339d

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/governance/governance.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, const std::string& msg_typ
143143
return;
144144
}
145145

146-
LOCK2(cs_main, cs);
146+
LOCK2(cs_main, ::mempool.cs); // Lock mempool because of GetTransaction deep inside
147+
LOCK(cs);
147148

148149
if (mapObjects.count(nHash) || mapPostponedObjects.count(nHash) || mapErasedGovernanceObjects.count(nHash)) {
149150
// TODO - print error code? what if it's GOVOBJ_ERROR_IMMATURE?
@@ -262,7 +263,8 @@ void CGovernanceManager::AddGovernanceObject(CGovernanceObject& govobj, CConnman
262263

263264
govobj.UpdateSentinelVariables(); //this sets local vars in object
264265

265-
LOCK2(cs_main, cs);
266+
LOCK2(cs_main, ::mempool.cs); // Lock mempool because of GetTransaction deep inside
267+
LOCK(cs);
266268
std::string strError;
267269

268270
// MAKE SURE THIS OBJECT IS OK
@@ -321,7 +323,8 @@ void CGovernanceManager::UpdateCachesAndClean()
321323

322324
std::vector<uint256> vecDirtyHashes = mmetaman.GetAndClearDirtyGovernanceObjectHashes();
323325

324-
LOCK2(cs_main, cs);
326+
LOCK2(cs_main, ::mempool.cs); // Lock mempool because of GetTransaction deep inside
327+
LOCK(cs);
325328

326329
for (const uint256& nHash : vecDirtyHashes) {
327330
auto it = mapObjects.find(nHash);
@@ -836,7 +839,8 @@ void CGovernanceManager::CheckPostponedObjects(CConnman& connman)
836839
{
837840
if (!masternodeSync.IsSynced()) return;
838841

839-
LOCK2(cs_main, cs);
842+
LOCK2(cs_main, ::mempool.cs); // Lock mempool because of GetTransaction deep inside
843+
LOCK(cs);
840844

841845
// Check postponed proposals
842846
for (auto it = mapPostponedObjects.begin(); it != mapPostponedObjects.end();) {

src/governance/object.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ UniValue CGovernanceObject::ToJson() const
438438

439439
void CGovernanceObject::UpdateLocalValidity()
440440
{
441-
LOCK(cs_main);
441+
AssertLockHeld(cs_main);
442442
// THIS DOES NOT CHECK COLLATERAL, THIS IS CHECKED UPON ORIGINAL ARRIVAL
443443
fCachedLocalValidity = IsValidLocally(strLocalValidityError, false);
444444
}
@@ -526,6 +526,9 @@ CAmount CGovernanceObject::GetMinCollateralFee(bool fork_active) const
526526

527527
bool CGovernanceObject::IsCollateralValid(std::string& strError, bool& fMissingConfirmations) const
528528
{
529+
AssertLockHeld(cs_main);
530+
AssertLockHeld(::mempool.cs); // because of GetTransaction
531+
529532
strError = "";
530533
fMissingConfirmations = false;
531534
uint256 nExpectedHash = GetHash();

src/rpc/governance.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ static UniValue gobject_submit(const JSONRPCRequest& request)
396396
g_txindex->BlockUntilSyncedToCurrentChain();
397397
}
398398

399-
LOCK(cs_main);
399+
LOCK2(cs_main, ::mempool.cs);
400400
if (!govobj.IsValidLocally(strError, fMissingConfirmations, true) && !fMissingConfirmations) {
401401
LogPrintf("gobject(submit) -- Object submission rejected because object is not valid - hash = %s, strError = %s\n", strHash, strError);
402402
throw JSONRPCError(RPC_INTERNAL_ERROR, "Governance object is not valid - " + strHash + " - " + strError);

0 commit comments

Comments
 (0)