Skip to content

Conversation

TheBlueMatt
Copy link
Contributor

Based on #11580 because I'm lazy.

We should generally avoid writing to debug.log unconditionally for
inbound peers which misbehave (the peer being about to be banned
being an exception, since they cannot do this twice).

@fanquake fanquake added the P2P label Oct 30, 2017
@practicalswift
Copy link
Contributor

Concept ACK

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK.

@@ -1514,7 +1511,9 @@ bool static ProcessMessage(CNode* pfrom, const std::string& strCommand, CDataStr
if (nVersion < MIN_PEER_PROTO_VERSION)
{
// disconnect from peers older than this proto version
LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion);
std::string obsolete_msg(strprintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion));
if (pfrom->fInbound) LogPrint(BCLog::NET, "%s", obsolete_log);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

obsolete_msg or above obsolete_log?

LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion);
std::string obsolete_msg(strprintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion));
if (pfrom->fInbound) LogPrint(BCLog::NET, "%s", obsolete_log);
else LogPrintf( "%s", obsolete_log);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK dba516034898cd390a07edf86af3e9ff9f52c911. I didn't try to verify there were no missing logprints, but these changes seem reasonable.

I think it would be good to add your "We should generally avoid writing to debug.log unconditionally..." comment from the commit message to the LogFlags enum, so there is a little information about good logging practices and how the enum values are supposed to be used.

@meshcollider
Copy link
Contributor

Concept ACK

@laanwj
Copy link
Member

laanwj commented Nov 9, 2017

"We should generally avoid writing to debug.log unconditionally"

Yes please. Loose logging practices just cause scared users.

Concept ACK.

LogPrintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion);
std::string obsolete_log(strprintf("peer=%d using obsolete version %i; disconnecting\n", pfrom->GetId(), nVersion));
if (pfrom->fInbound) LogPrint(BCLog::NET, "%s", obsolete_log);
else LogPrintf( "%s", obsolete_log);
Copy link
Member

