Fix deadlocks on cs_vSend in RequestGovernanceObject (#1387)

This commit is contained in:
Tim Flynn 2017-03-08 17:36:40 -05:00 committed by UdjinM6
parent c8b6199979
commit eb4e6a32dd

View File

@ -1036,6 +1036,7 @@ void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nH
filter.clear();
if(fUseFilter) {
LOCK(cs);
CGovernanceObject* pObj = FindGovernanceObject(nHash);
if(pObj) {
@ -1064,14 +1065,13 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
if(vNodesCopy.empty()) return -1;
LOCK2(cs_main, cs);
if(mapObjects.empty()) return -2;
int64_t nNow = GetTime();
int nTimeout = 60 * 60;
size_t nPeersPerHashMax = 3;
std::vector<CGovernanceObject*> vpGovObjsTmp;
std::vector<CGovernanceObject*> vpGovObjsTriggersTmp;
// This should help us to get some idea about an impact this can bring once deployed on mainnet.
// Testnet is ~40 times smaller in masternode count, but only ~1000 masternodes usually vote,
// so 1 obj on mainnet == ~10 objs or ~1000 votes on testnet. However we want to test a higher
@ -1083,8 +1083,10 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
nMaxObjRequestsPerNode = std::max(1, int(nProjectedVotes / std::max(1, mnodeman.size())));
}
std::vector<CGovernanceObject*> vpGovObjsTmp;
std::vector<CGovernanceObject*> vpGovObjsTriggersTmp;
{
LOCK2(cs_main, cs);
if(mapObjects.empty()) return -2;
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
if(mapAskedRecently.count(it->first)) {
@ -1104,6 +1106,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
vpGovObjsTmp.push_back(&(it->second));
}
}
}
LogPrint("gobject", "CGovernanceManager::RequestGovernanceObjectVotes -- start: vpGovObjsTriggersTmp %d vpGovObjsTmp %d mapAskedRecently %d\n",
vpGovObjsTriggersTmp.size(), vpGovObjsTmp.size(), mapAskedRecently.size());
@ -1301,17 +1304,22 @@ void CGovernanceManager::RequestOrphanObjects()
{
std::vector<CNode*> vNodesCopy = CopyNodeVector();
std::vector<uint256> vecHashesFiltered;
{
LOCK(cs);
std::vector<uint256> vecHashes;
LOCK(cs);
mapOrphanVotes.GetKeys(vecHashes);
LogPrint("gobject", "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashes.size());
for(size_t i = 0; i < vecHashes.size(); ++i) {
const uint256& nHash = vecHashes[i];
if(mapObjects.find(nHash) != mapObjects.end()) {
continue;
if(mapObjects.find(nHash) == mapObjects.end()) {
vecHashesFiltered.push_back(nHash);
}
}
}
LogPrint("gobject", "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashesFiltered.size());
for(size_t i = 0; i < vecHashesFiltered.size(); ++i) {
const uint256& nHash = vecHashesFiltered[i];
for(size_t j = 0; j < vNodesCopy.size(); ++j) {
CNode* pnode = vNodesCopy[j];
if(pnode->fMasternode) {
@ -1320,7 +1328,6 @@ void CGovernanceManager::RequestOrphanObjects()
RequestGovernanceObject(pnode, nHash);
}
}
}
ReleaseNodeVector(vNodesCopy);
}