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

inv messages vectors should not be pushed directly #591

Merged
merged 1 commit into from
Aug 31, 2015
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
30 changes: 14 additions & 16 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1144,22 +1144,22 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)

*/

vector<CInv> vInv;
int nInvCount = 0;

std::map<uint256, CBudgetProposalBroadcast>::iterator it1 = mapSeenMasternodeBudgetProposals.begin();
while(it1 != mapSeenMasternodeBudgetProposals.end()){
CBudgetProposal* pbudgetProposal = FindProposal((*it1).first);
if(pbudgetProposal && pbudgetProposal->fValid && (nProp == 0 || (*it1).first == nProp)){
CInv inv(MSG_BUDGET_PROPOSAL, (*it1).second.GetHash());
vInv.push_back(inv);
pfrom->PushInventory(CInv(MSG_BUDGET_PROPOSAL, (*it1).second.GetHash()));
nInvCount++;

//send votes
std::map<uint256, CBudgetVote>::iterator it2 = pbudgetProposal->mapVotes.begin();
while(it2 != pbudgetProposal->mapVotes.end()){
if((*it2).second.fValid){
if((fPartial && !(*it2).second.fSynced) || !fPartial) {
CInv inv(MSG_BUDGET_VOTE, (*it2).second.GetHash());
vInv.push_back(inv);
pfrom->PushInventory(CInv(MSG_BUDGET_VOTE, (*it2).second.GetHash()));
nInvCount++;
}
}
++it2;
Expand All @@ -1168,27 +1168,26 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)
++it1;
}

pfrom->PushMessage("ssc", MASTERNODE_SYNC_BUDGET_PROP, (int)vInv.size());
if(vInv.size() > 0) pfrom->PushMessage("inv", vInv);
pfrom->PushMessage("ssc", MASTERNODE_SYNC_BUDGET_PROP, nInvCount);

LogPrintf("CBudgetManager::Sync - sent %d items\n", (int)vInv.size());
LogPrintf("CBudgetManager::Sync - sent %d items\n", nInvCount);

vInv.clear();
nInvCount = 0;

std::map<uint256, CFinalizedBudgetBroadcast>::iterator it3 = mapSeenFinalizedBudgets.begin();
while(it3 != mapSeenFinalizedBudgets.end()){
CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first);
if(pfinalizedBudget && pfinalizedBudget->fValid && (nProp == 0 || (*it3).first == nProp)){
CInv inv(MSG_BUDGET_FINALIZED, (*it3).second.GetHash());
vInv.push_back(inv);
pfrom->PushInventory(CInv(MSG_BUDGET_FINALIZED, (*it3).second.GetHash()));
nInvCount++;

//send votes
std::map<uint256, CFinalizedBudgetVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
while(it4 != pfinalizedBudget->mapVotes.end()){
if((*it4).second.fValid) {
if((fPartial && !(*it4).second.fSynced) || !fPartial) {
CInv inv(MSG_BUDGET_FINALIZED_VOTE, (*it4).second.GetHash());
vInv.push_back(inv);
pfrom->PushInventory(CInv(MSG_BUDGET_FINALIZED_VOTE, (*it4).second.GetHash()));
nInvCount++;
}
}
++it4;
Expand All @@ -1197,9 +1196,8 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)
++it3;
}

pfrom->PushMessage("ssc", MASTERNODE_SYNC_BUDGET_FIN, (int)vInv.size());
if(vInv.size() > 0) pfrom->PushMessage("inv", vInv);
LogPrintf("CBudgetManager::Sync - sent %d items\n", (int)vInv.size());
pfrom->PushMessage("ssc", MASTERNODE_SYNC_BUDGET_FIN, nInvCount);
LogPrintf("CBudgetManager::Sync - sent %d items\n", nInvCount);

}

Expand Down
9 changes: 4 additions & 5 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,18 +782,17 @@ void CMasternodePayments::Sync(CNode* node, int nCountNeeded)
int nCount = (mnodeman.CountEnabled()*2);
if(nCountNeeded > nCount) nCountNeeded = nCount;

vector<CInv> vInv;
int nInvCount = 0;
std::map<uint256, CMasternodePaymentWinner>::iterator it = mapMasternodePayeeVotes.begin();
while(it != mapMasternodePayeeVotes.end()) {
CMasternodePaymentWinner winner = (*it).second;
if(winner.nBlockHeight >= chainActive.Tip()->nHeight-nCountNeeded && winner.nBlockHeight <= chainActive.Tip()->nHeight + 20) {
CInv inv(MSG_MASTERNODE_WINNER, winner.GetHash());
vInv.push_back(inv);
node->PushInventory(CInv(MSG_MASTERNODE_WINNER, winner.GetHash()));
nInvCount++;
}
++it;
}
node->PushMessage("ssc", MASTERNODE_SYNC_MNW, (int)vInv.size());
if(vInv.size() > 0) node->PushMessage("inv", vInv);
node->PushMessage("ssc", MASTERNODE_SYNC_MNW, nInvCount);
}

std::string CMasternodePayments::ToString() const
Expand Down
19 changes: 9 additions & 10 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -771,8 +771,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
} //else, asking for a specific node which is ok


std::vector<CInv> vInv;
int i = 0;
int nInvCount = 0;

BOOST_FOREACH(CMasternode& mn, vMasternodes) {
if(mn.addr.IsRFC1918()) continue; //local network

Expand All @@ -781,24 +781,23 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(vin == CTxIn() || vin == mn.vin){
CMasternodeBroadcast mnb = CMasternodeBroadcast(mn);
uint256 hash = mnb.GetHash();
CInv inv(MSG_MASTERNODE_ANNOUNCE, hash);
vInv.push_back(inv);
pfrom->PushInventory(CInv(MSG_MASTERNODE_ANNOUNCE, hash));
nInvCount++;

if(!mapSeenMasternodeBroadcast.count(hash)) mapSeenMasternodeBroadcast.insert(make_pair(hash, mnb));

if(vin == mn.vin) {
LogPrintf("dseg - Sent 1 Masternode entries to %s\n", pfrom->addr.ToString());
break;
return;
}
}
i++;
}
}

if(vin == CTxIn()) pfrom->PushMessage("ssc", MASTERNODE_SYNC_LIST, (int)vInv.size());
if(vInv.size() > 0) pfrom->PushMessage("inv", vInv);

if(vin == CTxIn()) LogPrintf("dseg - Sent %d Masternode entries to %s\n", i, pfrom->addr.ToString());
if(vin == CTxIn()) {
pfrom->PushMessage("ssc", MASTERNODE_SYNC_LIST, nInvCount);
LogPrintf("dseg - Sent %d Masternode entries to %s\n", nInvCount, pfrom->addr.ToString());
}
}
/*
* IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS
Expand Down