v30.3-roots.1 · Commit 3: [PATCH 03/68] feat(policy): preserve Roots relay and network controls on Core 30.3
test/functional/p2p_eviction.py
Before: test/functional/p2p_eviction.py · After: test/functional/p2p_eviction.py
File metadata
index 9809faa6823e926a3aca77799d9a8a4622fc7624..1b8cb6920ba1a85843a345390b0d768a46813f56 100755
Download original patch · Release notes
Diff rows 1–43 of 43. Line numbers refer to the original before/after files.
+ Added− RemovedUnmarked lines are context.
Scroll the code area horizontally to read long lines. Before is on the left; after is on the right. Unified view fits narrow screens more easily.
test/functional/p2p_eviction.py
CHANGED
|
@@ -122,6 +122,43 @@ class P2PEvict(BitcoinTestFramework):
|
|
| 122 |
self.log.debug("{} protected peers: {}".format(len(protected_peers), protected_peers))
|
| 123 |
assert evicted_peers[0] not in protected_peers
|
| 124 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
if __name__ == '__main__':
|
| 127 |
P2PEvict(__file__).main()
|
|
|
|
| 122 |
self.log.debug("{} protected peers: {}".format(len(protected_peers), protected_peers))
|
| 123 |
assert evicted_peers[0] not in protected_peers
|
| 124 |
|
| 125 |
+
self.log.info("Test that whitebind inbounds get extra eviction power")
|
| 126 |
+
# Allow 10 inbound connections, set whitebind and forceinbound
|
| 127 |
+
self.restart_node(0, extra_args=['-maxconnections=21', '-whitebind=127.0.0.1:30201', '-whitebind=forceinbound@127.0.0.1:30202'])
|
| 128 |
+
self.log.debug("Fill connections with unprivileged peers")
|
| 129 |
+
for i in range(10):
|
| 130 |
+
node.add_p2p_connection(P2PInterface())
|
| 131 |
+
|
| 132 |
+
# Create a peer that expects to be rejected
|
| 133 |
+
# FIXME: "multiprocess, i686, DEBUG" CI task has a reliable timeout issue for v2transport
|
| 134 |
+
class RejectedPeer(P2PInterface):
|
| 135 |
+
def connection_lost(self, exc):
|
| 136 |
+
return
|
| 137 |
+
|
| 138 |
+
allowed_peers = []
|
| 139 |
+
|
| 140 |
+
self.log.debug("Generic inbound gets rejected when full")
|
| 141 |
+
with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]):
|
| 142 |
+
node.add_p2p_connection(RejectedPeer(), wait_for_verack=False, supports_v2_p2p=False)
|
| 143 |
+
|
| 144 |
+
self.log.debug("Default whitebind inbound gets rejected, even when full")
|
| 145 |
+
with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]):
|
| 146 |
+
node.add_p2p_connection(RejectedPeer(), wait_for_verack=False, supports_v2_p2p=False, dstport=30201)
|
| 147 |
+
|
| 148 |
+
self.log.debug("ForceInbound whitebind inbound gets connected, even when full")
|
| 149 |
+
allowed_peers.append(node.add_p2p_connection(P2PInterface(), dstport=30202))
|
| 150 |
+
|
| 151 |
+
peerinfo = node.getpeerinfo()
|
| 152 |
+
assert_equal(len(peerinfo), 10)
|
| 153 |
+
for peer in peerinfo:
|
| 154 |
+
if "30202" in peer["addrbind"]:
|
| 155 |
+
assert peer["forced_inbound"]
|
| 156 |
+
else:
|
| 157 |
+
assert not peer["forced_inbound"]
|
| 158 |
+
|
| 159 |
+
self.log.debug("Generic inbound gets rejected when whitebind peer is filling inbound slot")
|
| 160 |
+
with node.assert_debug_log(["failed to find an eviction candidate - connection dropped (full)"]):
|
| 161 |
+
node.add_p2p_connection(RejectedPeer(), supports_v2_p2p=False, wait_for_verack=False)
|
| 162 |
|
| 163 |
if __name__ == '__main__':
|
| 164 |
P2PEvict(__file__).main()
|