diff options
author | glozow <gloriajzhao@gmail.com> | 2024-10-02 20:58:05 -0400 |
---|---|---|
committer | glozow <gloriajzhao@gmail.com> | 2024-10-02 21:20:26 -0400 |
commit | cfb59da4b3bb34afae467691a3e901f2b5a186f3 (patch) | |
tree | bf52aee9bdb3b1c91159b75a55c90657edb88d10 /src | |
parent | dda2613239b09e844717a06f255730c5f4c4aa4c (diff) | |
parent | a7498cc7e26b4b3de976e111de2bd2d79b056b31 (diff) |
Merge bitcoin/bitcoin#30980: fuzz: fix bug in p2p_headers_presync harness
a7498cc7e26b4b3de976e111de2bd2d79b056b31 Fix bug in p2p_headers_presync harness (marcofleon)
Pull request description:
The calculation for the test chain's work (`total_work`) should be outside of the loop. Previously, `total_work` was being miscalculated due to multiple additions of work from the same headers. Now, each header's work is only counted once, providing an accurate total.
https://github.com/bitcoin/bitcoin/pull/30918 followup
ACKs for top commit:
dergoegge:
utACK a7498cc7e26b4b3de976e111de2bd2d79b056b31
instagibbs:
ACK a7498cc7e26b4b3de976e111de2bd2d79b056b31
glozow:
makes sense, utACK a7498cc7e26b4b3de976e111de2bd2d79b056b31
mzumsande:
ACK https://github.com/bitcoin/bitcoin/commit/a7498cc7e26b4b3de976e111de2bd2d79b056b31
Tree-SHA512: b95f25dcf7ace220e30f1d72f50d85ee18777467927c0cc1ed8582b390cb7185ffc0e2f127309eb083044fb41f5a13fce5ebb15b7952718a899bafff26921be8
Diffstat (limited to 'src')
-rw-r--r-- | src/test/fuzz/p2p_headers_presync.cpp | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/src/test/fuzz/p2p_headers_presync.cpp b/src/test/fuzz/p2p_headers_presync.cpp index e22087303a..2670aa8ee4 100644 --- a/src/test/fuzz/p2p_headers_presync.cpp +++ b/src/test/fuzz/p2p_headers_presync.cpp @@ -197,15 +197,15 @@ FUZZ_TARGET(p2p_headers_presync, .init = initialize) auto headers_msg = NetMsg::Make(NetMsgType::BLOCK, TX_WITH_WITNESS(block)); g_testing_setup->SendMessage(fuzzed_data_provider, std::move(headers_msg)); }); + } - // This is a conservative overestimate, as base is only moved forward when sending headers. In theory, - // the longest chain generated by this test is 1600 (FUZZ_MAX_HEADERS_RESULTS * 100) headers. In that case, - // this variable will accurately reflect the chain's total work. - total_work += CalculateClaimedHeadersWork(all_headers); + // This is a conservative overestimate, as base is only moved forward when sending headers. In theory, + // the longest chain generated by this test is 1600 (FUZZ_MAX_HEADERS_RESULTS * 100) headers. In that case, + // this variable will accurately reflect the chain's total work. + total_work += CalculateClaimedHeadersWork(all_headers); - // This test should never create a chain with more work than MinimumChainWork. - assert(total_work < chainman.MinimumChainWork()); - } + // This test should never create a chain with more work than MinimumChainWork. + assert(total_work < chainman.MinimumChainWork()); // The headers/blocks sent in this test should never be stored, as the chains don't have the work required // to meet the anti-DoS work threshold. So, if at any point the block index grew in size, then there's a bug |