mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
Fix deadlocks on cs_vSend in RequestGovernanceObject (#1387)
This commit is contained in:
parent
c8b6199979
commit
eb4e6a32dd
@ -1036,6 +1036,7 @@ void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nH
|
|||||||
filter.clear();
|
filter.clear();
|
||||||
|
|
||||||
if(fUseFilter) {
|
if(fUseFilter) {
|
||||||
|
LOCK(cs);
|
||||||
CGovernanceObject* pObj = FindGovernanceObject(nHash);
|
CGovernanceObject* pObj = FindGovernanceObject(nHash);
|
||||||
|
|
||||||
if(pObj) {
|
if(pObj) {
|
||||||
@ -1064,14 +1065,13 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
|
|||||||
|
|
||||||
if(vNodesCopy.empty()) return -1;
|
if(vNodesCopy.empty()) return -1;
|
||||||
|
|
||||||
LOCK2(cs_main, cs);
|
|
||||||
|
|
||||||
if(mapObjects.empty()) return -2;
|
|
||||||
|
|
||||||
int64_t nNow = GetTime();
|
int64_t nNow = GetTime();
|
||||||
int nTimeout = 60 * 60;
|
int nTimeout = 60 * 60;
|
||||||
size_t nPeersPerHashMax = 3;
|
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.
|
// 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,
|
// 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
|
// 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())));
|
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) {
|
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
|
||||||
if(mapAskedRecently.count(it->first)) {
|
if(mapAskedRecently.count(it->first)) {
|
||||||
@ -1104,6 +1106,7 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
|
|||||||
vpGovObjsTmp.push_back(&(it->second));
|
vpGovObjsTmp.push_back(&(it->second));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LogPrint("gobject", "CGovernanceManager::RequestGovernanceObjectVotes -- start: vpGovObjsTriggersTmp %d vpGovObjsTmp %d mapAskedRecently %d\n",
|
LogPrint("gobject", "CGovernanceManager::RequestGovernanceObjectVotes -- start: vpGovObjsTriggersTmp %d vpGovObjsTmp %d mapAskedRecently %d\n",
|
||||||
vpGovObjsTriggersTmp.size(), vpGovObjsTmp.size(), mapAskedRecently.size());
|
vpGovObjsTriggersTmp.size(), vpGovObjsTmp.size(), mapAskedRecently.size());
|
||||||
@ -1301,17 +1304,22 @@ void CGovernanceManager::RequestOrphanObjects()
|
|||||||
{
|
{
|
||||||
std::vector<CNode*> vNodesCopy = CopyNodeVector();
|
std::vector<CNode*> vNodesCopy = CopyNodeVector();
|
||||||
|
|
||||||
|
std::vector<uint256> vecHashesFiltered;
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
|
||||||
std::vector<uint256> vecHashes;
|
std::vector<uint256> vecHashes;
|
||||||
|
LOCK(cs);
|
||||||
mapOrphanVotes.GetKeys(vecHashes);
|
mapOrphanVotes.GetKeys(vecHashes);
|
||||||
|
|
||||||
LogPrint("gobject", "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashes.size());
|
|
||||||
for(size_t i = 0; i < vecHashes.size(); ++i) {
|
for(size_t i = 0; i < vecHashes.size(); ++i) {
|
||||||
const uint256& nHash = vecHashes[i];
|
const uint256& nHash = vecHashes[i];
|
||||||
if(mapObjects.find(nHash) != mapObjects.end()) {
|
if(mapObjects.find(nHash) == mapObjects.end()) {
|
||||||
continue;
|
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) {
|
for(size_t j = 0; j < vNodesCopy.size(); ++j) {
|
||||||
CNode* pnode = vNodesCopy[j];
|
CNode* pnode = vNodesCopy[j];
|
||||||
if(pnode->fMasternode) {
|
if(pnode->fMasternode) {
|
||||||
@ -1320,7 +1328,6 @@ void CGovernanceManager::RequestOrphanObjects()
|
|||||||
RequestGovernanceObject(pnode, nHash);
|
RequestGovernanceObject(pnode, nHash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ReleaseNodeVector(vNodesCopy);
|
ReleaseNodeVector(vNodesCopy);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user