Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jun 9, 2022

Currently this is treated as misbehaviour with a score of 20 (out of 100). Practically, on my node no peer that hit a score of 20 hit the threshold of 100, so it seems fine to skip.

Effectively, large "vector" messages will be dropped, making them a bandwidth DoS if sent repeatedly. However, any peer can do a bandwidth DoS by sending a "vector" messages of smaller size, or messages of type notfound (which don't have any misbehaviour score for size), or a large block or tx message.

This change skips over a headers, getdata, inv, addr, and addrv2 message if it is too large.

For reference, there is no BIP that prescribes behaviour on oversized messages of those types. BIP 155 is the only BIP that mentions a size limit about the message types:

One message can contain up to 1,000 addresses. Clients SHOULD reject messages with more addresses.
https://en.bitcoin.it/wiki/BIP_0155#Specification

For reference, getblocks and getheaders since commit e254ff5 will unconditionally disconnect on size. It will even disconnect noban peers and manual connections, but this seems fine to keep.

@fanquake fanquake added the P2P label Jun 9, 2022
@maflcko
Copy link
Member Author

maflcko commented Jun 9, 2022

Data on a node:

  • This is only hit once per connection, going from score 0 to 20.
$ grep ' message size = ' ~/.bitcoin/debug.log 
2020-12-28T17:20:47Z [msghand] Misbehaving: peer=380051 (0 -> 20): headers message size = 48166
2021-01-04T17:58:47Z [msghand] Misbehaving: peer=567963 (0 -> 20): headers message size = 37000
2021-03-18T20:00:39Z [msghand] Misbehaving: peer=2442599 (0 -> 20): headers message size = 29794
2021-03-18T21:55:05Z [msghand] Misbehaving: peer=2445041 (0 -> 20): headers message size = 40538
2021-03-23T09:05:43Z [msghand] Misbehaving: peer=2563428 (0 -> 20): headers message size = 43132
2021-04-25T10:54:19Z [msghand] Misbehaving: peer=3388661 (0 -> 20): addrv2 message size = 1998
2021-05-08T14:39:59Z [msghand] Misbehaving: peer=3713735 (0 -> 20): headers message size = 30507
2021-05-23T21:06:54Z [msghand] Misbehaving: peer=4092238 (0 -> 20): headers message size = 41553
2021-06-12T01:44:57Z [msghand] Misbehaving: peer=4525871 (0 -> 20): headers message size = 2309
  • This is only hit on peers that have a bogus UA (except for the addrv2 violation, which was a debug version of Bitcoin Core)
$ grep 'receive version message' ~/.bitcoin/debug.log | grep --extended-regex '\<(380051|567963|2442599|2445041|2563428|3388661|3713735|4092238|4525871)\>' 
2020-12-28T17:20:23Z [msghand] receive version message: : version 50001, blocks=187250, us=34.82.170.246:8333, peer=380051
2021-01-04T17:58:42Z [msghand] receive version message: /Satoshi:0.6.0.6/: version 60000, blocks=36914, us=34.82.170.246:8333, peer=567963
2021-03-18T20:00:35Z [msghand] receive version message: : version 32400, blocks=180700, us=34.82.170.246:8333, peer=2442599
2021-03-18T21:54:28Z [msghand] receive version message: /Satoshi:0.6.0.6/: version 60000, blocks=191436, us=34.82.170.246:8333, peer=2445041
2021-03-23T09:05:42Z [msghand] receive version message: : version 32100, blocks=194744, us=34.82.170.246:8333, peer=2563428
2021-04-25T10:47:48Z [msghand] receive version message: /Satoshi:21.99.0/: version 70016, blocks=680547, us=34.82.170.246:43860, peer=3388661
2021-05-08T14:38:27Z [msghand] receive version message: : version 32400, blocks=188779, us=34.82.170.246:8333, peer=3713735
2021-05-23T21:06:32Z [msghand] receive version message: : version 32400, blocks=201925, us=34.82.170.246:8333, peer=4092238
2021-06-12T01:44:56Z [msghand] receive version message: : version 32400, blocks=165237, us=34.82.170.246:8333, peer=4525871
  • The peers got disconnected anyway
2020-12-28T17:28:29Z [net] socket closed for peer=380051
2020-12-28T17:28:29Z [net] disconnecting peer=380051
2020-12-28T17:28:29Z [net] Cleared nodestate for peer=380051

2021-01-04T18:03:18Z [net] socket closed for peer=567963
2021-01-04T18:03:18Z [net] disconnecting peer=567963
2021-01-04T18:03:18Z [net] Cleared nodestate for peer=567963

2021-03-18T20:12:52Z [net] socket recv error for peer=2442599: Connection reset by peer (104)
2021-03-18T20:12:52Z [net] disconnecting peer=2442599
2021-03-18T20:12:52Z [net] Cleared nodestate for peer=2442599

2021-03-18T21:58:23Z [net] socket recv error for peer=2445041: Connection reset by peer (104)
2021-03-18T21:58:23Z [net] disconnecting peer=2445041
2021-03-18T21:58:23Z [net] Cleared nodestate for peer=2445041

2021-03-23T09:25:00Z [net] socket recv error for peer=2563428: Connection reset by peer (104)
2021-03-23T09:25:00Z [net] disconnecting peer=2563428
2021-03-23T09:25:00Z [net] Cleared nodestate for peer=2563428

2021-04-26T00:12:56Z [net] ping timeout: 1207.998686s
2021-04-26T00:12:56Z [net] disconnecting peer=3388661
2021-04-26T00:13:07Z [net] Cleared nodestate for peer=3388661

2021-05-08T16:08:04Z [net] socket recv error for peer=3713735: Connection reset by peer (104)
2021-05-08T16:08:04Z [net] disconnecting peer=3713735
2021-05-08T16:08:04Z [net] Cleared nodestate for peer=3713735

2021-05-24T00:12:31Z [net] socket recv error for peer=4092238: Connection reset by peer (104)
2021-05-24T00:12:31Z [net] disconnecting peer=4092238
2021-05-24T00:12:31Z [net] Cleared nodestate for peer=4092238

2021-06-12T02:12:09Z [net] socket recv error for peer=4525871: Connection timed out (110)
2021-06-12T02:12:09Z [net] disconnecting peer=4525871
2021-06-12T02:12:09Z [net] Cleared nodestate for peer=4525871

@maflcko maflcko force-pushed the 2206-less-mis- branch 2 times, most recently from fa373d3 to fac0bb6 Compare June 9, 2022 15:10
@DrahtBot
Copy link
Contributor

DrahtBot commented Jun 9, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

No conflicts as of last run.

@@ -2997,9 +2997,8 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
return;
}

