-
Notifications
You must be signed in to change notification settings - Fork 38.7k
test: add addpeeraddress "tried", test addrman checks on restart with asmap #22831
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -239,7 +239,16 @@ def test_getnodeaddresses(self): | |
| assert_raises_rpc_error(-8, "Network not recognized: Foo", self.nodes[0].getnodeaddresses, 1, "Foo") | ||
|
|
||
| def test_addpeeraddress(self): | ||
| """RPC addpeeraddress sets the source address equal to the destination address. | ||
| If an address with the same /16 as an existing new entry is passed, it will be | ||
| placed in the same new bucket and have a 1/64 chance of the bucket positions | ||
| colliding (depending on the value of nKey in the addrman), in which case the | ||
| new address won't be added. The probability of collision can be reduced to | ||
| 1/2^16 = 1/65536 by using an address from a different /16. We avoid this here | ||
| by first testing adding a tried table entry before testing adding a new table one. | ||
| """ | ||
|
Comment on lines
+242
to
+249
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this nondeterminism turns out to be a problem also in other cases, then I guess a new option |
||
| self.log.info("Test addpeeraddress") | ||
| self.restart_node(1, ["-checkaddrman=1"]) | ||
| node = self.nodes[1] | ||
|
|
||
| self.log.debug("Test that addpeerinfo is a hidden RPC") | ||
|
|
@@ -251,17 +260,25 @@ def test_addpeeraddress(self): | |
| assert_equal(node.addpeeraddress(address="", port=8333), {"success": False}) | ||
| assert_equal(node.getnodeaddresses(count=0), []) | ||
|
|
||
| self.log.debug("Test that adding a valid address succeeds") | ||
| assert_equal(node.addpeeraddress(address="1.2.3.4", port=8333), {"success": True}) | ||
| addrs = node.getnodeaddresses(count=0) | ||
| assert_equal(len(addrs), 1) | ||
| assert_equal(addrs[0]["address"], "1.2.3.4") | ||
| assert_equal(addrs[0]["port"], 8333) | ||
|
|
||
| self.log.debug("Test that adding the same address again when already present fails") | ||
| assert_equal(node.addpeeraddress(address="1.2.3.4", port=8333), {"success": False}) | ||
| self.log.debug("Test that adding a valid address to the tried table succeeds") | ||
| assert_equal(node.addpeeraddress(address="1.2.3.4", tried=True, port=8333), {"success": True}) | ||
| with node.assert_debug_log(expected_msgs=["Addrman checks started: new 0, tried 1, total 1"]): | ||
| addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks | ||
| assert_equal(len(addrs), 1) | ||
| assert_equal(addrs[0]["address"], "1.2.3.4") | ||
| assert_equal(addrs[0]["port"], 8333) | ||
|
|
||
| self.log.debug("Test that adding an already-present tried address to the new and tried tables fails") | ||
| for value in [True, False]: | ||
| assert_equal(node.addpeeraddress(address="1.2.3.4", tried=value, port=8333), {"success": False}) | ||
| assert_equal(len(node.getnodeaddresses(count=0)), 1) | ||
|
|
||
| self.log.debug("Test that adding a second address, this time to the new table, succeeds") | ||
| assert_equal(node.addpeeraddress(address="2.0.0.0", port=8333), {"success": True}) | ||
| with node.assert_debug_log(expected_msgs=["Addrman checks started: new 1, tried 1, total 2"]): | ||
| addrs = node.getnodeaddresses(count=0) # getnodeaddresses re-runs the addrman checks | ||
| assert_equal(len(addrs), 2) | ||
jonatack marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Comment on lines
+278
to
+280
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't check the contents of
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in #23035. |
||
|
|
||
|
|
||
| if __name__ == '__main__': | ||
| NetTest().main() | ||
Uh oh!
There was an error while loading. Please reload this page.