Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iterator cleanup in several places #2164

Merged
merged 4 commits into from
Jul 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions src/governance-classes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,12 @@ std::vector<CSuperblock_sptr> CGovernanceTriggerManager::GetActiveTriggers()
DBG( std::cout << "GetActiveTriggers: mapTrigger.size() = " << mapTrigger.size() << std::endl; );

// LOOK AT THESE OBJECTS AND COMPILE A VALID LIST OF TRIGGERS
trigger_m_it it = mapTrigger.begin();
while(it != mapTrigger.end()) {

CGovernanceObject* pObj = governance.FindGovernanceObject((*it).first);

for (const auto& pair : mapTrigger) {
CGovernanceObject* pObj = governance.FindGovernanceObject(pair.first);
if(pObj) {
DBG( std::cout << "GetActiveTriggers: pObj->GetDataAsPlainString() = " << pObj->GetDataAsPlainString() << std::endl; );
vecResults.push_back(it->second);
vecResults.push_back(pair.second);
}
++it;
}

DBG( std::cout << "GetActiveTriggers: vecResults.size() = " << vecResults.size() << std::endl; );
Expand Down
72 changes: 32 additions & 40 deletions src/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,10 +524,10 @@ std::vector<CGovernanceVote> CGovernanceManager::GetCurrentVotes(const uint256&
vote_rec_t voteRecord;
if (!govobj.GetCurrentMNVotes(mnpair.first, voteRecord)) continue;

for (vote_instance_m_it it3 = voteRecord.mapInstances.begin(); it3 != voteRecord.mapInstances.end(); ++it3) {
int signal = (it3->first);
int outcome = ((it3->second).eOutcome);
int64_t nCreationTime = ((it3->second).nCreationTime);
for (const auto& voteInstancePair : voteRecord.mapInstances) {
int signal = voteInstancePair.first;
int outcome = voteInstancePair.second.eOutcome;
int64_t nCreationTime = voteInstancePair.second.nCreationTime;

CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal, (vote_outcome_enum_t)outcome);
vote.SetTime(nCreationTime);
Expand All @@ -545,24 +545,15 @@ std::vector<const CGovernanceObject*> CGovernanceManager::GetAllNewerThan(int64_

std::vector<const CGovernanceObject*> vGovObjs;

object_m_cit it = mapObjects.begin();
while(it != mapObjects.end())
{
for (const auto& objPair : mapObjects) {
// IF THIS OBJECT IS OLDER THAN TIME, CONTINUE

if((*it).second.GetCreationTime() < nMoreThanTime) {
++it;
if(objPair.second.GetCreationTime() < nMoreThanTime) {
continue;
}

// ADD GOVERNANCE OBJECT TO LIST

const CGovernanceObject* pGovObj = &((*it).second);
const CGovernanceObject* pGovObj = &(objPair.second);
vGovObjs.push_back(pGovObj);

// NEXT

++it;
}

return vGovObjs;
Expand Down Expand Up @@ -724,9 +715,10 @@ void CGovernanceManager::SyncAll(CNode* pnode, CConnman& connman) const
LOCK2(cs_main, cs);

// all valid objects, no votes
for(object_m_cit it = mapObjects.begin(); it != mapObjects.end(); ++it) {
const CGovernanceObject& govobj = it->second;
std::string strHash = it->first.ToString();
for (const auto& objPair : mapObjects) {
uint256 nHash = objPair.first;
const CGovernanceObject& govobj = objPair.second;
std::string strHash = nHash.ToString();

LogPrint("gobject", "CGovernanceManager::%s -- attempting to sync govobj: %s, peer=%d\n", __func__, strHash, pnode->id);

Expand All @@ -738,7 +730,7 @@ void CGovernanceManager::SyncAll(CNode* pnode, CConnman& connman) const

// Push the inventory budget proposal message over to the other client
LogPrint("gobject", "CGovernanceManager::%s -- syncing govobj: %s, peer=%d\n", __func__, strHash, pnode->id);
pnode->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, it->first));
pnode->PushInventory(CInv(MSG_GOVERNANCE_OBJECT, nHash));
++nObjCount;
}

Expand Down Expand Up @@ -904,8 +896,8 @@ void CGovernanceManager::CheckMasternodeOrphanVotes(CConnman& connman)

ScopedLockBool guard(cs, fRateChecksEnabled, false);

for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
it->second.CheckOrphanVotes(connman);
for (auto& objPair : mapObjects) {
objPair.second.CheckOrphanVotes(connman);
}
}

Expand Down Expand Up @@ -1086,22 +1078,25 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&

if(mapObjects.empty()) return -2;

for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
if(mapAskedRecently.count(it->first)) {
std::map<CService, int64_t>::iterator it1 = mapAskedRecently[it->first].begin();
while(it1 != mapAskedRecently[it->first].end()) {
if(it1->second < nNow) {
mapAskedRecently[it->first].erase(it1++);
for (const auto& objPair : mapObjects) {
uint256 nHash = objPair.first;
if(mapAskedRecently.count(nHash)) {
auto it = mapAskedRecently[nHash].begin();
while(it != mapAskedRecently[nHash].end()) {
if(it->second < nNow) {
mapAskedRecently[nHash].erase(it++);
} else {
++it1;
++it;
}
}
if(mapAskedRecently[it->first].size() >= nPeersPerHashMax) continue;
if(mapAskedRecently[nHash].size() >= nPeersPerHashMax) continue;
}
if(it->second.nObjectType == GOVERNANCE_OBJECT_TRIGGER) {
vpGovObjsTriggersTmp.push_back(&(it->second));

auto govObj = objPair.second;
if(govObj.nObjectType == GOVERNANCE_OBJECT_TRIGGER) {
vpGovObjsTriggersTmp.push_back(&govObj);
} else {
vpGovObjsTmp.push_back(&(it->second));
vpGovObjsTmp.push_back(&govObj);
}
}
}
Expand Down Expand Up @@ -1188,8 +1183,8 @@ void CGovernanceManager::RebuildIndexes()
LOCK(cs);

cmapVoteToObject.Clear();
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) {
CGovernanceObject& govobj = it->second;
for (auto& objPair : mapObjects) {
CGovernanceObject& govobj = objPair.second;
std::vector<CGovernanceVote> vecVotes = govobj.GetVoteFile().GetVotes();
for(size_t i = 0; i < vecVotes.size(); ++i) {
cmapVoteToObject.Insert(vecVotes[i].GetHash(), &govobj);
Expand Down Expand Up @@ -1236,10 +1231,8 @@ std::string CGovernanceManager::ToString() const
int nTriggerCount = 0;
int nOtherCount = 0;

object_m_cit it = mapObjects.begin();

while(it != mapObjects.end()) {
switch(it->second.GetObjectType()) {
for (const auto& objPair : mapObjects) {
switch(objPair.second.GetObjectType()) {
case GOVERNANCE_OBJECT_PROPOSAL:
nProposalCount++;
break;
Expand All @@ -1250,7 +1243,6 @@ std::string CGovernanceManager::ToString() const
nOtherCount++;
break;
}
++it;
}

return strprintf("Governance Objects: %d (Proposals: %d, Triggers: %d, Other: %d; Erased: %d), Votes: %d",
Expand Down
Loading