mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
Merge #19658: [rpc] Allow RPC to fetch all addrman records and add records to addrman
37a480e0cd[net] Add addpeeraddress RPC method (John Newbery)ae8051bbd8[test] Test that getnodeaddresses() can return all known addresses (John Newbery)f26502e9fc[addrman] Specify max addresses and pct when calling GetAddresses() (John Newbery) Pull request description: Currently addrman only allows a maximum of 1000 records or 23% of all records to be returned in a call to `GetAddr()`. Relax this limit and have the client specify the max records they want. For p2p, behaviour is unchanged (but the rate limiting is set inside net_processing, where it belongs). For RPC, `getnodeaddresses` can now return the complete addrman, which is helpful for testing and monitoring. Also add a test-only RPC `addpeeraddress`, which adds an IP address:port to addrman. This is helpful for testing (eg #18991). ACKs for top commit: naumenkogs: utACK37a480e0cdlaanwj: Code review and lightly manually tested ACK37a480e0cdTree-SHA512: f86dcd410aaebaf6e9ca18ce6f23556e5e4649c1325577213d873aa09967298e65ab2dc19a72670641ae92211a923afda1fe124a82e9d2c1cad73d478ef27fdc
This commit is contained in:
@@ -392,7 +392,7 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
|
||||
// Test: Sanity check, GetAddr should never return anything if addrman
|
||||
// is empty.
|
||||
BOOST_CHECK_EQUAL(addrman.size(), 0U);
|
||||
std::vector<CAddress> vAddr1 = addrman.GetAddr();
|
||||
std::vector<CAddress> vAddr1 = addrman.GetAddr(/* max_addresses */ 0, /* max_pct */0);
|
||||
BOOST_CHECK_EQUAL(vAddr1.size(), 0U);
|
||||
|
||||
CAddress addr1 = CAddress(ResolveService("250.250.2.1", 8333), NODE_NONE);
|
||||
@@ -415,13 +415,15 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
|
||||
BOOST_CHECK(addrman.Add(addr4, source2));
|
||||
BOOST_CHECK(addrman.Add(addr5, source1));
|
||||
|
||||
// GetAddr returns 23% of addresses, 23% of 5 is 1 rounded down.
|
||||
BOOST_CHECK_EQUAL(addrman.GetAddr().size(), 1U);
|
||||
BOOST_CHECK_EQUAL(addrman.GetAddr(/* max_addresses */ 0, /* max_pct */ 0).size(), 5U);
|
||||
// Net processing asks for 23% of addresses. 23% of 5 is 1 rounded down.
|
||||
BOOST_CHECK_EQUAL(addrman.GetAddr(/* max_addresses */ 2500, /* max_pct */ 23).size(), 1U);
|
||||
|
||||
// Test: Ensure GetAddr works with new and tried addresses.
|
||||
addrman.Good(CAddress(addr1, NODE_NONE));
|
||||
addrman.Good(CAddress(addr2, NODE_NONE));
|
||||
BOOST_CHECK_EQUAL(addrman.GetAddr().size(), 1U);
|
||||
BOOST_CHECK_EQUAL(addrman.GetAddr(/* max_addresses */ 0, /* max_pct */ 0).size(), 5U);
|
||||
BOOST_CHECK_EQUAL(addrman.GetAddr(/* max_addresses */ 2500, /* max_pct */ 23).size(), 1U);
|
||||
|
||||
// Test: Ensure GetAddr still returns 23% when addrman has many addrs.
|
||||
for (unsigned int i = 1; i < (8 * 256); i++) {
|
||||
@@ -436,7 +438,7 @@ BOOST_AUTO_TEST_CASE(addrman_getaddr)
|
||||
if (i % 8 == 0)
|
||||
addrman.Good(addr);
|
||||
}
|
||||
std::vector<CAddress> vAddr = addrman.GetAddr();
|
||||
std::vector<CAddress> vAddr = addrman.GetAddr(/* max_addresses */ 2500, /* max_pct */ 23);
|
||||
|
||||
size_t percent23 = (addrman.size() * 23) / 100;
|
||||
BOOST_CHECK_EQUAL(vAddr.size(), percent23);
|
||||
|
||||
Reference in New Issue
Block a user