Masternode inv messages / save seen in mncache

This commit is contained in:
Evan Duffield 2015-07-25 12:07:30 -07:00
parent 43101ebeca
commit c0a5dfba61
10 changed files with 41 additions and 49 deletions

View File

@ -171,7 +171,7 @@ bool CActiveMasternode::SendMasternodePing(std::string& errorMessage) {
}
pmn->lastPing = mnp;
mapSeenMasternodePing[mnp.GetHash()] = mnp;
mnodeman.mapSeenMasternodePing[mnp.GetHash()] = mnp;
mnp.Relay();
return true;
@ -244,7 +244,7 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
return false;
}
mapSeenMasternodePing[mnp.GetHash()] = mnp;
mnodeman.mapSeenMasternodePing[mnp.GetHash()] = mnp;
LogPrintf("CActiveMasternode::Register() - Adding to Masternode list\n service: %s\n vin: %s\n", service.ToString(), vin.ToString());
mnb = CMasternodeBroadcast(service, vin, pubKeyCollateralAddress, pubKeyMasternode, PROTOCOL_VERSION);
@ -254,7 +254,7 @@ bool CActiveMasternode::Register(CTxIn vin, CService service, CKey keyCollateral
LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage);
return false;
}
mapSeenMasternodeBroadcast[mnb.GetHash()] = mnb;
mnodeman.mapSeenMasternodeBroadcast[mnb.GetHash()] = mnb;
CMasternode* pmn = mnodeman.Find(vin);
if(pmn == NULL)

View File

