This PR makes a few minor clean-ups to Misbehaving()
in preparation to move it out of the cs_main lock.
There are very minor logging changes but otherwise no functional changes.
This PR makes a few minor clean-ups to Misbehaving()
in preparation to move it out of the cs_main lock.
There are very minor logging changes but otherwise no functional changes.
1064 {
1065- if (howmuch == 0)
1066- return;
1067+ assert(howmuch > 0);
1068
1069- CNodeState *state = State(pnode);
3733 state.m_should_discourage = false;
3734 } // cs_main
3735
3736 if (pnode.HasPermission(PF_NOBAN)) {
3737- // Peer has the NOBAN permission flag - log but don't disconnect
3738+ // We never disconnect or discourage peers for bad behavior if they have the NOBAN permission flag
dd9b305 whitespace linter needs appeasing (rm space at EOL)
0 // We never disconnect or discourage peers for bad behavior if they have the NOBAN permission flag
1843@@ -1848,7 +1844,7 @@ static void ProcessHeadersMessage(CNode& pfrom, CConnman& connman, ChainstateMan
1844 UpdateBlockAvailability(pfrom.GetId(), headers.back().GetHash());
1845
1846 if (nodestate->nUnconnectingHeaders % MAX_UNCONNECTING_HEADERS == 0) {
1847- Misbehaving(pfrom.GetId(), 20);
1848+ Misbehaving(pfrom.GetId(), 20, strprintf("%d unconnecting headers", nodestate->nUnconnectingHeaders));
nUnconnectingHeaders
ProcessHeadersMessage()
in net_processing.cpp and CBlockIndex* LookupBlockIndex
in validation.cpp.)
Pre-linter-appeasement ACK 2b5057de161e34 with one logging nit.
I think the last two commits touching Misbehaving()
can be squashed; the changes are light and it’s easier to review them together.
Based on review comments from Marco Falke and Jon Atack.
Misbehaving() could optionally take a debug string for printing to the
log file. Make this mandatory and always provide the string.
A couple of additional minor changes:
- remove the unnecessary forward declaration of Misbehaving()
- don't include the nodeid or newline in the passed debug message.
Misbehaving() adds these itself.
- Make const things const.
- Replace conditional return with assert.
- Don't log the peer's IP address.
- Log the name Misbehaving directly instead of relying on __func__.
1058@@ -1062,23 +1059,22 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
1059 * Increment peer's misbehavior score. If the new value >= DISCOURAGEMENT_THRESHOLD, mark the node
1060 * to be discouraged, meaning the peer might be disconnected and added to the discouragement filter.
1061 */
1062-void Misbehaving(NodeId pnode, int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1063+void Misbehaving(const NodeId pnode, const int howmuch, const std::string& message) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1064 {
1065- if (howmuch == 0)
1066- return;
1067+ assert(howmuch > 0);
I’ve verified all callers, this is is correct.
While this is true, if you assert on a const that gives the cpu regs a lot of control power, imho.
static_assert
), being that we’re always giving this parameter an integer literal :/
That may be a bit overkill, though.
And also would cause bloat in the built executable.
It’s easy enough to grep all instances of Misbehaving. We don’t need to automate everything :)
Code review ACK a8865f8b7215a975fd3dd9d97d7f791ac93ea65d.
Dunno if this breaks some existing log parser, but it’s an easy fix, unless it needs the peer IP.
Thanks for the review @promag!
Dunno if this breaks some existing log parser, but it’s an easy fix, unless it needs the peer IP.
We shouldn’t be logging the peer IP inside net processing, and the I believe the only other place we do is during the version handshake. See #19472 (review).