mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 18:53:23 -03:00
Merge bitcoin/bitcoin#22495: p2p: refactor: tidy up PeerManagerImpl::Misbehaving(...)
8858e88c84
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: utACK8858e88c84
rajarshimaitra: tACK8858e88c84
Tree-SHA512: 1d4dd5ac1d16ee9595edf4fa46e4960915a203641d74e6c33cffaba62ea71328834309a4451256fb45daf759f0cf6f4f199c46815afff6c89c0746e2ad4d4092
This commit is contained in:
commit
f372623807
1 changed files with 10 additions and 4 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Reference in a new issue