Commit a893d2b
committed
p2p: avoid false-positives in addr rate-limiting
On some occasions, a peer will send us addresses a few seconds after
the connection is established. As peers start with token=1 and only
get an additional token only every 10 seconds, some of these
addresses might be rate-limited. The following log snippet contains
an example:
```
04:12:02 [net] Added connection to [redacted] peer=1234
...
04:12:03 [net] Received addr: 1 addresses (1 processed, 0 rate-limited) from peer=1234
04:12:34 [net] Received addr: 4 addresses (3 processed, 1 rate-limited) from peer=1234
04:13:09 [net] Received addr: 2 addresses (2 processed, 0 rate-limited) from peer=1234
```
The peer starts with token=1 and uses one for its self-announcement at
04:12:03. Until the next addr message arrives at 04:12:34, it re-gains
3 tokens and uses them, however, the fourth address in this addr
message is rate-limited. At 04:13:09, the peer has token=3 and uses 2.
This change gives peers token=5 to start with. To choose this value, I
looked at the address relay of freshly connected peers. The data was
sampled from the debug.logs from different nodes. It appears, that only
very few peers require more than 5 initial tokens.
(see image in PR)
By increasing the initial tokens to 5, someone could connect, send 5
addresses, disconnect, and repeat to spam the node with addresses.
Previously, the same was possible but only one address was processed.
I don't think this is a problem since we have bitcoin#30568.1 parent 161864a commit a893d2b
2 files changed
+5
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
376 | | - | |
377 | | - | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
378 | 378 | | |
379 | 379 | | |
380 | 380 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| |||
0 commit comments