Skip to content

Commit f372623

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22495: p2p: refactor: tidy up PeerManagerImpl::Misbehaving(...)
8858e88 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 8858e88 rajarshimaitra: tACK bitcoin/bitcoin@8858e88 Tree-SHA512: 1d4dd5ac1d16ee9595edf4fa46e4960915a203641d74e6c33cffaba62ea71328834309a4451256fb45daf759f0cf6f4f199c46815afff6c89c0746e2ad4d4092
2 parents 7075a52 + 8858e88 commit f372623

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/net_processing.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,14 +1280,20 @@ void PeerManagerImpl::Misbehaving(const NodeId pnode, const int howmuch, const s
12801280
if (peer == nullptr) return;
12811281

12821282
LOCK(peer->m_misbehavior_mutex);
1283+
const int score_before{peer->m_misbehavior_score};
12831284
peer->m_misbehavior_score += howmuch;
1285+
const int score_now{peer->m_misbehavior_score};
1286+
12841287
const std::string message_prefixed = message.empty() ? "" : (": " + message);
1285-
if (peer->m_misbehavior_score >= DISCOURAGEMENT_THRESHOLD && peer->m_misbehavior_score - howmuch < DISCOURAGEMENT_THRESHOLD) {
1286-
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);
1288+
std::string warning;
1289+
1290+
if (score_now >= DISCOURAGEMENT_THRESHOLD && score_before < DISCOURAGEMENT_THRESHOLD) {
1291+
warning = " DISCOURAGE THRESHOLD EXCEEDED";
12871292
peer->m_should_discourage = true;
1288-
} else {
1289-
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s\n", pnode, peer->m_misbehavior_score - howmuch, peer->m_misbehavior_score, message_prefixed);
12901293
}
1294+
1295+
LogPrint(BCLog::NET, "Misbehaving: peer=%d (%d -> %d)%s%s\n",
1296+
pnode, score_before, score_now, warning, message_prefixed);
12911297
}
12921298

12931299
bool PeerManagerImpl::MaybePunishNodeForBlock(NodeId nodeid, const BlockValidationState& state,

0 commit comments

Comments
 (0)