mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-08-03 04:52:50 +02:00
p2p: refactor: tidy up PeerManagerImpl::Misbehaving(...)
- introduce constant variables `score_before` and `score_after` in order to improve readability - deduplicate calls to LogPrint(), eliminates else-branch
This commit is contained in:
@@ -1280,14 +1280,20 @@ void PeerManagerImpl::Misbehaving(const NodeId pnode, const int howmuch, const s
|
||||
if (peer == nullptr) return;
|
||||
|
||||
LOCK(peer->m_misbehavior_mutex);
|
||||
const int score_before{peer->m_misbehavior_score};
|
||||
peer->m_misbehavior_score += howmuch;
|
||||
const int score_now{peer->m_misbehavior_score};
|
||||
|
||||
const std::string message_prefixed = message.empty() ? "" : (": " + message);
|
||||
if (peer->m_misbehavior_score >= DISCOURAGEMENT_THRESHOLD && peer->m_misbehavior_score - howmuch < DISCOURAGEMENT_THRESHOLD) {
|
||||
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d) DISCOURAGE THRESHOLD EXCEEDED%s\n", pnode, peer->m_misbehavior_score - howmuch, peer->m_misbehavior_score, message_prefixed);
|
||||
std::string warning;
|
||||
|
||||
if (score_now >= DISCOURAGEMENT_THRESHOLD && score_before < DISCOURAGEMENT_THRESHOLD) {
|
||||
warning = " DISCOURAGE THRESHOLD EXCEEDED";
|
||||
peer->m_should_discourage = true;
|
||||
} else {
|
||||
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s\n", pnode, peer->m_misbehavior_score - howmuch, peer->m_misbehavior_score, message_prefixed);
|
||||
}
|
||||
|
||||
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s%s\n",
|
||||
pnode, score_before, score_now, warning, message_prefixed);
|
||||
}
|
||||
|
||||
bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,
|
||||
|
Reference in New Issue
Block a user