diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-07-12 23:53:45 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2021-07-26 15:51:14 +0200 |
commit | 8858e88c840197cdcabea07dd1380ef2aa4ece02 (patch) | |
tree | 3c669edaf7abc59a193d67a832f94c004c7c4987 /src/net_processing.cpp | |
parent | d3474b8df2f973e9b9142c0b64505a8a78bcb292 (diff) | |
download | bitcoin-8858e88c840197cdcabea07dd1380ef2aa4ece02.tar.xz |
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
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r-- | src/net_processing.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 9c4544df21..d23e546330 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -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, |