diff options
author | Andrew Chow <github@achow101.com> | 2023-09-20 08:19:30 -0400 |
---|---|---|
committer | Andrew Chow <github@achow101.com> | 2023-09-20 08:25:20 -0400 |
commit | ff564c75e751db6cfaf2a5f1b8a3b471f510976f (patch) | |
tree | cd6a9a6c12c7f0bcecffa968527da584509b095e /test/functional | |
parent | 3966b0a0b6b5e6110ba8106c04af1067fc6219bc (diff) | |
parent | 28bac81a346c0b68273fa73af924f7096cb3f41d (diff) |
Merge bitcoin/bitcoin#27511: rpc: Add test-only RPC getaddrmaninfo for new/tried table address count
28bac81a346c0b68273fa73af924f7096cb3f41d test: add functional test for getaddrmaninfo (stratospher)
c8eb8dae51039aa1938e7040001a149210e87275 rpc: Introduce getaddrmaninfo for count of addresses stored in new/tried table (stratospher)
Pull request description:
implements https://github.com/bitcoin/bitcoin/issues/26907. split off from #26988 to keep RPC, CLI discussions separate.
This PR introduces a new RPC `getaddrmaninfo`which returns the count of addresses in the new/tried table of a node's addrman broken down by network type. This would be useful for users who want to see the distribution of addresses from different networks across new/tried table in the addrman.
```jsx
$ getaddrmaninfo
Result:
{ (json object) json object with network type as keys
"network" : { (json object) The network (ipv4, ipv6, onion, i2p, cjdns)
"new" : n, (numeric) number of addresses in new table
"tried" : n, (numeric) number of addresses in tried table
"total" : n (numeric) total number of addresses in both new/tried tables from a network
},
...
}
```
### additional context from [original PR](https://github.com/bitcoin/bitcoin/pull/26988)
1. network coverage tests were skipped because there’s a small chance that addresses from different networks could hash to the same bucket and cause count of different network addresses in the tests to fail. see https://github.com/bitcoin/bitcoin/pull/26988#discussion_r1137596851.
2. #26988 uses this RPC in -addrinfo CLI. Slight preference for keeping the RPC hidden since this info will mostly be useful to only super users. see https://github.com/bitcoin/bitcoin/pull/26988#discussion_r1173964808.
ACKs for top commit:
0xB10C:
ACK 28bac81a346c0b68273fa73af924f7096cb3f41d
willcl-ark:
reACK 28bac81a346c0b68273fa73af924f7096cb3f41d
achow101:
ACK 28bac81a346c0b68273fa73af924f7096cb3f41d
brunoerg:
reACK 28bac81a346c0b68273fa73af924f7096cb3f41d
theStack:
Code-review ACK 28bac81a346c0b68273fa73af924f7096cb3f41d
Tree-SHA512: 346390167e1ebed7ca5c79328ea452633736aff8b7feefea77460e04d4489059334ae78a3f757f32f5fb7827b309d7186bebab3c3760b3dfb016d564a647371a
Diffstat (limited to 'test/functional')
-rwxr-xr-x | test/functional/rpc_net.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/functional/rpc_net.py b/test/functional/rpc_net.py index 255f5108a2..4fbe22a846 100755 --- a/test/functional/rpc_net.py +++ b/test/functional/rpc_net.py @@ -66,6 +66,7 @@ class NetTest(BitcoinTestFramework): self.test_getnodeaddresses() self.test_addpeeraddress() self.test_sendmsgtopeer() + self.test_getaddrmaninfo() def test_connection_count(self): self.log.info("Test getconnectioncount") @@ -360,6 +361,28 @@ class NetTest(BitcoinTestFramework): node.sendmsgtopeer(peer_id=0, msg_type="addr", msg=zero_byte_string.hex()) self.wait_until(lambda: len(self.nodes[0].getpeerinfo()) == 0, timeout=10) + def test_getaddrmaninfo(self): + self.log.info("Test getaddrmaninfo") + node = self.nodes[1] + + self.log.debug("Test that getaddrmaninfo is a hidden RPC") + # It is hidden from general help, but its detailed help may be called directly. + assert "getaddrmaninfo" not in node.help() + assert "getaddrmaninfo" in node.help("getaddrmaninfo") + + # current count of ipv4 addresses in addrman is {'new':1, 'tried':1} + self.log.info("Test that count of addresses in addrman match expected values") + res = node.getaddrmaninfo() + assert_equal(res["ipv4"]["new"], 1) + assert_equal(res["ipv4"]["tried"], 1) + assert_equal(res["ipv4"]["total"], 2) + assert_equal(res["all_networks"]["new"], 1) + assert_equal(res["all_networks"]["tried"], 1) + assert_equal(res["all_networks"]["total"], 2) + for net in ["ipv6", "onion", "i2p", "cjdns"]: + assert_equal(res[net]["new"], 0) + assert_equal(res[net]["tried"], 0) + assert_equal(res[net]["total"], 0) if __name__ == '__main__': NetTest().main() |