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);
assert ?,== DoS ?
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)
// We never disconnect or discourage peers for bad behavior if they have the NOBAN permission flag
am reviewing anyway, so can wait on this until the review, if you like
Fixed
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));
2d4e694 the log message might be more clear for users if s/unconnecting/non-connecting/...yes, in the codebase it is called unconnecting...but nicely enough, anyone grepping for "non-connecting" will see this line as the only result and link it immediately to nUnconnectingHeaders
(Maybe just me, but "unconnecting" strikes me as confusing naming; it suggests disconnection when we are really talking about invalid or non-connecting header messages, unless I am misreading the code in ProcessHeadersMessage() in net_processing.cpp and CBlockIndex* LookupBlockIndex in validation.cpp.)
Agree that unconnecting sounds more like a verb than an adjective. I've changed this to non-connecting.
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__.
Code review ACK a8865f8b7215a975fd3dd9d97d7f791ac93ea65d
ACK a8865f8
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.
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.
we changed howmuch to const int , and then we assert, i saw such things optimized to regs. and the cpu is not always in your control and here we are at a net sanity check that should not be hookable.imho.
Bugs me that I can't find a way to check this at compile time (like static_assert), being that we're always giving this parameter an integer literal :/
If you make it a templated function, you can pass in howmuch as a template parameter, enabling static_asserts on it. That may be a bit overkill, though.
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).
Concept ACK.
tACK a8865f8b7215a975fd3dd9d97d7f791ac93ea65d