pack of small cleanup fixes / optimizations (#2334)
* remove vector, extra loop in cleanup function This commit removes 2 loops and a vector which I don't believe are necessary in CMasternode::FlagGovernanceItemsAsDirty. I could be missing something, but can't think of any good reason why this was implemented this way. * use range operator to range over vectors * remove deprecated wire message types * mn: simplify govobj map mgmt a bit * remove extra semicolons * invert if/else condition and drop else * remove if/else logic from Qt This is the entire purpose of the Get<X>String methods on MNP class. * Revert "remove deprecated wire message types" This reverts commit 9de88a3fda999555c00cb829d60e322b2fd3800d. * Revert "remove if/else logic from Qt" This reverts commit c0f43c9b85274b13a3ac9625775817bc5b53bb9d.
This commit is contained in:
parent
9603c52900
commit
89f744d064
@ -270,9 +270,8 @@ void CGovernanceManager::CheckOrphanVotes(CGovernanceObject& govobj, CGovernance
|
|||||||
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
ScopedLockBool guard(cs, fRateChecksEnabled, false);
|
||||||
|
|
||||||
int64_t nNow = GetAdjustedTime();
|
int64_t nNow = GetAdjustedTime();
|
||||||
for (size_t i = 0; i < vecVotePairs.size(); ++i) {
|
for (auto& pairVote : vecVotePairs) {
|
||||||
bool fRemove = false;
|
bool fRemove = false;
|
||||||
vote_time_pair_t& pairVote = vecVotePairs[i];
|
|
||||||
CGovernanceVote& vote = pairVote.first;
|
CGovernanceVote& vote = pairVote.first;
|
||||||
CGovernanceException exception;
|
CGovernanceException exception;
|
||||||
if (pairVote.second < nNow) {
|
if (pairVote.second < nNow) {
|
||||||
@ -368,8 +367,8 @@ void CGovernanceManager::UpdateCachesAndClean()
|
|||||||
|
|
||||||
LOCK2(cs_main, cs);
|
LOCK2(cs_main, cs);
|
||||||
|
|
||||||
for (size_t i = 0; i < vecDirtyHashes.size(); ++i) {
|
for (const uint256& nHash : vecDirtyHashes) {
|
||||||
object_m_it it = mapObjects.find(vecDirtyHashes[i]);
|
object_m_it it = mapObjects.find(nHash);
|
||||||
if (it == mapObjects.end()) {
|
if (it == mapObjects.end()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -1018,8 +1017,8 @@ void CGovernanceManager::RequestGovernanceObject(CNode* pfrom, const uint256& nH
|
|||||||
filter = CBloomFilter(Params().GetConsensus().nGovernanceFilterElements, GOVERNANCE_FILTER_FP_RATE, GetRandInt(999999), BLOOM_UPDATE_ALL);
|
filter = CBloomFilter(Params().GetConsensus().nGovernanceFilterElements, GOVERNANCE_FILTER_FP_RATE, GetRandInt(999999), BLOOM_UPDATE_ALL);
|
||||||
std::vector<CGovernanceVote> vecVotes = pObj->GetVoteFile().GetVotes();
|
std::vector<CGovernanceVote> vecVotes = pObj->GetVoteFile().GetVotes();
|
||||||
nVoteCount = vecVotes.size();
|
nVoteCount = vecVotes.size();
|
||||||
for (size_t i = 0; i < vecVotes.size(); ++i) {
|
for (const auto& vote : vecVotes) {
|
||||||
filter.insert(vecVotes[i].GetHash());
|
filter.insert(vote.GetHash());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1296,8 +1295,7 @@ void CGovernanceManager::RequestOrphanObjects(CConnman& connman)
|
|||||||
std::vector<uint256> vecHashes;
|
std::vector<uint256> vecHashes;
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
cmmapOrphanVotes.GetKeys(vecHashes);
|
cmmapOrphanVotes.GetKeys(vecHashes);
|
||||||
for (size_t i = 0; i < vecHashes.size(); ++i) {
|
for (const uint256& nHash : vecHashes) {
|
||||||
const uint256& nHash = vecHashes[i];
|
|
||||||
if (mapObjects.find(nHash) == mapObjects.end()) {
|
if (mapObjects.find(nHash) == mapObjects.end()) {
|
||||||
vecHashesFiltered.push_back(nHash);
|
vecHashesFiltered.push_back(nHash);
|
||||||
}
|
}
|
||||||
@ -1305,10 +1303,8 @@ void CGovernanceManager::RequestOrphanObjects(CConnman& connman)
|
|||||||
}
|
}
|
||||||
|
|
||||||
LogPrint("gobject", "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashesFiltered.size());
|
LogPrint("gobject", "CGovernanceObject::RequestOrphanObjects -- number objects = %d\n", vecHashesFiltered.size());
|
||||||
for (size_t i = 0; i < vecHashesFiltered.size(); ++i) {
|
for (const uint256& nHash : vecHashesFiltered) {
|
||||||
const uint256& nHash = vecHashesFiltered[i];
|
for (CNode* pnode : vNodesCopy) {
|
||||||
for (size_t j = 0; j < vNodesCopy.size(); ++j) {
|
|
||||||
CNode* pnode = vNodesCopy[j];
|
|
||||||
if (pnode->fMasternode) {
|
if (pnode->fMasternode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -993,20 +993,16 @@ std::string CMasternodePing::GetDaemonString() const
|
|||||||
|
|
||||||
void CMasternode::AddGovernanceVote(uint256 nGovernanceObjectHash)
|
void CMasternode::AddGovernanceVote(uint256 nGovernanceObjectHash)
|
||||||
{
|
{
|
||||||
if(mapGovernanceObjectsVotedOn.count(nGovernanceObjectHash)) {
|
// Insert a zero value, or not. Then increment the value regardless. This
|
||||||
mapGovernanceObjectsVotedOn[nGovernanceObjectHash]++;
|
// ensures the value is in the map.
|
||||||
} else {
|
const auto& pair = mapGovernanceObjectsVotedOn.emplace(nGovernanceObjectHash, 0);
|
||||||
mapGovernanceObjectsVotedOn.insert(std::make_pair(nGovernanceObjectHash, 1));
|
pair.first->second++;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CMasternode::RemoveGovernanceObject(uint256 nGovernanceObjectHash)
|
void CMasternode::RemoveGovernanceObject(uint256 nGovernanceObjectHash)
|
||||||
{
|
{
|
||||||
std::map<uint256, int>::iterator it = mapGovernanceObjectsVotedOn.find(nGovernanceObjectHash);
|
// Whether or not the govobj hash exists in the map first is irrelevant.
|
||||||
if(it == mapGovernanceObjectsVotedOn.end()) {
|
mapGovernanceObjectsVotedOn.erase(nGovernanceObjectHash);
|
||||||
return;
|
|
||||||
}
|
|
||||||
mapGovernanceObjectsVotedOn.erase(it);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1017,15 +1013,7 @@ void CMasternode::RemoveGovernanceObject(uint256 nGovernanceObjectHash)
|
|||||||
*/
|
*/
|
||||||
void CMasternode::FlagGovernanceItemsAsDirty()
|
void CMasternode::FlagGovernanceItemsAsDirty()
|
||||||
{
|
{
|
||||||
std::vector<uint256> vecDirty;
|
for (auto& govObjHashPair : mapGovernanceObjectsVotedOn) {
|
||||||
{
|
mnodeman.AddDirtyGovernanceObjectHash(govObjHashPair.first);
|
||||||
std::map<uint256, int>::iterator it = mapGovernanceObjectsVotedOn.begin();
|
|
||||||
while(it != mapGovernanceObjectsVotedOn.end()) {
|
|
||||||
vecDirty.push_back(it->first);
|
|
||||||
++it;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for(size_t i = 0; i < vecDirty.size(); ++i) {
|
|
||||||
mnodeman.AddDirtyGovernanceObjectHash(vecDirty[i]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -226,7 +226,7 @@ public:
|
|||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
std::vector<uint256> vecTmp = vecDirtyGovernanceObjectHashes;
|
std::vector<uint256> vecTmp = vecDirtyGovernanceObjectHashes;
|
||||||
vecDirtyGovernanceObjectHashes.clear();
|
vecDirtyGovernanceObjectHashes.clear();
|
||||||
return vecTmp;;
|
return vecTmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool IsSentinelPingActive();
|
bool IsSentinelPingActive();
|
||||||
|
@ -305,7 +305,7 @@ std::string CPrivateSendClientSession::GetStatus(bool fWaitForBlock)
|
|||||||
if( nStatusMessageProgress % 70 <= 30) strSuffix = ".";
|
if( nStatusMessageProgress % 70 <= 30) strSuffix = ".";
|
||||||
else if(nStatusMessageProgress % 70 <= 50) strSuffix = "..";
|
else if(nStatusMessageProgress % 70 <= 50) strSuffix = "..";
|
||||||
else if(nStatusMessageProgress % 70 <= 70) strSuffix = "...";
|
else if(nStatusMessageProgress % 70 <= 70) strSuffix = "...";
|
||||||
return strprintf(_("Submitted to masternode, waiting in queue %s"), strSuffix);;
|
return strprintf(_("Submitted to masternode, waiting in queue %s"), strSuffix);
|
||||||
case POOL_STATE_ACCEPTING_ENTRIES:
|
case POOL_STATE_ACCEPTING_ENTRIES:
|
||||||
if(nEntriesCount == 0) {
|
if(nEntriesCount == 0) {
|
||||||
nStatusMessageProgress = 0;
|
nStatusMessageProgress = 0;
|
||||||
|
@ -474,10 +474,7 @@ void MasternodeList::ShowQRCode(std::string strAlias) {
|
|||||||
bool fFound = false;
|
bool fFound = false;
|
||||||
|
|
||||||
for (const auto& mne : masternodeConfig.getEntries()) {
|
for (const auto& mne : masternodeConfig.getEntries()) {
|
||||||
if (strAlias != mne.getAlias()) {
|
if (strAlias == mne.getAlias()) {
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
strMNPrivKey = mne.getPrivKey();
|
strMNPrivKey = mne.getPrivKey();
|
||||||
strCollateral = mne.getTxHash() + "-" + mne.getOutputIndex();
|
strCollateral = mne.getTxHash() + "-" + mne.getOutputIndex();
|
||||||
strIP = mne.getIp();
|
strIP = mne.getIp();
|
||||||
|
Loading…
Reference in New Issue
Block a user