Skip to content

Commit 1b4ef1d

Browse files
author
evan82
committed
Merge pull request #591 from UdjinM6/fix_inv
inv messages vectors should not be pushed directly
2 parents 2c14877 + ef9b90a commit 1b4ef1d

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

src/masternode-budget.cpp

+14-16
Original file line numberDiff line numberDiff line change
@@ -1144,22 +1144,22 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)
11441144
11451145
*/
11461146

1147-
vector<CInv> vInv;
1147+
int nInvCount = 0;
11481148

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

11561156
//send votes
11571157
std::map<uint256, CBudgetVote>::iterator it2 = pbudgetProposal->mapVotes.begin();
11581158
while(it2 != pbudgetProposal->mapVotes.end()){
11591159
if((*it2).second.fValid){
11601160
if((fPartial && !(*it2).second.fSynced) || !fPartial) {
1161-
CInv inv(MSG_BUDGET_VOTE, (*it2).second.GetHash());
1162-
vInv.push_back(inv);
1161+
pfrom->PushInventory(CInv(MSG_BUDGET_VOTE, (*it2).second.GetHash()));
1162+
nInvCount++;
11631163
}
11641164
}
11651165
++it2;
@@ -1168,27 +1168,26 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)
11681168
++it1;
11691169
}
11701170

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

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

1176-
vInv.clear();
1175+
nInvCount = 0;
11771176

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

11851184
//send votes
11861185
std::map<uint256, CFinalizedBudgetVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
11871186
while(it4 != pfinalizedBudget->mapVotes.end()){
11881187
if((*it4).second.fValid) {
11891188
if((fPartial && !(*it4).second.fSynced) || !fPartial) {
1190-
CInv inv(MSG_BUDGET_FINALIZED_VOTE, (*it4).second.GetHash());
1191-
vInv.push_back(inv);
1189+
pfrom->PushInventory(CInv(MSG_BUDGET_FINALIZED_VOTE, (*it4).second.GetHash()));
1190+
nInvCount++;
11921191
}
11931192
}
11941193
++it4;
@@ -1197,9 +1196,8 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp, bool fPartial)
11971196
++it3;
11981197
}
11991198

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

12041202
}
12051203

src/masternode-payments.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -782,18 +782,17 @@ void CMasternodePayments::Sync(CNode* node, int nCountNeeded)
782782
int nCount = (mnodeman.CountEnabled()*2);
783783
if(nCountNeeded > nCount) nCountNeeded = nCount;
784784

785-
vector<CInv> vInv;
785+
int nInvCount = 0;
786786
std::map<uint256, CMasternodePaymentWinner>::iterator it = mapMasternodePayeeVotes.begin();
787787
while(it != mapMasternodePayeeVotes.end()) {
788788
CMasternodePaymentWinner winner = (*it).second;
789789
if(winner.nBlockHeight >= chainActive.Tip()->nHeight-nCountNeeded && winner.nBlockHeight <= chainActive.Tip()->nHeight + 20) {
790-
CInv inv(MSG_MASTERNODE_WINNER, winner.GetHash());
791-
vInv.push_back(inv);
790+
node->PushInventory(CInv(MSG_MASTERNODE_WINNER, winner.GetHash()));
791+
nInvCount++;
792792
}
793793
++it;
794794
}
795-
node->PushMessage("ssc", MASTERNODE_SYNC_MNW, (int)vInv.size());
796-
if(vInv.size() > 0) node->PushMessage("inv", vInv);
795+
node->PushMessage("ssc", MASTERNODE_SYNC_MNW, nInvCount);
797796
}
798797

799798
std::string CMasternodePayments::ToString() const

src/masternodeman.cpp

+9-10
Original file line numberDiff line numberDiff line change
@@ -771,8 +771,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
771771
} //else, asking for a specific node which is ok
772772

773773

774-
std::vector<CInv> vInv;
775-
int i = 0;
774+
int nInvCount = 0;
775+
776776
BOOST_FOREACH(CMasternode& mn, vMasternodes) {
777777
if(mn.addr.IsRFC1918()) continue; //local network
778778

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

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

789789
if(vin == mn.vin) {
790790
LogPrintf("dseg - Sent 1 Masternode entries to %s\n", pfrom->addr.ToString());
791-
break;
791+
return;
792792
}
793793
}
794-
i++;
795794
}
796795
}
797796

798-
if(vin == CTxIn()) pfrom->PushMessage("ssc", MASTERNODE_SYNC_LIST, (int)vInv.size());
799-
if(vInv.size() > 0) pfrom->PushMessage("inv", vInv);
800-
801-
if(vin == CTxIn()) LogPrintf("dseg - Sent %d Masternode entries to %s\n", i, pfrom->addr.ToString());
797+
if(vin == CTxIn()) {
798+
pfrom->PushMessage("ssc", MASTERNODE_SYNC_LIST, nInvCount);
799+
LogPrintf("dseg - Sent %d Masternode entries to %s\n", nInvCount, pfrom->addr.ToString());
800+
}
802801
}
803802
/*
804803
* IT'S SAFE TO REMOVE THIS IN FURTHER VERSIONS

0 commit comments

Comments
 (0)