if (vAddr.size() > MAX_ADDR_TO_SEND)
{
Misbehaving(pfrom.GetId(), 20, strprintf("%s message size = %u", msg_type, vAddr.size()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did the Misbehaving was replaced by LogPrint ? I took a look at Misbehaving and saw that it calls the LogPrint inside of itself. So it seems to be a logging function with some other stuff. Would explain the difference between LogPrint and Misbehaving?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is explained in the pull request description. Practically, I couldn't find a difference between Misbehaving and LogPrint on one of my nodes. In theory there is a difference, but I explain why it shouldn't matter. (The difference is that Misbehaving may disconnect and discourage the peer, unless it is a manual or noban connection).

Copy link
Contributor

Choose a reason for hiding this comment

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

Thank you, @MarcoFalke I'm new to bitcoin source code and have lots of questions, posting my basic questions as comment on PRs good way to ask my questions? Or there are better places? such as IRC or bitcoin-talk? I'm aware that this question has nothing to do with the PR but I couldn't find a way to send direct message to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

You can also ask on the dev IRC (https://github.com/bitcoin/bitcoin/blob/master/CONTRIBUTING.md#communication-channels), the review IRC (https://bitcoincore.reviews/), or on Bitcoin StackExchange.

@sdaftuar
Copy link
Member

I think it would be helpful to have more context and understanding of how to think about peer selection and eviction in order to review making changes to these peer misbehavior scores. I agree that what we have is arbitrary and not consistent, but I also think that we could go in two different directions here -- to either be more or less permissive -- and it's not obvious to me which is better.

The DoS reasoning you provide, which is that large messages of these types are no worse than large notfound messages, seems pretty convincing to me that we should not bother assigning DoS-points to inbound peers that send us these messages. But if an outbound peer is sending us messages like this, then perhaps we do want to disconnect and find another outbound peer? I wonder if it might make sense to differentiate behavior based on inbound/outbound-ness?

Really though I don't have a strong feeling either way about this change; it's probably not harmful, so if people think this is a good change I don't object in principle, but hard for me to say what approach makes the most sense.

@maflcko maflcko closed this Jul 5, 2022
@maflcko maflcko deleted the 2206-less-mis-🔈 branch July 5, 2022 16:19
@bitcoin bitcoin locked and limited conversation to collaborators Jul 5, 2023
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.

5 participants