@ -4016,13 +4016,13 @@ bool static AlreadyHave(const CInv& inv)
}
return false;
case MSG_MASTERNODE_ANNOUNCE:
if(mapSeenMasternodeBroadcast.count(inv.hash)) {
if(mnodeman.mapSeenMasternodeBroadcast.count(inv.hash)) {
masternodeSync.AddedMasternodeList();
return true;
}
return false;
case MSG_MASTERNODE_PING:
return mapSeenMasternodePing.count(inv.hash);
return mnodeman.mapSeenMasternodePing.count(inv.hash);
}
// Don't know what it is, just say we already got one
return true;
@ -4223,20 +4223,20 @@ void static ProcessGetData(CNode* pfrom)
}
if (!pushed && inv.type == MSG_MASTERNODE_ANNOUNCE) {
if(mapSeenMasternodeBroadcast.count(inv.hash)){
if(mnodeman.mapSeenMasternodeBroadcast.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mapSeenMasternodeBroadcast[inv.hash];
ss << mnodeman.mapSeenMasternodeBroadcast[inv.hash];
pfrom->PushMessage("mnb", ss);
pushed = true;
}
}
if (!pushed && inv.type == MSG_MASTERNODE_PING) {
if(mapSeenMasternodePing.count(inv.hash)){
if(mnodeman.mapSeenMasternodePing.count(inv.hash)){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << mapSeenMasternodePing[inv.hash];
ss << mnodeman.mapSeenMasternodePing[inv.hash];
pfrom->PushMessage("mnp", ss);
pushed = true;
}

View File

@ -952,14 +952,14 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp)
CBudgetProposal* pbudgetProposal = FindProposal((*it1).first);
if(pbudgetProposal && pbudgetProposal->fValid && (nProp == 0 || (*it1).first == nProp)){
CInv inv(MSG_BUDGET_PROPOSAL, (*it1).second.GetHash());
RelayInv(inv);
pfrom->PushInventory(inv);
//send votes
std::map<uint256, CBudgetVote>::iterator it2 = pbudgetProposal->mapVotes.begin();
while(it2 != pbudgetProposal->mapVotes.end()){
if((*it2).second.fValid){
CInv inv(MSG_BUDGET_VOTE, (*it2).second.GetHash());
RelayInv(inv);
pfrom->PushInventory(inv);
}
++it2;
}
@ -972,14 +972,15 @@ void CBudgetManager::Sync(CNode* pfrom, uint256 nProp)
CFinalizedBudget* pfinalizedBudget = FindFinalizedBudget((*it3).first);
if(pfinalizedBudget && pfinalizedBudget->fValid && (nProp == 0 || (*it3).first == nProp)){
CInv inv(MSG_BUDGET_FINALIZED, (*it3).second.GetHash());
RelayInv(inv);
pfrom->PushInventory(inv);
//send votes
std::map<uint256, CFinalizedBudgetVote>::iterator it4 = pfinalizedBudget->mapVotes.begin();
while(it4 != pfinalizedBudget->mapVotes.end()){
if((*it4).second.fValid)
if((*it4).second.fValid) {
CInv inv(MSG_BUDGET_FINALIZED_VOTE, (*it4).second.GetHash());
RelayInv(inv);
pfrom->PushInventory(inv);
}
++it4;
}
}

View File

@ -763,7 +763,7 @@ void CMasternodePayments::Sync(CNode* node, int nCountNeeded)
CMasternodePaymentWinner winner = (*it).second;
if(winner.nBlockHeight >= chainActive.Tip()->nHeight-nCountNeeded && winner.nBlockHeight <= chainActive.Tip()->nHeight + 20) {
CInv inv(MSG_MASTERNODE_WINNER, winner.GetHash());
RelayInv(inv);
node->PushInventory(inv);
}
++it;
}

View File

@ -160,7 +160,7 @@ void CMasternodeSync::Process()
pnode->FulfilledRequest("mnsync");
if((lastMasternodeList == 0 || lastMasternodeList > GetTime() - MASTERNODE_SYNC_TIMEOUT)
&& RequestedMasternodeAttempt <= 2){
&& RequestedMasternodeAttempt <= 4){
mnodeman.DsegUpdate(pnode);
RequestedMasternodeAttempt++;
}

View File

@ -141,7 +141,7 @@ void CMasternode::UpdateFromNewBroadcast(CMasternodeBroadcast& mnb)
int nDoS = 0;
if(mnb.lastPing == CMasternodePing() || (mnb.lastPing != CMasternodePing() && mnb.lastPing.CheckAndUpdate(nDoS, false))) {
lastPing = mnb.lastPing;
mapSeenMasternodePing[lastPing.GetHash()] = lastPing;
mnodeman.mapSeenMasternodePing[lastPing.GetHash()] = lastPing;
}
}

View File

@ -15,12 +15,6 @@
/** Masternode manager */
CMasternodeMan mnodeman;
// Keep track of all broadcasts I've seen
map<uint256, CMasternodeBroadcast> mapSeenMasternodeBroadcast;
// Keep track of all pings I've seen
map<uint256, CMasternodePing> mapSeenMasternodePing;
struct CompareValueOnly
{
bool operator()(const pair<int64_t, CTxIn>& t1,
@ -617,11 +611,11 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CMasternodeBroadcast mnb;
vRecv >> mnb;
if(mapSeenMasternodeBroadcast.count(mnb.GetHash())) { //seen
if(mnodeman.mapSeenMasternodeBroadcast.count(mnb.GetHash())) { //seen
masternodeSync.AddedMasternodeList();
return;
}
mapSeenMasternodeBroadcast[mnb.GetHash()] = mnb;
mnodeman.mapSeenMasternodeBroadcast[mnb.GetHash()] = mnb;
int nDoS = 0;
if(!mnb.CheckAndUpdate(nDoS)){
@ -661,8 +655,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(fDebug) LogPrintf("mnp - Masternode ping, vin: %s\n", mnp.vin.ToString());
if(mapSeenMasternodePing.count(mnp.GetHash())) return; //seen
mapSeenMasternodePing[mnp.GetHash()] = mnp;
if(mnodeman.mapSeenMasternodePing.count(mnp.GetHash())) return; //seen
mnodeman.mapSeenMasternodePing[mnp.GetHash()] = mnp;
int nDoS = 0;
if(mnp.CheckAndUpdate(nDoS)) return;
@ -724,15 +718,11 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(mn.IsEnabled()) {
if(fDebug) LogPrintf("dseg - Sending Masternode entry - %s \n", mn.addr.ToString().c_str());
if(vin == CTxIn()){
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << CMasternodeBroadcast(mn);
pfrom->PushMessage("mnb", ss);
CInv inv(MSG_MASTERNODE_ANNOUNCE, CMasternodeBroadcast(mn).GetHash());
pfrom->PushInventory(inv);
} else if (vin == mn.vin) {
CDataStream ss(SER_NETWORK, PROTOCOL_VERSION);
ss.reserve(1000);
ss << CMasternodeBroadcast(mn);
pfrom->PushMessage("mnb", ss);
CInv inv(MSG_MASTERNODE_ANNOUNCE, CMasternodeBroadcast(mn).GetHash());
pfrom->PushInventory(inv);
LogPrintf("dseg - Sent 1 Masternode entries to %s\n", pfrom->addr.ToString().c_str());
return;

View File

@ -20,12 +20,6 @@ using namespace std;
class CMasternodeMan;
// Keep track of all broadcasts I've seen
extern map<uint256, CMasternodeBroadcast> mapSeenMasternodeBroadcast;
// Keep track of all pings I've seen
extern map<uint256, CMasternodePing> mapSeenMasternodePing;
extern CMasternodeMan mnodeman;
void DumpMasternodes();
@ -71,6 +65,11 @@ private:
std::map<COutPoint, int64_t> mWeAskedForMasternodeListEntry;
public:
// Keep track of all broadcasts I've seen
map<uint256, CMasternodeBroadcast> mapSeenMasternodeBroadcast;
// Keep track of all pings I've seen
map<uint256, CMasternodePing> mapSeenMasternodePing;
// keep track of dsq count to prevent masternodes from gaming darksend queue
int64_t nDsqCount;
@ -78,12 +77,15 @@ public:
template <typename Stream, typename Operation>
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
LOCK(cs);
READWRITE(vMasternodes);
READWRITE(mAskedUsForMasternodeList);
READWRITE(mWeAskedForMasternodeList);
READWRITE(mWeAskedForMasternodeListEntry);
READWRITE(nDsqCount);
LOCK(cs);
READWRITE(vMasternodes);
READWRITE(mAskedUsForMasternodeList);
READWRITE(mWeAskedForMasternodeList);
READWRITE(mWeAskedForMasternodeListEntry);
READWRITE(nDsqCount);
READWRITE(mapSeenMasternodeBroadcast);
READWRITE(mapSeenMasternodePing);
}
CMasternodeMan();

View File

@ -1799,7 +1799,6 @@ void RelayTransactionLockReq(const CTransaction& tx, bool relayToAll)
pnode->PushMessage("ix", tx);
}
}
void RelayInv(CInv &inv, const int minProtoVersion) {