aboutsummaryrefslogtreecommitdiff
path: root/test/functional/p2p_addrv2_relay.py
diff options
context:
space:
mode:
authorW. J. van der Laan <laanwj@protonmail.com>2021-07-19 12:41:59 +0200
committerW. J. van der Laan <laanwj@protonmail.com>2021-07-19 12:42:07 +0200
commitd3474b8df2f973e9b9142c0b64505a8a78bcb292 (patch)
treed047ee0c06b0d0829d6a4f7dd1e845d134617e6c /test/functional/p2p_addrv2_relay.py
parente8f85e0e86e92e583b8984455b7bf9d0a777578a (diff)
parenta4bcd687c934d47aa3922334e97e579caf5f8124 (diff)
Merge bitcoin/bitcoin#22387: Rate limit the processing of rumoured addresses
a4bcd687c934d47aa3922334e97e579caf5f8124 Improve tests using statistics (John Newbery) f424d601e1b6870e20bc60f5ccba36d2e210377b Add logging and addr rate limiting statistics (Pieter Wuille) b4ece8a1cda69cc268d39d21bba59c51fa2fb9ed Functional tests for addr rate limiting (Pieter Wuille) 5648138f5949013331c017c740646e2f4013bc24 Randomize the order of addr processing (Pieter Wuille) 0d64b8f709b4655d8702f810d4876cd8d96ded82 Rate limit the processing of incoming addr messages (Pieter Wuille) Pull request description: The rate at which IP addresses are rumoured (through ADDR and ADDRV2 messages) on the network seems to vary from 0 for some non-participating nodes, to 0.005-0.025 addr/s for recent Bitcoin Core nodes. However, the current codebase will happily accept and process an effectively unbounded rate from attackers. There are measures to limit the influence attackers can have on the addrman database (bucket restrictions based on source IPs), but still - there is no need to permit them to feed us addresses at a rate that's orders of magnitude larger than what is common on the network today, especially as it will cause us to spam our peers too. This PR implements a [token bucket](https://en.wikipedia.org/wiki/Token_bucket) based rate limiter, allowing an average of 0.1 addr/s per connection, with bursts up to 1000 addresses at once. Whitelisted peers as well as responses to GETADDR requests are exempt from the limit. New connections start with 1 token, so as to not interfere with the common practice of peers' self-announcement. ACKs for top commit: laanwj: ACK a4bcd687c934d47aa3922334e97e579caf5f8124 vasild: ACK a4bcd687c934d47aa3922334e97e579caf5f8124 jnewbery: ACK a4bcd687c934d47aa3922334e97e579caf5f8124 jonatack: ACK a4bcd687c934d47aa3922334e97e579caf5f8124 Tree-SHA512: b757de76ad78a53035b622944c4213b29b3b55d3d98bf23585afa84bfba10808299d858649f92269a16abfa75eb4366ea047eae3216f7e2f6d3c455782a16bea
Diffstat (limited to 'test/functional/p2p_addrv2_relay.py')
-rwxr-xr-xtest/functional/p2p_addrv2_relay.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/test/functional/p2p_addrv2_relay.py b/test/functional/p2p_addrv2_relay.py
index c006a6c24f..32c1d42b1c 100755
--- a/test/functional/p2p_addrv2_relay.py
+++ b/test/functional/p2p_addrv2_relay.py
@@ -42,7 +42,9 @@ class AddrReceiver(P2PInterface):
super().__init__(support_addrv2 = True)
def on_addrv2(self, message):
- if ADDRS == message.addrs:
+ expected_set = set((addr.ip, addr.port) for addr in ADDRS)
+ received_set = set((addr.ip, addr.port) for addr in message.addrs)
+ if expected_set == received_set:
self.addrv2_received_and_checked = True
def wait_for_addrv2(self):
@@ -53,6 +55,7 @@ class AddrTest(BitcoinTestFramework):
def set_test_params(self):
self.setup_clean_chain = True
self.num_nodes = 1
+ self.extra_args = [["-whitelist=addr@127.0.0.1"]]
def run_test(self):
self.log.info('Create connection that sends addrv2 messages')