iterator cleanup in several places (#2164)

* iterator cleanup in Dash-specific code

* const

* *Pair/pair

* it++ -> ++it
This commit is contained in:
Nathan Marley 2018-07-12 16:07:51 +07:00 committed by UdjinM6
parent df1be90ce1
commit fd70a1eb92
8 changed files with 98 additions and 154 deletions

View File

@ -239,16 +239,12 @@ std::vector<CSuperblock_sptr> CGovernanceTriggerManager::GetActiveTriggers()
DBG( std::cout << "GetActiveTriggers: mapTrigger.size() = " << mapTrigger.size() << std::endl; ); DBG( std::cout << "GetActiveTriggers: mapTrigger.size() = " << mapTrigger.size() << std::endl; );
// LOOK AT THESE OBJECTS AND COMPILE A VALID LIST OF TRIGGERS // LOOK AT THESE OBJECTS AND COMPILE A VALID LIST OF TRIGGERS
trigger_m_it it = mapTrigger.begin(); for (const auto& pair : mapTrigger) {
while(it != mapTrigger.end()) { CGovernanceObject* pObj = governance.FindGovernanceObject(pair.first);
CGovernanceObject* pObj = governance.FindGovernanceObject((*it).first);
if(pObj) { if(pObj) {
DBG( std::cout << "GetActiveTriggers: pObj->GetDataAsPlainString() = " << pObj->GetDataAsPlainString() << std::endl; ); 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; ); DBG( std::cout << "GetActiveTriggers: vecResults.size() = " << vecResults.size() << std::endl; );

View File

@ -530,10 +530,10 @@ std::vector<CGovernanceVote> CGovernanceManager::GetCurrentVotes(const uint256&
vote_rec_t voteRecord; vote_rec_t voteRecord;
if (!govobj.GetCurrentMNVotes(mnpair.first, voteRecord)) continue; if (!govobj.GetCurrentMNVotes(mnpair.first, voteRecord)) continue;
for (vote_instance_m_it it3 = voteRecord.mapInstances.begin(); it3 != voteRecord.mapInstances.end(); ++it3) { for (const auto& voteInstancePair : voteRecord.mapInstances) {
int signal = (it3->first); int signal = voteInstancePair.first;
int outcome = ((it3->second).eOutcome); int outcome = voteInstancePair.second.eOutcome;
int64_t nCreationTime = ((it3->second).nCreationTime); int64_t nCreationTime = voteInstancePair.second.nCreationTime;
CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal, (vote_outcome_enum_t)outcome); CGovernanceVote vote = CGovernanceVote(mnpair.first, nParentHash, (vote_signal_enum_t)signal, (vote_outcome_enum_t)outcome);
vote.SetTime(nCreationTime); vote.SetTime(nCreationTime);
@ -551,24 +551,15 @@ std::vector<const CGovernanceObject*> CGovernanceManager::GetAllNewerThan(int64_
std::vector<const CGovernanceObject*> vGovObjs; std::vector<const CGovernanceObject*> vGovObjs;
object_m_cit it = mapObjects.begin(); for (const auto& objPair : mapObjects) {
while(it != mapObjects.end())
{
// IF THIS OBJECT IS OLDER THAN TIME, CONTINUE // IF THIS OBJECT IS OLDER THAN TIME, CONTINUE
if(objPair.second.GetCreationTime() < nMoreThanTime) {
if((*it).second.GetCreationTime() < nMoreThanTime) {
++it;
continue; continue;
} }
// ADD GOVERNANCE OBJECT TO LIST // ADD GOVERNANCE OBJECT TO LIST
const CGovernanceObject* pGovObj = &(objPair.second);
const CGovernanceObject* pGovObj = &((*it).second);
vGovObjs.push_back(pGovObj); vGovObjs.push_back(pGovObj);
// NEXT
++it;
} }
return vGovObjs; return vGovObjs;
@ -730,9 +721,10 @@ void CGovernanceManager::SyncAll(CNode* pnode, CConnman& connman) const
LOCK2(cs_main, cs); LOCK2(cs_main, cs);
// all valid objects, no votes // all valid objects, no votes
for(object_m_cit it = mapObjects.begin(); it != mapObjects.end(); ++it) { for (const auto& objPair : mapObjects) {
const CGovernanceObject& govobj = it->second; uint256 nHash = objPair.first;
std::string strHash = it->first.ToString(); 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); LogPrint("gobject", "CGovernanceManager::%s -- attempting to sync govobj: %s, peer=%d\n", __func__, strHash, pnode->id);
@ -744,7 +736,7 @@ void CGovernanceManager::SyncAll(CNode* pnode, CConnman& connman) const
// Push the inventory budget proposal message over to the other client // 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); 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; ++nObjCount;
} }
@ -910,8 +902,8 @@ void CGovernanceManager::CheckMasternodeOrphanVotes(CConnman& connman)
ScopedLockBool guard(cs, fRateChecksEnabled, false); ScopedLockBool guard(cs, fRateChecksEnabled, false);
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { for (auto& objPair : mapObjects) {
it->second.CheckOrphanVotes(connman); objPair.second.CheckOrphanVotes(connman);
} }
} }
@ -1092,22 +1084,25 @@ int CGovernanceManager::RequestGovernanceObjectVotes(const std::vector<CNode*>&
if(mapObjects.empty()) return -2; if(mapObjects.empty()) return -2;
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { for (const auto& objPair : mapObjects) {
if(mapAskedRecently.count(it->first)) { uint256 nHash = objPair.first;
std::map<CService, int64_t>::iterator it1 = mapAskedRecently[it->first].begin(); if(mapAskedRecently.count(nHash)) {
while(it1 != mapAskedRecently[it->first].end()) { auto it = mapAskedRecently[nHash].begin();
if(it1->second < nNow) { while(it != mapAskedRecently[nHash].end()) {
mapAskedRecently[it->first].erase(it1++); if(it->second < nNow) {
mapAskedRecently[nHash].erase(it++);
} else { } 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 { } else {
vpGovObjsTmp.push_back(&(it->second)); vpGovObjsTmp.push_back(&govObj);
} }
} }
} }
@ -1194,8 +1189,8 @@ void CGovernanceManager::RebuildIndexes()
LOCK(cs); LOCK(cs);
cmapVoteToObject.Clear(); cmapVoteToObject.Clear();
for(object_m_it it = mapObjects.begin(); it != mapObjects.end(); ++it) { for (auto& objPair : mapObjects) {
CGovernanceObject& govobj = it->second; CGovernanceObject& govobj = objPair.second;
std::vector<CGovernanceVote> vecVotes = govobj.GetVoteFile().GetVotes(); std::vector<CGovernanceVote> vecVotes = govobj.GetVoteFile().GetVotes();
for(size_t i = 0; i < vecVotes.size(); ++i) { for(size_t i = 0; i < vecVotes.size(); ++i) {
cmapVoteToObject.Insert(vecVotes[i].GetHash(), &govobj); cmapVoteToObject.Insert(vecVotes[i].GetHash(), &govobj);
@ -1242,10 +1237,8 @@ std::string CGovernanceManager::ToString() const
int nTriggerCount = 0; int nTriggerCount = 0;
int nOtherCount = 0; int nOtherCount = 0;
object_m_cit it = mapObjects.begin(); for (const auto& objPair : mapObjects) {
switch(objPair.second.GetObjectType()) {
while(it != mapObjects.end()) {
switch(it->second.GetObjectType()) {
case GOVERNANCE_OBJECT_PROPOSAL: case GOVERNANCE_OBJECT_PROPOSAL:
nProposalCount++; nProposalCount++;
break; break;
@ -1256,7 +1249,6 @@ std::string CGovernanceManager::ToString() const
nOtherCount++; nOtherCount++;
break; break;
} }
++it;
} }
return strprintf("Governance Objects: %d (Proposals: %d, Triggers: %d, Other: %d; Erased: %d), Votes: %d", return strprintf("Governance Objects: %d (Proposals: %d, Triggers: %d, Other: %d; Erased: %d), Votes: %d",

View File

@ -223,12 +223,10 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
if(mapLockRequestAccepted.find(txHash) == mapLockRequestAccepted.end()) return; if(mapLockRequestAccepted.find(txHash) == mapLockRequestAccepted.end()) return;
// check if we need to vote on this candidate's outpoints, // check if we need to vote on this candidate's outpoints,
// it's possible that we need to vote for several of them // it's possible that we need to vote for several of them
std::map<COutPoint, COutPointLock>::iterator itOutpointLock = txLockCandidate.mapOutPointLocks.begin(); for (auto& outpointLockPair : txLockCandidate.mapOutPointLocks) {
while(itOutpointLock != txLockCandidate.mapOutPointLocks.end()) { int nPrevoutHeight = GetUTXOHeight(outpointLockPair.first);
int nPrevoutHeight = GetUTXOHeight(itOutpointLock->first);
if(nPrevoutHeight == -1) { if(nPrevoutHeight == -1) {
LogPrint("instantsend", "CInstantSend::Vote -- Failed to find UTXO %s\n", itOutpointLock->first.ToStringShort()); LogPrint("instantsend", "CInstantSend::Vote -- Failed to find UTXO %s\n", outpointLockPair.first.ToStringShort());
return; return;
} }
@ -238,20 +236,18 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto()); int nMinRequiredProtocol = std::max(MIN_INSTANTSEND_PROTO_VERSION, mnpayments.GetMinMasternodePaymentsProto());
if(!mnodeman.GetMasternodeRank(activeMasternode.outpoint, nRank, nLockInputHeight, nMinRequiredProtocol)) { if(!mnodeman.GetMasternodeRank(activeMasternode.outpoint, nRank, nLockInputHeight, nMinRequiredProtocol)) {
LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternode.outpoint.ToStringShort()); LogPrint("instantsend", "CInstantSend::Vote -- Can't calculate rank for masternode %s\n", activeMasternode.outpoint.ToStringShort());
++itOutpointLock;
continue; continue;
} }
int nSignaturesTotal = COutPointLock::SIGNATURES_TOTAL; int nSignaturesTotal = COutPointLock::SIGNATURES_TOTAL;
if(nRank > nSignaturesTotal) { if(nRank > nSignaturesTotal) {
LogPrint("instantsend", "CInstantSend::Vote -- Masternode not in the top %d (%d)\n", nSignaturesTotal, nRank); LogPrint("instantsend", "CInstantSend::Vote -- Masternode not in the top %d (%d)\n", nSignaturesTotal, nRank);
++itOutpointLock;
continue; continue;
} }
LogPrint("instantsend", "CInstantSend::Vote -- In the top %d (%d)\n", nSignaturesTotal, nRank); LogPrint("instantsend", "CInstantSend::Vote -- In the top %d (%d)\n", nSignaturesTotal, nRank);
std::map<COutPoint, std::set<uint256> >::iterator itVoted = mapVotedOutpoints.find(itOutpointLock->first); std::map<COutPoint, std::set<uint256> >::iterator itVoted = mapVotedOutpoints.find(outpointLockPair.first);
// Check to see if we already voted for this outpoint, // Check to see if we already voted for this outpoint,
// refuse to vote twice or to include the same outpoint in another tx // refuse to vote twice or to include the same outpoint in another tx
@ -259,23 +255,22 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
if(itVoted != mapVotedOutpoints.end()) { if(itVoted != mapVotedOutpoints.end()) {
for (const auto& hash : itVoted->second) { for (const auto& hash : itVoted->second) {
std::map<uint256, CTxLockCandidate>::iterator it2 = mapTxLockCandidates.find(hash); std::map<uint256, CTxLockCandidate>::iterator it2 = mapTxLockCandidates.find(hash);
if(it2->second.HasMasternodeVoted(itOutpointLock->first, activeMasternode.outpoint)) { if(it2->second.HasMasternodeVoted(outpointLockPair.first, activeMasternode.outpoint)) {
// we already voted for this outpoint to be included either in the same tx or in a competing one, // we already voted for this outpoint to be included either in the same tx or in a competing one,
// skip it anyway // skip it anyway
fAlreadyVoted = true; fAlreadyVoted = true;
LogPrintf("CInstantSend::Vote -- WARNING: We already voted for this outpoint, skipping: txHash=%s, outpoint=%s\n", LogPrintf("CInstantSend::Vote -- WARNING: We already voted for this outpoint, skipping: txHash=%s, outpoint=%s\n",
txHash.ToString(), itOutpointLock->first.ToStringShort()); txHash.ToString(), outpointLockPair.first.ToStringShort());
break; break;
} }
} }
} }
if(fAlreadyVoted) { if(fAlreadyVoted) {
++itOutpointLock;
continue; // skip to the next outpoint continue; // skip to the next outpoint
} }
// we haven't voted for this outpoint yet, let's try to do this now // we haven't voted for this outpoint yet, let's try to do this now
CTxLockVote vote(txHash, itOutpointLock->first, activeMasternode.outpoint); CTxLockVote vote(txHash, outpointLockPair.first, activeMasternode.outpoint);
if(!vote.Sign()) { if(!vote.Sign()) {
LogPrintf("CInstantSend::Vote -- Failed to sign consensus vote\n"); LogPrintf("CInstantSend::Vote -- Failed to sign consensus vote\n");
@ -289,27 +284,25 @@ void CInstantSend::Vote(CTxLockCandidate& txLockCandidate, CConnman& connman)
// vote constructed sucessfully, let's store and relay it // vote constructed sucessfully, let's store and relay it
uint256 nVoteHash = vote.GetHash(); uint256 nVoteHash = vote.GetHash();
mapTxLockVotes.insert(std::make_pair(nVoteHash, vote)); mapTxLockVotes.insert(std::make_pair(nVoteHash, vote));
if(itOutpointLock->second.AddVote(vote)) { if(outpointLockPair.second.AddVote(vote)) {
LogPrintf("CInstantSend::Vote -- Vote created successfully, relaying: txHash=%s, outpoint=%s, vote=%s\n", LogPrintf("CInstantSend::Vote -- Vote created successfully, relaying: txHash=%s, outpoint=%s, vote=%s\n",
txHash.ToString(), itOutpointLock->first.ToStringShort(), nVoteHash.ToString()); txHash.ToString(), outpointLockPair.first.ToStringShort(), nVoteHash.ToString());
if(itVoted == mapVotedOutpoints.end()) { if(itVoted == mapVotedOutpoints.end()) {
std::set<uint256> setHashes; std::set<uint256> setHashes;
setHashes.insert(txHash); setHashes.insert(txHash);
mapVotedOutpoints.insert(std::make_pair(itOutpointLock->first, setHashes)); mapVotedOutpoints.insert(std::make_pair(outpointLockPair.first, setHashes));
} else { } else {
mapVotedOutpoints[itOutpointLock->first].insert(txHash); mapVotedOutpoints[outpointLockPair.first].insert(txHash);
if(mapVotedOutpoints[itOutpointLock->first].size() > 1) { if(mapVotedOutpoints[outpointLockPair.first].size() > 1) {
// it's ok to continue, just warn user // it's ok to continue, just warn user
LogPrintf("CInstantSend::Vote -- WARNING: Vote conflicts with some existing votes: txHash=%s, outpoint=%s, vote=%s\n", LogPrintf("CInstantSend::Vote -- WARNING: Vote conflicts with some existing votes: txHash=%s, outpoint=%s, vote=%s\n",
txHash.ToString(), itOutpointLock->first.ToStringShort(), nVoteHash.ToString()); txHash.ToString(), outpointLockPair.first.ToStringShort(), nVoteHash.ToString());
} }
} }
vote.Relay(connman); vote.Relay(connman);
} }
++itOutpointLock;
} }
} }
@ -548,11 +541,8 @@ void CInstantSend::LockTransactionInputs(const CTxLockCandidate& txLockCandidate
if(!txLockCandidate.IsAllOutPointsReady()) return; if(!txLockCandidate.IsAllOutPointsReady()) return;
std::map<COutPoint, COutPointLock>::const_iterator it = txLockCandidate.mapOutPointLocks.begin(); for (const auto& pair : txLockCandidate.mapOutPointLocks) {
mapLockedOutpoints.insert(std::make_pair(pair.first, txHash));
while(it != txLockCandidate.mapOutPointLocks.end()) {
mapLockedOutpoints.insert(std::make_pair(it->first, txHash));
++it;
} }
LogPrint("instantsend", "CInstantSend::LockTransactionInputs -- done, txid=%s\n", txHash.ToString()); LogPrint("instantsend", "CInstantSend::LockTransactionInputs -- done, txid=%s\n", txHash.ToString());
} }
@ -648,12 +638,9 @@ int64_t CInstantSend::GetAverageMasternodeOrphanVoteTime()
// NOTE: should never actually call this function when mapMasternodeOrphanVotes is empty // NOTE: should never actually call this function when mapMasternodeOrphanVotes is empty
if(mapMasternodeOrphanVotes.empty()) return 0; if(mapMasternodeOrphanVotes.empty()) return 0;
std::map<COutPoint, int64_t>::iterator it = mapMasternodeOrphanVotes.begin();
int64_t total = 0; int64_t total = 0;
for (const auto& pair : mapMasternodeOrphanVotes) {
while(it != mapMasternodeOrphanVotes.end()) { total += pair.second;
total+= it->second;
++it;
} }
return total / mapMasternodeOrphanVotes.size(); return total / mapMasternodeOrphanVotes.size();
@ -673,11 +660,10 @@ void CInstantSend::CheckAndRemove()
uint256 txHash = txLockCandidate.GetHash(); uint256 txHash = txLockCandidate.GetHash();
if(txLockCandidate.IsExpired(nCachedBlockHeight)) { if(txLockCandidate.IsExpired(nCachedBlockHeight)) {
LogPrintf("CInstantSend::CheckAndRemove -- Removing expired Transaction Lock Candidate: txid=%s\n", txHash.ToString()); LogPrintf("CInstantSend::CheckAndRemove -- Removing expired Transaction Lock Candidate: txid=%s\n", txHash.ToString());
std::map<COutPoint, COutPointLock>::iterator itOutpointLock = txLockCandidate.mapOutPointLocks.begin();
while(itOutpointLock != txLockCandidate.mapOutPointLocks.end()) { for (const auto& pair : txLockCandidate.mapOutPointLocks) {
mapLockedOutpoints.erase(itOutpointLock->first); mapLockedOutpoints.erase(pair.first);
mapVotedOutpoints.erase(itOutpointLock->first); mapVotedOutpoints.erase(pair.first);
++itOutpointLock;
} }
mapLockRequestAccepted.erase(txHash); mapLockRequestAccepted.erase(txHash);
mapLockRequestRejected.erase(txHash); mapLockRequestRejected.erase(txHash);
@ -828,11 +814,9 @@ bool CInstantSend::IsLockedInstantSendTransaction(const uint256& txHash)
if(itLockCandidate->second.mapOutPointLocks.empty()) return false; if(itLockCandidate->second.mapOutPointLocks.empty()) return false;
// and all of these outputs must be included in mapLockedOutpoints with correct hash // and all of these outputs must be included in mapLockedOutpoints with correct hash
std::map<COutPoint, COutPointLock>::iterator itOutpointLock = itLockCandidate->second.mapOutPointLocks.begin(); for (const auto& pair : itLockCandidate->second.mapOutPointLocks) {
while(itOutpointLock != itLockCandidate->second.mapOutPointLocks.end()) {
uint256 hashLocked; uint256 hashLocked;
if(!GetLockedOutPointTxHash(itOutpointLock->first, hashLocked) || hashLocked != txHash) return false; if(!GetLockedOutPointTxHash(pair.first, hashLocked) || hashLocked != txHash) return false;
++itOutpointLock;
} }
return true; return true;
@ -912,35 +896,28 @@ void CInstantSend::SyncTransaction(const CTransaction& tx, const CBlockIndex *pi
txHash.ToString(), nHeightNew); txHash.ToString(), nHeightNew);
itLockCandidate->second.SetConfirmedHeight(nHeightNew); itLockCandidate->second.SetConfirmedHeight(nHeightNew);
// Loop through outpoint locks // Loop through outpoint locks
std::map<COutPoint, COutPointLock>::iterator itOutpointLock = itLockCandidate->second.mapOutPointLocks.begin(); for (const auto& pair : itLockCandidate->second.mapOutPointLocks) {
while(itOutpointLock != itLockCandidate->second.mapOutPointLocks.end()) {
// Check corresponding lock votes // Check corresponding lock votes
std::vector<CTxLockVote> vVotes = itOutpointLock->second.GetVotes(); for (const auto& vote : pair.second.GetVotes()) {
std::vector<CTxLockVote>::iterator itVote = vVotes.begin(); uint256 nVoteHash = vote.GetHash();
std::map<uint256, CTxLockVote>::iterator it;
while(itVote != vVotes.end()) {
uint256 nVoteHash = itVote->GetHash();
LogPrint("instantsend", "CInstantSend::SyncTransaction -- txid=%s nHeightNew=%d vote %s updated\n", LogPrint("instantsend", "CInstantSend::SyncTransaction -- txid=%s nHeightNew=%d vote %s updated\n",
txHash.ToString(), nHeightNew, nVoteHash.ToString()); txHash.ToString(), nHeightNew, nVoteHash.ToString());
it = mapTxLockVotes.find(nVoteHash); const auto& it = mapTxLockVotes.find(nVoteHash);
if(it != mapTxLockVotes.end()) { if(it != mapTxLockVotes.end()) {
it->second.SetConfirmedHeight(nHeightNew); it->second.SetConfirmedHeight(nHeightNew);
} }
++itVote;
} }
++itOutpointLock;
} }
} }
// check orphan votes // check orphan votes
std::map<uint256, CTxLockVote>::iterator itOrphanVote = mapTxLockVotesOrphan.begin(); for (const auto& pair : mapTxLockVotesOrphan) {
while(itOrphanVote != mapTxLockVotesOrphan.end()) { if(pair.second.GetTxHash() == txHash) {
if(itOrphanVote->second.GetTxHash() == txHash) {
LogPrint("instantsend", "CInstantSend::SyncTransaction -- txid=%s nHeightNew=%d vote %s updated\n", LogPrint("instantsend", "CInstantSend::SyncTransaction -- txid=%s nHeightNew=%d vote %s updated\n",
txHash.ToString(), nHeightNew, itOrphanVote->first.ToString()); txHash.ToString(), nHeightNew, pair.first.ToString());
mapTxLockVotes[itOrphanVote->first].SetConfirmedHeight(nHeightNew); mapTxLockVotes[pair.first].SetConfirmedHeight(nHeightNew);
} }
++itOrphanVote;
} }
} }
@ -1178,10 +1155,8 @@ bool COutPointLock::AddVote(const CTxLockVote& vote)
std::vector<CTxLockVote> COutPointLock::GetVotes() const std::vector<CTxLockVote> COutPointLock::GetVotes() const
{ {
std::vector<CTxLockVote> vRet; std::vector<CTxLockVote> vRet;
std::map<COutPoint, CTxLockVote>::const_iterator itVote = mapMasternodeVotes.begin(); for (const auto& pair : mapMasternodeVotes) {
while(itVote != mapMasternodeVotes.end()) { vRet.push_back(pair.second);
vRet.push_back(itVote->second);
++itVote;
} }
return vRet; return vRet;
} }
@ -1193,10 +1168,8 @@ bool COutPointLock::HasMasternodeVoted(const COutPoint& outpointMasternodeIn) co
void COutPointLock::Relay(CConnman& connman) const void COutPointLock::Relay(CConnman& connman) const
{ {
std::map<COutPoint, CTxLockVote>::const_iterator itVote = mapMasternodeVotes.begin(); for (const auto& pair : mapMasternodeVotes) {
while(itVote != mapMasternodeVotes.end()) { pair.second.Relay(connman);
itVote->second.Relay(connman);
++itVote;
} }
} }
@ -1227,10 +1200,8 @@ bool CTxLockCandidate::IsAllOutPointsReady() const
{ {
if(mapOutPointLocks.empty()) return false; if(mapOutPointLocks.empty()) return false;
std::map<COutPoint, COutPointLock>::const_iterator it = mapOutPointLocks.begin(); for (const auto& pair : mapOutPointLocks) {
while(it != mapOutPointLocks.end()) { if(!pair.second.IsReady()) return false;
if(!it->second.IsReady()) return false;
++it;
} }
return true; return true;
} }
@ -1245,10 +1216,8 @@ int CTxLockCandidate::CountVotes() const
{ {
// Note: do NOT use vote count to figure out if tx is locked, use IsAllOutPointsReady() instead // Note: do NOT use vote count to figure out if tx is locked, use IsAllOutPointsReady() instead
int nCountVotes = 0; int nCountVotes = 0;
std::map<COutPoint, COutPointLock>::const_iterator it = mapOutPointLocks.begin(); for (const auto& pair : mapOutPointLocks) {
while(it != mapOutPointLocks.end()) { nCountVotes += pair.second.CountVotes();
nCountVotes += it->second.CountVotes();
++it;
} }
return nCountVotes; return nCountVotes;
} }
@ -1267,9 +1236,7 @@ bool CTxLockCandidate::IsTimedOut() const
void CTxLockCandidate::Relay(CConnman& connman) const void CTxLockCandidate::Relay(CConnman& connman) const
{ {
connman.RelayTransaction(*txLockRequest.tx); connman.RelayTransaction(*txLockRequest.tx);
std::map<COutPoint, COutPointLock>::const_iterator itOutpointLock = mapOutPointLocks.begin(); for (const auto& pair : mapOutPointLocks) {
while(itOutpointLock != mapOutPointLocks.end()) { pair.second.Relay(connman);
itOutpointLock->second.Relay(connman);
++itOutpointLock;
} }
} }

View File

@ -1009,12 +1009,11 @@ void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode, CConnman& co
pindex = pindex->pprev; pindex = pindex->pprev;
} }
auto it = mapMasternodeBlocks.begin(); for (auto& mnBlockPayees : mapMasternodeBlocks) {
int nBlockHeight = mnBlockPayees.first;
while(it != mapMasternodeBlocks.end()) {
int nTotalVotes = 0; int nTotalVotes = 0;
bool fFound = false; bool fFound = false;
for (const auto& payee : it->second.vecPayees) { for (const auto& payee : mnBlockPayees.second.vecPayees) {
if(payee.GetVoteCount() >= MNPAYMENTS_SIGNATURES_REQUIRED) { if(payee.GetVoteCount() >= MNPAYMENTS_SIGNATURES_REQUIRED) {
fFound = true; fFound = true;
break; break;
@ -1025,24 +1024,23 @@ void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode, CConnman& co
// or no clear winner was found but there are at least avg number of votes // or no clear winner was found but there are at least avg number of votes
if(fFound || nTotalVotes >= (MNPAYMENTS_SIGNATURES_TOTAL + MNPAYMENTS_SIGNATURES_REQUIRED)/2) { if(fFound || nTotalVotes >= (MNPAYMENTS_SIGNATURES_TOTAL + MNPAYMENTS_SIGNATURES_REQUIRED)/2) {
// so just move to the next block // so just move to the next block
++it;
continue; continue;
} }
// DEBUG // DEBUG
DBG ( DBG (
// Let's see why this failed // Let's see why this failed
for (const auto& payee : it->second.vecPayees) { for (const auto& payee : mnBlockPayees.second.vecPayees) {
CTxDestination address1; CTxDestination address1;
ExtractDestination(payee.GetPayee(), address1); ExtractDestination(payee.GetPayee(), address1);
CBitcoinAddress address2(address1); CBitcoinAddress address2(address1);
printf("payee %s votes %d\n", address2.ToString().c_str(), payee.GetVoteCount()); printf("payee %s votes %d\n", address2.ToString().c_str(), payee.GetVoteCount());
} }
printf("block %d votes total %d\n", it->first, nTotalVotes); printf("block %d votes total %d\n", nBlockHeight, nTotalVotes);
) )
// END DEBUG // END DEBUG
// Low data block found, let's try to sync it // Low data block found, let's try to sync it
uint256 hash; uint256 hash;
if(GetBlockHash(hash, it->first)) { if(GetBlockHash(hash, nBlockHeight)) {
vToFetch.push_back(CInv(MSG_MASTERNODE_PAYMENT_BLOCK, hash)); vToFetch.push_back(CInv(MSG_MASTERNODE_PAYMENT_BLOCK, hash));
} }
// We should not violate GETDATA rules // We should not violate GETDATA rules
@ -1052,7 +1050,6 @@ void CMasternodePayments::RequestLowDataPaymentBlocks(CNode* pnode, CConnman& co
// Start filling new batch // Start filling new batch
vToFetch.clear(); vToFetch.clear();
} }
++it;
} }
// Ask for the rest of it // Ask for the rest of it
if(!vToFetch.empty()) { if(!vToFetch.empty()) {

View File

@ -772,14 +772,11 @@ void CMasternodeMan::ProcessPendingMnbRequests(CConnman& connman)
bool fDone = connman.ForNode(itPendingMNB->first, [&](CNode* pnode) { bool fDone = connman.ForNode(itPendingMNB->first, [&](CNode* pnode) {
// compile request vector // compile request vector
std::vector<CInv> vToFetch; std::vector<CInv> vToFetch;
std::set<uint256>& setHashes = itPendingMNB->second.second; for (auto& nHash : itPendingMNB->second.second) {
std::set<uint256>::iterator it = setHashes.begin(); if(nHash != uint256()) {
while(it != setHashes.end()) { vToFetch.push_back(CInv(MSG_MASTERNODE_ANNOUNCE, nHash));
if(*it != uint256()) { LogPrint("masternode", "-- asking for mnb %s from addr=%s\n", nHash.ToString(), pnode->addr.ToString());
vToFetch.push_back(CInv(MSG_MASTERNODE_ANNOUNCE, *it));
LogPrint("masternode", "-- asking for mnb %s from addr=%s\n", it->ToString(), pnode->addr.ToString());
} }
++it;
} }
// ask for data // ask for data
@ -1013,20 +1010,18 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
int nRanksTotal = (int)vecMasternodeRanks.size(); int nRanksTotal = (int)vecMasternodeRanks.size();
// send verify requests only if we are in top MAX_POSE_RANK // send verify requests only if we are in top MAX_POSE_RANK
rank_pair_vec_t::iterator it = vecMasternodeRanks.begin(); for (auto& rankPair : vecMasternodeRanks) {
while(it != vecMasternodeRanks.end()) { if(rankPair.first > MAX_POSE_RANK) {
if(it->first > MAX_POSE_RANK) {
LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Must be in top %d to send verify request\n", LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Must be in top %d to send verify request\n",
(int)MAX_POSE_RANK); (int)MAX_POSE_RANK);
return; return;
} }
if(it->second.outpoint == activeMasternode.outpoint) { if(rankPair.second.outpoint == activeMasternode.outpoint) {
nMyRank = it->first; nMyRank = rankPair.first;
LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n", LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Found self at rank %d/%d, verifying up to %d masternodes\n",
nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS); nMyRank, nRanksTotal, (int)MAX_POSE_CONNECTIONS);
break; break;
} }
++it;
} }
// edge case: list is too short and this masternode is not enabled // edge case: list is too short and this masternode is not enabled
@ -1044,7 +1039,7 @@ void CMasternodeMan::DoFullVerificationStep(CConnman& connman)
sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr()); sort(vSortedByAddr.begin(), vSortedByAddr.end(), CompareByAddr());
it = vecMasternodeRanks.begin() + nOffset; auto it = vecMasternodeRanks.begin() + nOffset;
while(it != vecMasternodeRanks.end()) { while(it != vecMasternodeRanks.end()) {
if(it->second.IsPoSeVerified() || it->second.IsPoSeBanned()) { if(it->second.IsPoSeVerified() || it->second.IsPoSeBanned()) {
LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Already %s%s%s masternode %s address %s, skipping...\n", LogPrint("masternode", "CMasternodeMan::DoFullVerificationStep -- Already %s%s%s masternode %s address %s, skipping...\n",

View File

@ -1342,7 +1342,8 @@ bool CPrivateSendClient::CreateDenominated(const CompactTallyItem& tallyItem, bo
do { do {
std::vector<CAmount> vecStandardDenoms = CPrivateSend::GetStandardDenominations(); std::vector<CAmount> vecStandardDenoms = CPrivateSend::GetStandardDenominations();
BOOST_REVERSE_FOREACH(CAmount nDenomValue, vecStandardDenoms) { for (auto it = vecStandardDenoms.rbegin(); it != vecStandardDenoms.rend(); ++it) {
CAmount nDenomValue = *it;
if(fSkip) { if(fSkip) {
// Note: denoms are skipped if there are already DENOMS_COUNT_MAX of them // Note: denoms are skipped if there are already DENOMS_COUNT_MAX of them

View File

@ -417,8 +417,8 @@ int CPrivateSend::GetDenominationsByAmounts(const std::vector<CAmount>& vecAmoun
CScript scriptTmp = CScript(); CScript scriptTmp = CScript();
std::vector<CTxOut> vecTxOut; std::vector<CTxOut> vecTxOut;
BOOST_REVERSE_FOREACH(CAmount nAmount, vecAmount) { for (auto it = vecAmount.rbegin(); it != vecAmount.rend(); ++it) {
CTxOut txout(nAmount, scriptTmp); CTxOut txout((*it), scriptTmp);
vecTxOut.push_back(txout); vecTxOut.push_back(txout);
} }

View File

@ -73,12 +73,8 @@ void CSporkManager::ProcessSpork(CNode* pfrom, const std::string& strCommand, CD
ExecuteSpork(spork.nSporkID, spork.nValue); ExecuteSpork(spork.nSporkID, spork.nValue);
} else if (strCommand == NetMsgType::GETSPORKS) { } else if (strCommand == NetMsgType::GETSPORKS) {
for (const auto& pair : mapSporksActive) {
std::map<int, CSporkMessage>::iterator it = mapSporksActive.begin(); connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SPORK, pair.second));
while(it != mapSporksActive.end()) {
connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SPORK, it->second));
it++;
} }
} }