Skip to content

Commit

Permalink
[Output] Properly log reason(s) for increasing a peer's DoS score.
Browse files Browse the repository at this point in the history
Many of the MN related DoS checks had their log messages output only if
the client was running in debug mode, leading to unexplained peer bans.
  • Loading branch information
Fuzzbawls committed May 23, 2018
1 parent 9985266 commit fe14f5f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
12 changes: 8 additions & 4 deletions src/masternode-budget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,10 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData

mapSeenMasternodeBudgetVotes.insert(make_pair(vote.GetHash(), vote));
if (!vote.SignatureValid(true)) {
LogPrint("mnbudget","mvote - signature invalid\n");
if (masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20);
if (masternodeSync.IsSynced()) {
LogPrintf("CBudgetManager::ProcessMessage() : mvote - signature invalid\n");
Misbehaving(pfrom->GetId(), 20);
}
// it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, vote.vin);
return;
Expand Down Expand Up @@ -1219,8 +1221,10 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData

mapSeenFinalizedBudgetVotes.insert(make_pair(vote.GetHash(), vote));
if (!vote.SignatureValid(true)) {
LogPrint("mnbudget","fbvote - signature invalid\n");
if (masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20);
if (masternodeSync.IsSynced()) {
LogPrintf("CBudgetManager::ProcessMessage() : fbvote - signature invalid\n");
Misbehaving(pfrom->GetId(), 20);
}
// it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, vote.vin);
return;
Expand Down
8 changes: 5 additions & 3 deletions src/masternode-payments.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st

if (Params().NetworkID() == CBaseChainParams::MAIN) {
if (pfrom->HasFulfilledRequest("mnget")) {
LogPrint("masternode","mnget - peer already asked me for the list\n");
LogPrintf("CMasternodePayments::ProcessMessageMasternodePayments() : mnget - peer already asked me for the list\n");
Misbehaving(pfrom->GetId(), 20);
return;
}
Expand Down Expand Up @@ -413,8 +413,10 @@ void CMasternodePayments::ProcessMessageMasternodePayments(CNode* pfrom, std::st
}

if (!winner.SignatureValid()) {
// LogPrint("masternode","mnw - invalid signature\n");
if (masternodeSync.IsSynced()) Misbehaving(pfrom->GetId(), 20);
if (masternodeSync.IsSynced()) {
LogPrintf("CMasternodePayments::ProcessMessageMasternodePayments() : mnw - invalid signature\n");
Misbehaving(pfrom->GetId(), 20);
}
// it could just be a non-synced masternode
mnodeman.AskForMN(pfrom, winner.vinMasternode);
return;
Expand Down
24 changes: 12 additions & 12 deletions src/masternodeman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
// make sure the vout that was signed is related to the transaction that spawned the Masternode
// - this is expensive, so it's only done once per Masternode
if (!obfuScationSigner.IsVinAssociatedWithPubkey(mnb.vin, mnb.pubKeyCollateralAddress)) {
LogPrint("masternode","mnb - Got mismatched pubkey and vin\n");
LogPrintf("CMasternodeMan::ProcessMessage() : mnb - Got mismatched pubkey and vin\n");
Misbehaving(pfrom->GetId(), 33);
return;
}
Expand Down Expand Up @@ -810,8 +810,8 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
if (i != mAskedUsForMasternodeList.end()) {
int64_t t = (*i).second;
if (GetTime() < t) {
LogPrintf("CMasternodeMan::ProcessMessage() : dseg - peer already asked me for the list\n");
Misbehaving(pfrom->GetId(), 34);
LogPrint("masternode","dseg - peer already asked me for the list\n");
return;
}
}
Expand Down Expand Up @@ -877,7 +877,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData

// make sure signature isn't in the future (past is OK)
if (sigTime > GetAdjustedTime() + 60 * 60) {
LogPrint("masternode","dsee - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString());
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString());
Misbehaving(pfrom->GetId(), 1);
return;
}
Expand All @@ -888,7 +888,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion) + donationAddress.ToString() + boost::lexical_cast<std::string>(donationPercentage);

if (protocolVersion < masternodePayments.GetMinMasternodePaymentsProto()) {
LogPrint("masternode","dsee - ignoring outdated Masternode %s protocol version %d < %d\n", vin.prevout.hash.ToString(), protocolVersion, masternodePayments.GetMinMasternodePaymentsProto());
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - ignoring outdated Masternode %s protocol version %d < %d\n", vin.prevout.hash.ToString(), protocolVersion, masternodePayments.GetMinMasternodePaymentsProto());
Misbehaving(pfrom->GetId(), 1);
return;
}
Expand All @@ -897,7 +897,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
pubkeyScript = GetScriptForDestination(pubkey.GetID());

if (pubkeyScript.size() != 25) {
LogPrint("masternode","dsee - pubkey the wrong size\n");
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - pubkey the wrong size\n");
Misbehaving(pfrom->GetId(), 100);
return;
}
Expand All @@ -906,20 +906,20 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
pubkeyScript2 = GetScriptForDestination(pubkey2.GetID());

if (pubkeyScript2.size() != 25) {
LogPrint("masternode","dsee - pubkey2 the wrong size\n");
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - pubkey2 the wrong size\n");
Misbehaving(pfrom->GetId(), 100);
return;
}

if (!vin.scriptSig.empty()) {
LogPrint("masternode","dsee - Ignore Not Empty ScriptSig %s\n", vin.prevout.hash.ToString());
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Ignore Not Empty ScriptSig %s\n", vin.prevout.hash.ToString());
Misbehaving(pfrom->GetId(), 100);
return;
}

std::string errorMessage = "";
if (!obfuScationSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)) {
LogPrint("masternode","dsee - Got bad Masternode address signature\n");
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Got bad Masternode address signature\n");
Misbehaving(pfrom->GetId(), 100);
return;
}
Expand Down Expand Up @@ -973,7 +973,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
// make sure the vout that was signed is related to the transaction that spawned the Masternode
// - this is expensive, so it's only done once per Masternode
if (!obfuScationSigner.IsVinAssociatedWithPubkey(vin, pubkey)) {
LogPrint("masternode","dsee - Got mismatched pubkey and vin\n");
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Got mismatched pubkey and vin\n");
Misbehaving(pfrom->GetId(), 100);
return;
}
Expand All @@ -999,7 +999,7 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData

if (fAcceptable) {
if (GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS) {
LogPrint("masternode","dsee - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS);
LogPrintf("CMasternodeMan::ProcessMessage() : dsee - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS);
Misbehaving(pfrom->GetId(), 20);
return;
}
Expand Down Expand Up @@ -1073,13 +1073,13 @@ void CMasternodeMan::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
//LogPrint("masternode","dseep - Received: vin: %s sigTime: %lld stop: %s\n", vin.ToString().c_str(), sigTime, stop ? "true" : "false");

if (sigTime > GetAdjustedTime() + 60 * 60) {
LogPrint("masternode","dseep - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString());
LogPrintf("CMasternodeMan::ProcessMessage() : dseep - Signature rejected, too far into the future %s\n", vin.prevout.hash.ToString());
Misbehaving(pfrom->GetId(), 1);
return;
}

if (sigTime <= GetAdjustedTime() - 60 * 60) {
LogPrint("masternode","dseep - Signature rejected, too far into the past %s - %d %d \n", vin.prevout.hash.ToString(), sigTime, GetAdjustedTime());
LogPrintf("CMasternodeMan::ProcessMessage() : dseep - Signature rejected, too far into the past %s - %d %d \n", vin.prevout.hash.ToString(), sigTime, GetAdjustedTime());
Misbehaving(pfrom->GetId(), 1);
return;
}
Expand Down

0 comments on commit fe14f5f

Please sign in to comment.