ask for mn / lower ban score for mnw

This commit is contained in:
UdjinM6 2015-08-07 06:07:40 +03:00
parent 6fdefceb24
commit f57c470f95
7 changed files with 48 additions and 29 deletions

View File

@ -138,7 +138,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
mapTxLockVote.insert(make_pair(ctx.GetHash(), ctx));
if(ProcessConsensusVote(ctx)){
if(ProcessConsensusVote(pfrom, ctx)){
//Spam/Dos protection
/*
Masternodes will sometimes propagate votes before the transaction is known to the client.
@ -297,7 +297,7 @@ void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight)
}
//received a consensus vote
bool ProcessConsensusVote(CConsensusVote& ctx)
bool ProcessConsensusVote(CNode* pnode, CConsensusVote& ctx)
{
int n = mnodeman.GetMasternodeRank(ctx.vinMasternode, ctx.nBlockHeight, MIN_INSTANTX_PROTO_VERSION);
@ -309,6 +309,7 @@ bool ProcessConsensusVote(CConsensusVote& ctx)
{
//can be caused by past versions trying to vote with an invalid protocol
LogPrint("instantx", "InstantX::ProcessConsensusVote - Unknown Masternode\n");
mnodeman.AskForMN(pnode, ctx.vinMasternode);
return false;
}
@ -320,7 +321,8 @@ bool ProcessConsensusVote(CConsensusVote& ctx)
if(!ctx.SignatureValid()) {
LogPrintf("InstantX::ProcessConsensusVote - Signature invalid\n");
//don't ban, it could just be a non-synced masternode
// don't ban, it could just be a non-synced masternode
mnodeman.AskForMN(pnode, ctx.vinMasternode);
return false;
}

View File

@ -55,7 +55,7 @@ void ProcessMessageInstantX(CNode* pfrom, std::string& strCommand, CDataStream&
void DoConsensusVote(CTransaction& tx, int64_t nBlockHeight);
//process consensus vote message
bool ProcessConsensusVote(CConsensusVote& ctx);
bool ProcessConsensusVote(CNode *pnode, CConsensusVote& ctx);
// keep transaction locks in memory for an hour
void CleanTransactionLocksList();

View File

@ -926,6 +926,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CMasternode* pmn = mnodeman.Find(vote.vin);
if(pmn == NULL) {
LogPrint("mnbudget", "mvote - unknown masternode - vin: %s\n", vote.vin.ToString());
mnodeman.AskForMN(pfrom, vote.vin);
return;
}
@ -934,6 +935,8 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(!vote.SignatureValid(true)){
LogPrintf("mvote - signature invalid\n");
Misbehaving(pfrom->GetId(), 20);
// it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, vote.vin);
return;
}
@ -994,6 +997,7 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
CMasternode* pmn = mnodeman.Find(vote.vin);
if(pmn == NULL) {
LogPrint("mnbudget", "fbvote - unknown masternode - vin: %s\n", vote.vin.ToString());
mnodeman.AskForMN(pfrom, vote.vin);
return;
}
@ -1001,6 +1005,8 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(!vote.SignatureValid(true)){
LogPrintf("fbvote - signature invalid\n");
Misbehaving(pfrom->GetId(), 20);
// it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, vote.vin);
return;
}

View File

@ -376,7 +376,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
}
std::string strError = "";
if(!winner.IsValid(strError)){
if(!winner.IsValid(pfrom, strError)){
LogPrintf("mnw - invalid message - %s\n", strError);
return;
}
@ -388,7 +388,9 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
if(!winner.SignatureValid()){
LogPrintf("mnw - invalid signature\n");
Misbehaving(pfrom->GetId(), 100);
Misbehaving(pfrom->GetId(), 20);
// it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, winner.vinMasternode);
return;
}
@ -616,7 +618,7 @@ bool IsReferenceNode(CTxIn& vin)
return false;
}
bool CMasternodePaymentWinner::IsValid(std::string& strError)
bool CMasternodePaymentWinner::IsValid(CNode* pnode, std::string& strError)
{
if(IsReferenceNode(vinMasternode)) return true;
@ -626,6 +628,7 @@ bool CMasternodePaymentWinner::IsValid(std::string& strError)
{
strError = strprintf("Unknown Masternode %s", vinMasternode.prevout.ToStringShort());
LogPrintf ("CMasternodePaymentWinner::IsValid - %s\n", strError);
mnodeman.AskForMN(pnode, vinMasternode);
return false;
}

View File

@ -183,7 +183,7 @@ public:
}
bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode);
bool IsValid(std::string& strError);
bool IsValid(CNode* pnode, std::string& strError);
bool SignatureValid();
void Relay();

View File

@ -224,6 +224,23 @@ bool CMasternodeMan::Add(CMasternode &mn)
return false;
}
void CMasternodeMan::AskForMN(CNode* pnode, CTxIn &vin)
{
std::map<COutPoint, int64_t>::iterator i = mWeAskedForMasternodeListEntry.find(vin.prevout);
if (i != mWeAskedForMasternodeListEntry.end())
{
int64_t t = (*i).second;
if (GetTime() < t) return; // we've asked recently
}
// ask for the mnb info once from the node that sent mnp
LogPrintf("CMasternodeMan::AskForMN - Asking node for missing entry, vin: %s\n", vin.ToString());
pnode->PushMessage("dseg", vin);
int64_t askAgain = GetTime() + MASTERNODE_MIN_MNP_SECONDS;
mWeAskedForMasternodeListEntry[vin.prevout] = askAgain;
}
void CMasternodeMan::Check()
{
LOCK(cs);
@ -691,30 +708,18 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if(mnp.CheckAndUpdate(nDoS)) return;
if(nDoS > 0) {
// if anything significant failed, mark that node and return
// if anything significant failed, mark that node
Misbehaving(pfrom->GetId(), nDoS);
return;
} else {
// if nothing significant failed, search existing Masternode list
CMasternode* pmn = mnodeman.Find(mnp.vin);
// if it's known, don't ask for the mnb, just return
if(pmn != NULL) return;
}
//search existing Masternode list, if it's known -- don't ask for the mnb
CMasternode* pmn = mnodeman.Find(mnp.vin);
if(pmn != NULL) return;
// we wasn't able to accept mnp but nothing significant happened,
// we might just have to ask for a masternode entry once
std::map<COutPoint, int64_t>::iterator i = mWeAskedForMasternodeListEntry.find(mnp.vin.prevout);
if (i != mWeAskedForMasternodeListEntry.end())
{
int64_t t = (*i).second;
if (GetTime() < t) return; // we've asked recently
}
// ask for the mnb info once from the node that sent mnp
LogPrintf("mnp - Asking source node for missing entry, vin: %s\n", mnp.vin.ToString());
pfrom->PushMessage("dseg", mnp.vin);
int64_t askAgain = GetTime() + MASTERNODE_MIN_MNP_SECONDS;
mWeAskedForMasternodeListEntry[mnp.vin.prevout] = askAgain;
// something significant is broken or mn is unknown,
// we might have to ask for a masternode entry once
AskForMN(pfrom, mnp.vin);
} else if (strCommand == "dseg") { //Get Masternode list or specific entry

View File

@ -94,6 +94,9 @@ public:
/// Add an entry
bool Add(CMasternode &mn);
/// Ask (source) node for mnb
void AskForMN(CNode *pnode, CTxIn &vin);
/// Check all Masternodes
void Check();