diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2021-09-23 01:00:36 +0200 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2022-01-03 22:25:40 +0100 |
commit | 4f1bb467b556ec93c9b8f758783fda4d050da491 (patch) | |
tree | 7bf9bbebd45d17228c144e8f023d25ce1499d162 /src/test/addrman_tests.cpp | |
parent | e880bb7836dab2018049390884220177c6db9b92 (diff) | |
download | bitcoin-4f1bb467b556ec93c9b8f758783fda4d050da491.tar.xz |
test: Add test for multiplicity in addrman new tables
Diffstat (limited to 'src/test/addrman_tests.cpp')
-rw-r--r-- | src/test/addrman_tests.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/test/addrman_tests.cpp b/src/test/addrman_tests.cpp index 75c8cc15bc..a5f40d2d22 100644 --- a/src/test/addrman_tests.cpp +++ b/src/test/addrman_tests.cpp @@ -218,6 +218,38 @@ BOOST_AUTO_TEST_CASE(addrman_new_collisions) BOOST_CHECK_EQUAL(addrman->size(), num_addrs - collisions); } +BOOST_AUTO_TEST_CASE(addrman_new_multiplicity) +{ + auto addrman = TestAddrMan(); + CAddress addr{CAddress(ResolveService("253.3.3.3", 8333), NODE_NONE)}; + int64_t start_time{GetAdjustedTime()}; + addr.nTime = start_time; + + // test that multiplicity stays at 1 if nTime doesn't increase + for (unsigned int i = 1; i < 20; ++i) { + std::string addr_ip{ToString(i % 256) + "." + ToString(i >> 8 % 256) + ".1.1"}; + CNetAddr source{ResolveIP(addr_ip)}; + addrman->Add({addr}, source); + } + AddressPosition addr_pos = addrman->FindAddressEntry(addr).value(); + BOOST_CHECK_EQUAL(addr_pos.multiplicity, 1U); + BOOST_CHECK_EQUAL(addrman->size(), 1U); + + // if nTime increases, an addr can occur in up to 8 buckets + // The acceptance probability decreases exponentially with existing multiplicity - + // choose number of iterations such that it gets to 8 with deterministic addrman. + for (unsigned int i = 1; i < 400; ++i) { + std::string addr_ip{ToString(i % 256) + "." + ToString(i >> 8 % 256) + ".1.1"}; + CNetAddr source{ResolveIP(addr_ip)}; + addr.nTime = start_time + i; + addrman->Add({addr}, source); + } + AddressPosition addr_pos_multi = addrman->FindAddressEntry(addr).value(); + BOOST_CHECK_EQUAL(addr_pos_multi.multiplicity, 8U); + // multiplicity doesn't affect size + BOOST_CHECK_EQUAL(addrman->size(), 1U); +} + BOOST_AUTO_TEST_CASE(addrman_tried_collisions) { auto addrman = TestAddrMan(); |