mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 20:42:59 +01:00
Merge pull request #478 from UdjinM6/v0.12.0.x_sync_added
V0.12.0.x track hashes and update `last...` only twice per hash
This commit is contained in:
commit
0d625c888d
@ -250,6 +250,7 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
|
||||
return false;
|
||||
}
|
||||
mnodeman.mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb));
|
||||
masternodeSync.AddedMasternodeList(mnb.GetHash());
|
||||
|
||||
CMasternode* pmn = mnodeman.Find(vin);
|
||||
if(pmn == NULL)
|
||||
|
12
src/main.cpp
12
src/main.cpp
@ -4001,37 +4001,37 @@ bool static AlreadyHave(const CInv& inv)
|
||||
return mapSporks.count(inv.hash);
|
||||
case MSG_MASTERNODE_WINNER:
|
||||
if(masternodePayments.mapMasternodePayeeVotes.count(inv.hash)) {
|
||||
masternodeSync.AddedMasternodeWinner();
|
||||
masternodeSync.AddedMasternodeWinner(inv.hash);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MSG_BUDGET_VOTE:
|
||||
if(budget.mapSeenMasternodeBudgetVotes.count(inv.hash)) {
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(inv.hash);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MSG_BUDGET_PROPOSAL:
|
||||
if(budget.mapSeenMasternodeBudgetProposals.count(inv.hash)) {
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(inv.hash);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MSG_BUDGET_FINALIZED_VOTE:
|
||||
if(budget.mapSeenFinalizedBudgetVotes.count(inv.hash)) {
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(inv.hash);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MSG_BUDGET_FINALIZED:
|
||||
if(budget.mapSeenFinalizedBudgets.count(inv.hash)) {
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(inv.hash);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
case MSG_MASTERNODE_ANNOUNCE:
|
||||
if(mnodeman.mapSeenMasternodeBroadcast.count(inv.hash)) {
|
||||
masternodeSync.AddedMasternodeList();
|
||||
masternodeSync.AddedMasternodeList(inv.hash);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -830,7 +830,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
vRecv >> budgetProposalBroadcast;
|
||||
|
||||
if(mapSeenMasternodeBudgetProposals.count(budgetProposalBroadcast.GetHash())){
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -849,7 +849,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
|
||||
CBudgetProposal budgetProposal(budgetProposalBroadcast);
|
||||
if(AddProposal(budgetProposal)) {budgetProposalBroadcast.Relay();}
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash());
|
||||
|
||||
LogPrintf("mprop - new budget - %s\n", budgetProposalBroadcast.GetHash().ToString());
|
||||
|
||||
@ -863,7 +863,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
vote.fValid = true;
|
||||
|
||||
if(mapSeenMasternodeBudgetVotes.count(vote.GetHash())){
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(vote.GetHash());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -884,7 +884,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
std::string strError = "";
|
||||
if(UpdateProposal(vote, pfrom, strError)) {
|
||||
vote.Relay();
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(vote.GetHash());
|
||||
}
|
||||
|
||||
LogPrintf("mvote - new budget vote - %s\n", vote.GetHash().ToString());
|
||||
@ -895,7 +895,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
vRecv >> finalizedBudgetBroadcast;
|
||||
|
||||
if(mapSeenFinalizedBudgets.count(finalizedBudgetBroadcast.GetHash())){
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(finalizedBudgetBroadcast.GetHash());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -916,7 +916,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
|
||||
CFinalizedBudget finalizedBudget(finalizedBudgetBroadcast);
|
||||
if(AddFinalizedBudget(finalizedBudget)) {finalizedBudgetBroadcast.Relay();}
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(finalizedBudgetBroadcast.GetHash());
|
||||
|
||||
//we might have active votes for this budget that are now valid
|
||||
CheckOrphanVotes();
|
||||
@ -928,7 +928,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
vote.fValid = true;
|
||||
|
||||
if(mapSeenFinalizedBudgetVotes.count(vote.GetHash())){
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(vote.GetHash());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -948,7 +948,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
std::string strError = "";
|
||||
if(UpdateFinalizedBudget(vote, pfrom, strError)) {
|
||||
vote.Relay();
|
||||
masternodeSync.AddedBudgetItem();
|
||||
masternodeSync.AddedBudgetItem(vote.GetHash());
|
||||
}
|
||||
|
||||
LogPrint("mnbudget", "fbs - new finalized budget vote - %s\n", vote.GetHash().ToString());
|
||||
|
@ -365,7 +365,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
|
||||
|
||||
if(masternodePayments.mapMasternodePayeeVotes.count(winner.GetHash())){
|
||||
LogPrint("mnpayments", "mnw - Already seen - %s bestHeight %d\n", winner.GetHash().ToString().c_str(), chainActive.Tip()->nHeight);
|
||||
masternodeSync.AddedMasternodeWinner();
|
||||
masternodeSync.AddedMasternodeWinner(winner.GetHash());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -400,7 +400,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
|
||||
|
||||
if(masternodePayments.AddWinningMasternode(winner)){
|
||||
winner.Relay();
|
||||
masternodeSync.AddedMasternodeWinner();
|
||||
masternodeSync.AddedMasternodeWinner(winner.GetHash());
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -598,6 +598,7 @@ void CMasternodePayments::CleanPaymentList()
|
||||
|
||||
if(chainActive.Tip()->nHeight - winner.nBlockHeight > nLimit){
|
||||
LogPrint("mnpayments", "CMasternodePayments::CleanPaymentList - Removing old Masternode payment - block %d\n", winner.nBlockHeight);
|
||||
masternodeSync.mapSeenSyncMNW.erase((*it).first);
|
||||
mapMasternodePayeeVotes.erase(it++);
|
||||
} else {
|
||||
++it;
|
||||
|
@ -75,19 +75,44 @@ void CMasternodeSync::Reset()
|
||||
RequestedMasternodeAttempt = 0;
|
||||
}
|
||||
|
||||
void CMasternodeSync::AddedMasternodeList()
|
||||
void CMasternodeSync::AddedMasternodeList(uint256 hash)
|
||||
{
|
||||
lastMasternodeList = GetTime();
|
||||
if(mnodeman.mapSeenMasternodeBroadcast.count(hash)) {
|
||||
if(mapSeenSyncMNB[hash] < 2) {
|
||||
lastMasternodeList = GetTime();
|
||||
mapSeenSyncMNB[hash]++;
|
||||
}
|
||||
} else {
|
||||
lastMasternodeList = GetTime();
|
||||
mapSeenSyncMNB.insert(make_pair(hash, 1));
|
||||
}
|
||||
}
|
||||
|
||||
void CMasternodeSync::AddedMasternodeWinner()
|
||||
void CMasternodeSync::AddedMasternodeWinner(uint256 hash)
|
||||
{
|
||||
lastMasternodeWinner = GetTime();
|
||||
if(masternodePayments.mapMasternodePayeeVotes.count(hash)) {
|
||||
if(mapSeenSyncMNW[hash] < 2) {
|
||||
lastMasternodeWinner = GetTime();
|
||||
mapSeenSyncMNW[hash]++;
|
||||
}
|
||||
} else {
|
||||
lastMasternodeWinner = GetTime();
|
||||
mapSeenSyncMNW.insert(make_pair(hash, 1));
|
||||
}
|
||||
}
|
||||
|
||||
void CMasternodeSync::AddedBudgetItem()
|
||||
void CMasternodeSync::AddedBudgetItem(uint256 hash)
|
||||
{
|
||||
lastBudgetItem = GetTime();
|
||||
if(budget.mapSeenMasternodeBudgetProposals.count(hash) || budget.mapSeenMasternodeBudgetVotes.count(hash) ||
|
||||
budget.mapSeenFinalizedBudgets.count(hash) || budget.mapSeenFinalizedBudgetVotes.count(hash)) {
|
||||
if(mapSeenSyncBudget[hash] < 2) {
|
||||
lastBudgetItem = GetTime();
|
||||
mapSeenSyncBudget[hash]++;
|
||||
}
|
||||
} else {
|
||||
lastBudgetItem = GetTime();
|
||||
mapSeenSyncBudget.insert(make_pair(hash, 1));
|
||||
}
|
||||
}
|
||||
|
||||
bool CMasternodeSync::IsBudgetPropEmpty()
|
||||
@ -141,25 +166,21 @@ void CMasternodeSync::ProcessMessage(CNode* pfrom, std::string& strCommand, CDat
|
||||
{
|
||||
case(MASTERNODE_SYNC_LIST):
|
||||
if(nItemID != RequestedMasternodeAssets) return;
|
||||
if(nCount == 0) lastMasternodeList = GetTime();
|
||||
sumMasternodeList += nCount;
|
||||
countMasternodeList++;
|
||||
break;
|
||||
case(MASTERNODE_SYNC_MNW):
|
||||
if(nItemID != RequestedMasternodeAssets) return;
|
||||
if(nCount == 0) lastMasternodeWinner = GetTime();
|
||||
sumMasternodeWinner += nCount;
|
||||
countMasternodeWinner++;
|
||||
break;
|
||||
case(MASTERNODE_SYNC_BUDGET_PROP):
|
||||
if(RequestedMasternodeAssets != MASTERNODE_SYNC_BUDGET) return;
|
||||
if(nCount == 0) lastBudgetItem = GetTime();
|
||||
sumBudgetItemProp += nCount;
|
||||
countBudgetItemProp++;
|
||||
break;
|
||||
case(MASTERNODE_SYNC_BUDGET_FIN):
|
||||
if(RequestedMasternodeAssets != MASTERNODE_SYNC_BUDGET) return;
|
||||
if(nCount == 0) lastBudgetItem = GetTime();
|
||||
sumBudgetItemFin += nCount;
|
||||
countBudgetItemFin++;
|
||||
break;
|
||||
|
@ -27,6 +27,10 @@ extern CMasternodeSync masternodeSync;
|
||||
class CMasternodeSync
|
||||
{
|
||||
public:
|
||||
std::map<uint256, int> mapSeenSyncMNB;
|
||||
std::map<uint256, int> mapSeenSyncMNW;
|
||||
std::map<uint256, int> mapSeenSyncBudget;
|
||||
|
||||
int64_t lastMasternodeList;
|
||||
int64_t lastMasternodeWinner;
|
||||
int64_t lastBudgetItem;
|
||||
@ -50,9 +54,9 @@ public:
|
||||
|
||||
CMasternodeSync();
|
||||
|
||||
void AddedMasternodeList();
|
||||
void AddedMasternodeWinner();
|
||||
void AddedBudgetItem();
|
||||
void AddedMasternodeList(uint256 hash);
|
||||
void AddedMasternodeWinner(uint256 hash);
|
||||
void AddedBudgetItem(uint256 hash);
|
||||
void GetNextAsset();
|
||||
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
||||
bool IsBudgetFinEmpty();
|
||||
|
@ -390,7 +390,7 @@ bool CMasternodeBroadcast::CheckAndUpdate(int& nDos)
|
||||
pmn->UpdateFromNewBroadcast((*this));
|
||||
pmn->Check();
|
||||
if(pmn->IsEnabled()) Relay();
|
||||
masternodeSync.AddedMasternodeList();
|
||||
masternodeSync.AddedMasternodeList(GetHash());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -254,6 +254,7 @@ void CMasternodeMan::CheckAndRemove(bool forceExpiredRemoval)
|
||||
map<uint256, CMasternodeBroadcast>::iterator it3 = mapSeenMasternodeBroadcast.begin();
|
||||
while(it3 != mapSeenMasternodeBroadcast.end()){
|
||||
if((*it3).second.vin == (*it).vin){
|
||||
masternodeSync.mapSeenSyncMNB.erase((*it3).first);
|
||||
mapSeenMasternodeBroadcast.erase(it3++);
|
||||
} else {
|
||||
++it3;
|
||||
@ -644,7 +645,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
vRecv >> mnb;
|
||||
|
||||
if(mnodeman.mapSeenMasternodeBroadcast.count(mnb.GetHash())) { //seen
|
||||
masternodeSync.AddedMasternodeList();
|
||||
masternodeSync.AddedMasternodeList(mnb.GetHash());
|
||||
return;
|
||||
}
|
||||
mnodeman.mapSeenMasternodeBroadcast.insert(make_pair(mnb.GetHash(), mnb));
|
||||
@ -672,7 +673,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
|
||||
if(mnb.CheckInputsAndAdd(nDoS)) {
|
||||
// use this as a peer
|
||||
addrman.Add(CAddress(mnb.addr), pfrom->addr, 2*60*60);
|
||||
masternodeSync.AddedMasternodeList();
|
||||
masternodeSync.AddedMasternodeList(mnb.GetHash());
|
||||
} else {
|
||||
LogPrintf("mnb - Rejected Masternode entry %s\n", mnb.addr.ToString());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user