aboutsummaryrefslogtreecommitdiff
path: root/src/net_processing.cpp
diff options
context:
space:
mode:
authorMarcoFalke <falke.marco@gmail.com>2021-07-27 11:26:35 +0200
committerMarcoFalke <falke.marco@gmail.com>2021-07-27 11:26:39 +0200
commitf372623807c538bf8d2a5710d9939e1ae39f9a74 (patch)
tree073de0ee49e199067ab813f3df96ca47a57ced33 /src/net_processing.cpp
parent7075a52b67dc09c47142d987dcd089cc74bdcce6 (diff)
parent8858e88c840197cdcabea07dd1380ef2aa4ece02 (diff)
downloadbitcoin-f372623807c538bf8d2a5710d9939e1ae39f9a74.tar.xz
Merge bitcoin/bitcoin#22495: p2p: refactor: tidy up `PeerManagerImpl::Misbehaving(...)`
8858e88c840197cdcabea07dd1380ef2aa4ece02 p2p: refactor: tidy up `PeerManagerImpl::Misbehaving(...)` (Sebastian Falbesoner) Pull request description: This simple refactoring PR has the goal to improve the readability of the `Misbehaving` method by - introducing constant variables `score_before` and `score_now` (to avoid repeatedly calculating the former) - deduplicating calls to LogPrint(), eliminates else-branch ACKs for top commit: jnewbery: utACK 8858e88c840197cdcabea07dd1380ef2aa4ece02 rajarshimaitra: tACK https://github.com/bitcoin/bitcoin/pull/22495/commits/8858e88c840197cdcabea07dd1380ef2aa4ece02 Tree-SHA512: 1d4dd5ac1d16ee9595edf4fa46e4960915a203641d74e6c33cffaba62ea71328834309a4451256fb45daf759f0cf6f4f199c46815afff6c89c0746e2ad4d4092
Diffstat (limited to 'src/net_processing.cpp')
-rw-r--r--src/net_processing.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/net_processing.cpp b/src/net_processing.cpp
index a0c346b99f..70eac468f3 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,