@laanwj laanwj Nov 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would prefer to create a BCLog::ALWAYS category and use something like pfrom->fInbound ? BCLog::NET: BCLog::ALWAYS instead of repeating the log statements in this way.
(after that you could even factor it to a uint32_t log_category = ...` at the beginning of the function ProcessMessage)

@TheBlueMatt
Copy link
Contributor Author

After discussion on IRC I removed the weird branching on fInbound to decide between LogPrint and LogPrintf...added a new "New outbound peer connected" log to ::VERACK handling to replace it. Also added a general comment in util.h about LogPrint/LogPrintf usage.

@ghost
Copy link

ghost commented Nov 9, 2017

What about the debug.log message "connection from <Peer> dropped (banned)"?
I banned the nodes in gmaxwells banlist.cli.txt, and some of them aggressively try to connect permanently every few seconds after being banned, e.g. this one (this is a original cutout of the debug.log, the messages are exactly like this (except the x-anonymization), I did not remove other log entries in between)

2017-11-x 15:55:34 connection from 129.13.252.x:36133 dropped (banned)
2017-11-x 15:55:39 connection from 129.13.252.x:36225 dropped (banned)
2017-11-x 15:55:43 connection from 129.13.252.x:36363 dropped (banned)
2017-11-x 15:55:47 connection from 129.13.252.x:36474 dropped (banned)
2017-11-x 15:55:50 connection from 129.13.252.x:36579 dropped (banned)
2017-11-x 15:55:53 connection from 129.13.252.x:36673 dropped (banned)
2017-11-x 15:55:56 connection from 129.13.252.x:36780 dropped (banned)
2017-11-x 15:56:00 connection from 129.13.252.x:36888 dropped (banned)
2017-11-x 15:56:03 connection from 129.13.252.x:36989 dropped (banned)
2017-11-x 15:56:07 connection from 129.13.252.x:37108 dropped (banned)
2017-11-x 15:56:10 connection from 129.13.252.x:37210 dropped (banned)
2017-11-x 15:56:13 connection from 129.13.252.x:37307 dropped (banned)
2017-11-x 15:56:17 connection from 129.13.252.x:37409 dropped (banned)
2017-11-x 15:56:20 connection from 129.13.252.x:37516 dropped (banned)
2017-11-x 15:56:23 connection from 129.13.252.x:37612 dropped (banned)
2017-11-x 15:56:27 connection from 129.13.252.x:37712 dropped (banned)
2017-11-x 15:56:30 connection from 129.13.252.x:37814 dropped (banned)

Because this permanently spammed the debug.log, I added iptables rules to drop these silently on OS layer :-/

Edit: running 0.15.1rc1

We should generally avoid writing to debug.log unconditionally for
inbound peers which misbehave (the peer being about to be banned
being an exception, since they cannot do this twice).

To avoid removing logs for outbound peers, a new log is added to
notify users when a new outbound peer is connected which mimics
the version print.
@TheBlueMatt
Copy link
Contributor Author

Added the banned listing to the list as well (thanks!)...I'm sure there's others that are missed that can be triggered in validation logic, but I'll leave those for a future PR.

@greenaddress
Copy link

Concept ACK.

@laanwj
Copy link
Member

laanwj commented Dec 11, 2017

utACK be9f38c

@laanwj laanwj merged commit be9f38c into bitcoin:master Dec 11, 2017
laanwj added a commit that referenced this pull request Dec 11, 2017
…g entries

be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Based on #11580 because I'm lazy.

  We should generally avoid writing to debug.log unconditionally for
  inbound peers which misbehave (the peer being about to be banned
  being an exception, since they cannot do this twice).

Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
laanwj added a commit to laanwj/bitcoin that referenced this pull request Jan 24, 2018
This moves the error messages for misbehavior (when available) into the
line that reports the misbehavior, as well as moves the logging to the
`net` category.

This is a continuation of bitcoin#11583 and avoids serious-looking errors due
to misbehaving peers.

To do this, Misbehaving() gains an optional `message` argument.

E.g. change:

    2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED
    2018-01-18 16:02:27 ERROR: non-continuous headers sequence

to

    2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED: non-continuous headers sequence
clemtaylor added a commit to clemtaylor/bitcoin that referenced this pull request Feb 3, 2018
…non-contributing peers (port scanners?)

37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..."
laanwj added a commit that referenced this pull request Feb 6, 2018
…ssage

c887f87 Extend #11583 to include the most common message generated by non-contributing peers (port scanners?) 37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..." (Clem Taylor)

Pull request description:

  37% of the default log entries for a node that has been up for ~24hrs was "version handshake timeout..."

Tree-SHA512: dceeee5d55a9ff7570174aeb63faac9beda239087220522adefef7ed11e0eeffa008ca28726011247c8834c1a222d37817baf895635ab874a95ebc435959070e
laanwj added a commit that referenced this pull request Feb 6, 2018
d3a185a net: Move misbehaving logging to net logging category (Wladimir J. van der Laan)

Pull request description:

  This moves the error messages for misbehavior (when available) into the line that reports the misbehavior, as well as moves the logging to the `net` category.

  This is a continuation of #11583 and avoids serious-looking errors due to misbehaving peers. As it is impossible to correlate the `peer=X` numbers to specific incoming connections now without enabling the `net` category, it doesn't really help to see these messages by default.

  To do this, Misbehaving() gains an optional `message` argument.

  E.g. change:

      2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED
      2018-01-18 16:02:27 ERROR: non-continuous headers sequence

  to

      2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED: non-continuous headers sequence

  When there is a category for "important" net messages (see #12219 ), we should move it there.

Tree-SHA512: 51c97e9a649bf5409f2fd4625fa1243a036e9c9de6037bb064244207408c2e0eb025e3af80866df673cdc006b8f35dc4078d074033f0d4c6a73bbb03949a269f
hkjn pushed a commit to hkjn/bitcoin that referenced this pull request Feb 12, 2018
This moves the error messages for misbehavior (when available) into the
line that reports the misbehavior, as well as moves the logging to the
`net` category.

This is a continuation of bitcoin#11583 and avoids serious-looking errors due
to misbehaving peers.

To do this, Misbehaving() gains an optional `message` argument.

E.g. change:

    2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED
    2018-01-18 16:02:27 ERROR: non-continuous headers sequence

to

    2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED: non-continuous headers sequence
hkjn pushed a commit to hkjn/bitcoin that referenced this pull request Feb 12, 2018
…non-contributing peers (port scanners?)

37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..."
HashUnlimited pushed a commit to HashUnlimited/chaincoin that referenced this pull request Jul 31, 2018
…non-contributing peers (port scanners?)

37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..."
HashUnlimited pushed a commit to HashUnlimited/chaincoin that referenced this pull request Jul 31, 2018
This moves the error messages for misbehavior (when available) into the
line that reports the misbehavior, as well as moves the logging to the
`net` category.

This is a continuation of bitcoin#11583 and avoids serious-looking errors due
to misbehaving peers.

To do this, Misbehaving() gains an optional `message` argument.

E.g. change:

    2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED
    2018-01-18 16:02:27 ERROR: non-continuous headers sequence

to

    2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED: non-continuous headers sequence
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jan 20, 2019
Summary:
bitcoin/bitcoin#11583

We should generally avoid writing to debug.log unconditionally for
inbound peers which misbehave (the peer being about to be banned
being an exception, since they cannot do this twice).

To avoid removing logs for outbound peers, a new log is added to
notify users when a new outbound peer is connected which mimics
the version print.

This is a backport of Core PR11583

Test Plan: CI

Reviewers: #bitcoin_abc, deadalnix, Fabien

Reviewed By: #bitcoin_abc, deadalnix, Fabien

Subscribers: Fabien, teamcity, schancel

Differential Revision: https://reviews.bitcoinabc.org/D2323
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 26, 2020
…rate log entries

be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Based on bitcoin#11580 because I'm lazy.

  We should generally avoid writing to debug.log unconditionally for
  inbound peers which misbehave (the peer being about to be banned
  being an exception, since they cannot do this twice).

Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 26, 2020
…egory

d3a185a net: Move misbehaving logging to net logging category (Wladimir J. van der Laan)

Pull request description:

  This moves the error messages for misbehavior (when available) into the line that reports the misbehavior, as well as moves the logging to the `net` category.

  This is a continuation of bitcoin#11583 and avoids serious-looking errors due to misbehaving peers. As it is impossible to correlate the `peer=X` numbers to specific incoming connections now without enabling the `net` category, it doesn't really help to see these messages by default.

  To do this, Misbehaving() gains an optional `message` argument.

  E.g. change:

      2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED
      2018-01-18 16:02:27 ERROR: non-continuous headers sequence

  to

      2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED: non-continuous headers sequence

  When there is a category for "important" net messages (see bitcoin#12219 ), we should move it there.

Tree-SHA512: 51c97e9a649bf5409f2fd4625fa1243a036e9c9de6037bb064244207408c2e0eb025e3af80866df673cdc006b8f35dc4078d074033f0d4c6a73bbb03949a269f
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 26, 2020
…ke timeout" message

c887f87 Extend bitcoin#11583 to include the most common message generated by non-contributing peers (port scanners?) 37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..." (Clem Taylor)

Pull request description:

  37% of the default log entries for a node that has been up for ~24hrs was "version handshake timeout..."

Tree-SHA512: dceeee5d55a9ff7570174aeb63faac9beda239087220522adefef7ed11e0eeffa008ca28726011247c8834c1a222d37817baf895635ab874a95ebc435959070e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 26, 2020
…ke timeout" message

c887f87 Extend bitcoin#11583 to include the most common message generated by non-contributing peers (port scanners?) 37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..." (Clem Taylor)

Pull request description:

  37% of the default log entries for a node that has been up for ~24hrs was "version handshake timeout..."

Tree-SHA512: dceeee5d55a9ff7570174aeb63faac9beda239087220522adefef7ed11e0eeffa008ca28726011247c8834c1a222d37817baf895635ab874a95ebc435959070e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 26, 2020
…ke timeout" message

c887f87 Extend bitcoin#11583 to include the most common message generated by non-contributing peers (port scanners?) 37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..." (Clem Taylor)

Pull request description:

  37% of the default log entries for a node that has been up for ~24hrs was "version handshake timeout..."

Tree-SHA512: dceeee5d55a9ff7570174aeb63faac9beda239087220522adefef7ed11e0eeffa008ca28726011247c8834c1a222d37817baf895635ab874a95ebc435959070e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 27, 2020
…ke timeout" message

c887f87 Extend bitcoin#11583 to include the most common message generated by non-contributing peers (port scanners?) 37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..." (Clem Taylor)

Pull request description:

  37% of the default log entries for a node that has been up for ~24hrs was "version handshake timeout..."

Tree-SHA512: dceeee5d55a9ff7570174aeb63faac9beda239087220522adefef7ed11e0eeffa008ca28726011247c8834c1a222d37817baf895635ab874a95ebc435959070e
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 27, 2020
…egory

d3a185a net: Move misbehaving logging to net logging category (Wladimir J. van der Laan)

Pull request description:

  This moves the error messages for misbehavior (when available) into the line that reports the misbehavior, as well as moves the logging to the `net` category.

  This is a continuation of bitcoin#11583 and avoids serious-looking errors due to misbehaving peers. As it is impossible to correlate the `peer=X` numbers to specific incoming connections now without enabling the `net` category, it doesn't really help to see these messages by default.

  To do this, Misbehaving() gains an optional `message` argument.

  E.g. change:

      2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED
      2018-01-18 16:02:27 ERROR: non-continuous headers sequence

  to

      2018-01-18 16:02:27 Misbehaving: x.x.x.x:62174 peer=164603 (80 -> 100) BAN THRESHOLD EXCEEDED: non-continuous headers sequence

  When there is a category for "important" net messages (see bitcoin#12219 ), we should move it there.

Tree-SHA512: 51c97e9a649bf5409f2fd4625fa1243a036e9c9de6037bb064244207408c2e0eb025e3af80866df673cdc006b8f35dc4078d074033f0d4c6a73bbb03949a269f
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jan 27, 2020
…ke timeout" message

c887f87 Extend bitcoin#11583 to include the most common message generated by non-contributing peers (port scanners?) 37% of the log default log entries for a node that has been up for ~24hrs was "version handshake timeout..." (Clem Taylor)

Pull request description:

  37% of the default log entries for a node that has been up for ~24hrs was "version handshake timeout..."

Tree-SHA512: dceeee5d55a9ff7570174aeb63faac9beda239087220522adefef7ed11e0eeffa008ca28726011247c8834c1a222d37817baf895635ab874a95ebc435959070e
random-zebra added a commit to PIVX-Project/PIVX that referenced this pull request Jan 13, 2021
… to generate log entries

4801464 Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Adapted from bitcoin#11583, following the same rationale:

  We have to be much more conservative when using LogPrintf/error or other things which unconditionally log to debug.log, It should not be the case that an inbound peer can fill up a users disk with debug.log entries (DoS).

  This rule should be applied in many other areas of the sources as well (not only on the net area). But well, step by step.

ACKs for top commit:
  random-zebra:
    utACK 4801464
  Fuzzbawls:
    utACK 4801464

Tree-SHA512: 746bdb46f286d34a0bd109b3f4d278f714ce3140c34c897ccfbe948b8c56eb7e04e91b004a9ff9e60e56c312dfc4f47d31a1f77c5e8f0f71310c3e77f5d47460
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Jun 30, 2021
…rate log entries

be9f38c Do not make it trivial for inbound peers to generate log entries (Matt Corallo)

Pull request description:

  Based on bitcoin#11580 because I'm lazy.

  We should generally avoid writing to debug.log unconditionally for
  inbound peers which misbehave (the peer being about to be banned
  being an exception, since they cannot do this twice).

Tree-SHA512: 8e59c8d08d00b1527951b30f4842d010a4c2fc440503ade112baa2c1b9afd0e0d1c5c2df83dde25183a242af45089cf9b9f873b71796771232ffb6c5fc6cc0cc
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants