diff options
author | Jon Atack <jon@atack.com> | 2021-02-20 17:17:26 +0100 |
---|---|---|
committer | Jon Atack <jon@atack.com> | 2021-03-19 20:13:04 +0100 |
commit | caa21f586f951d626a67f391050c3644f1057f57 (patch) | |
tree | 22f586682a41742f4d39b6194981b5ae6bec4257 /src/test/net_peer_eviction_tests.cpp | |
parent | 8f1a53eb027727a4c0eaac6d82f0a8279549f638 (diff) | |
download | bitcoin-caa21f586f951d626a67f391050c3644f1057f57.tar.xz |
Protect onion+localhost peers in ProtectEvictionCandidatesByRatio()
Now that we have a reliable way to detect inbound onion peers, this commit
updates our existing eviction protection of 1/4 localhost peers to instead
protect up to 1/4 onion peers (connected via our tor control service), sorted by
longest uptime. Any remaining slots of the 1/4 are then allocated to protect
localhost peers, or 2 localhost peers if no slots remain and 2 or more onion
peers are protected, sorted by longest uptime.
The goal is to avoid penalizing onion peers, due to their higher min ping times
relative to IPv4 and IPv6 peers, and improve our diversity of peer connections.
Thank you to Gregory Maxwell, Suhas Daftuar, Vasil Dimov and Pieter Wuille
for valuable review feedback that shaped the direction.
Diffstat (limited to 'src/test/net_peer_eviction_tests.cpp')
-rw-r--r-- | src/test/net_peer_eviction_tests.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/test/net_peer_eviction_tests.cpp b/src/test/net_peer_eviction_tests.cpp index 517474bad4..0bd0aefcee 100644 --- a/src/test/net_peer_eviction_tests.cpp +++ b/src/test/net_peer_eviction_tests.cpp @@ -94,7 +94,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test) BOOST_CHECK(IsProtected( num_peers, [](NodeEvictionCandidate& c) { c.nTimeConnected = c.id; - c.m_is_local = false; + c.m_is_onion = c.m_is_local = false; }, /* protected_peer_ids */ {0, 1, 2, 3, 4, 5}, /* unprotected_peer_ids */ {6, 7, 8, 9, 10, 11}, @@ -104,7 +104,7 @@ BOOST_AUTO_TEST_CASE(peer_protection_test) BOOST_CHECK(IsProtected( num_peers, [num_peers](NodeEvictionCandidate& c) { c.nTimeConnected = num_peers - c.id; - c.m_is_local = false; + c.m_is_onion = c.m_is_local = false; }, /* protected_peer_ids */ {6, 7, 8, 9, 10, 11}, /* unprotected_peer_ids */ {0, 1, 2, 3, 4, 5}, @@ -113,20 +113,22 @@ BOOST_AUTO_TEST_CASE(peer_protection_test) // Test protection of localhost peers... // Expect 1/4 localhost peers to be protected from eviction, - // independently of other characteristics. + // if no onion peers. BOOST_CHECK(IsProtected( num_peers, [](NodeEvictionCandidate& c) { + c.m_is_onion = false; c.m_is_local = (c.id == 1 || c.id == 9 || c.id == 11); }, /* protected_peer_ids */ {1, 9, 11}, /* unprotected_peer_ids */ {}, random_context)); - // Expect 1/4 localhost peers and 1/4 of the others to be protected - // from eviction, sorted by longest uptime (lowest nTimeConnected). + // Expect 1/4 localhost peers and 1/4 of the other peers to be protected, + // sorted by longest uptime (lowest nTimeConnected), if no onion peers. BOOST_CHECK(IsProtected( num_peers, [](NodeEvictionCandidate& c) { c.nTimeConnected = c.id; + c.m_is_onion = false; c.m_is_local = (c.id > 6); }, /* protected_peer_ids */ {0, 1, 2, 7, 8, 9}, |