[fuzz] Use public methods in addrman fuzz tests #23053

pull jnewbery wants to merge 5 commits into bitcoin:master from jnewbery:2021-09-addrman-fuzzer-public-methods2 changing 1 files +71 −76
  1. jnewbery commented at 10:04 AM on September 21, 2021: member

    #22974 improved the performance of CAddrMan::Good() significantly so that it could be used directly in the fuzz tests, instead of those tests reaching directly into addrman's internal data structures.

    This PR continues the work of making the fuzz tests only use CAddrMan's public methods and pulls the Fill() and RandAddr() methods from CAddrManDeterministic into free functions, since they no longer need access to CAddrMan internals.

  2. jnewbery commented at 10:05 AM on September 21, 2021: member

    @vasild - this addresses your review comment here: #22974#pullrequestreview-757542948

  3. in src/test/fuzz/addrman.cpp:29 in 00a2c72d52 outdated
      23 | @@ -23,92 +24,85 @@ void initialize_addrman()
      24 |      SelectParams(CBaseChainParams::REGTEST);
      25 |  }
      26 |  
      27 | -class CAddrManDeterministic : public CAddrMan
      28 | +/** Generate a random address. Always returns a valid address. */
      29 | +static CNetAddr RandAddr(FuzzedDataProvider& fuzzed_data_provider, FastRandomContext& fast_random_context)
      30 | +    EXCLUSIVE_LOCKS_REQUIRED(cs)
    


    MarcoFalke commented at 10:21 AM on September 21, 2021:

    leftover annotation?


    jnewbery commented at 1:13 PM on September 21, 2021:

    Oops! Fixed now. Thank you.

  4. DrahtBot added the label Tests on Sep 21, 2021
  5. jnewbery force-pushed on Sep 21, 2021
  6. DrahtBot added the label Needs rebase on Sep 21, 2021
  7. jnewbery commented at 11:02 AM on September 22, 2021: member

    Rebased

  8. jnewbery force-pushed on Sep 22, 2021
  9. DrahtBot removed the label Needs rebase on Sep 22, 2021
  10. DrahtBot commented at 5:45 PM on September 22, 2021: member

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #22910 ([RFC] Encapsulate asmap in NetGroupManager by jnewbery)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  11. in src/test/fuzz/addrman.cpp:113 in 19e2d94ecd outdated
     137 | -                Add_(addr, source, time_penalty);
     138 | +    return addr;
     139 | +}
     140 |  
     141 | -                if (n > 0 && mapInfo.size() % n == 0) {
     142 | -                    Good_(addr, false, GetTime());
    


    vasild commented at 8:31 AM on September 29, 2021:

    The new code calls Good() which calls Good_(/*test_before_evict=*/true) whereas the old code passed false. I think this is ok.

  12. vasild approved
  13. vasild commented at 8:43 AM on September 29, 2021: member

    ACK 19e2d94ecd599e469e3ff168b456088e12e61f6f

    The public Good() will do some extra locking and call Check() in comparison to Good_(). The locking should be insignificant wrt performance and the Check() should be noop due to the used consistency_check_ratio=0. Also, the public Good() will do "test before evict" which could cause some slowdown.

    I did measure the timings to fill an addrman with hardcoded n=3 (33% tried), num_sources=50 and num_addresses=500 on both master and this PR. The addrman ends up with about 16k addresses.

    master:

       13.493194 sec: fill
        0.534130 sec: ser
        5.664423 sec: deser
        1.330460 sec: compare
    
       13.488360 sec: fill
        0.529679 sec: ser
        5.632100 sec: deser
        1.321111 sec: compare
    

    This PR:

       14.130295 sec: fill
        0.553457 sec: ser
        5.809201 sec: deser
        1.392843 sec: compare
    
       13.757125 sec: fill
        0.556877 sec: ser
        5.863635 sec: deser
        1.371259 sec: compare
    
  14. MarcoFalke requested review from mzumsande on Sep 29, 2021
  15. MarcoFalke requested review from amitiuttarwar on Sep 29, 2021
  16. practicalswift commented at 2:44 PM on September 29, 2021: contributor

    Concept ACK

  17. jnewbery commented at 2:54 PM on September 29, 2021: member

    I'm moving this to draft for now. It conflicts with #22950, which I think should go in first.

  18. jnewbery marked this as a draft on Sep 29, 2021
  19. jnewbery force-pushed on Oct 4, 2021
  20. jnewbery commented at 2:02 PM on October 4, 2021: member

    Rebased on #22950. Leaving as a draft until that PR is merged.

  21. [fuzz] Create a FastRandomContext in addrman fuzz tests
    Don't reach inside the object-under-test to use its random context.
    56303e382e
  22. [fuzz] Pass FuzzedDataProvider& into Fill() in addrman fuzz tests
    Use a (reference) parameter instead of a data member of
    CAddrManDeterministic. This will allow us to make Fill() a free function
    in a later commit.
    
    Also remove CAddrManDeterministic.m_fuzzed_data_provider since it's no
    longer used.
    491975c596
  23. jnewbery force-pushed on Oct 5, 2021
  24. [fuzz] Make RandAddr() a free function in fuzz/addrman.cpp
    It doesn't require access to CAddrManDeterministic
    90ad8ad61a
  25. [fuzz] Make Fill() a free function in fuzz/addrman.cpp
    Also rename it to FillAddrman and pass an addrman reference as an
    argument. Change FillAddrman to only use addrman's public interface methods.
    640476eb0e
  26. [fuzz] Update comment in FillAddrman()
    Suggested here: https://github.com/bitcoin/bitcoin/pull/22974#discussion_r711119626
    44452110f0
  27. jnewbery force-pushed on Oct 5, 2021
  28. jnewbery commented at 3:59 PM on October 5, 2021: member

    Rebased. Marking ready for review.

  29. jnewbery marked this as ready for review on Oct 5, 2021
  30. MarcoFalke commented at 4:14 PM on October 5, 2021: member
    SUMMARY: ThreadSanitizer: data race /usr/lib/llvm-12/bin/../include/c++/v1/ios:523:12 in std::__1::ios_base::width() const
    
  31. amitiuttarwar commented at 4:21 PM on October 5, 2021: contributor

    concept ACK

  32. jnewbery commented at 4:31 PM on October 5, 2021: member

    SUMMARY: ThreadSanitizer: data race /usr/lib/llvm-12/bin/../include/c++/v1/ios:523:12 in std::__1::ios_base::width() const @MarcoFalke - I don't see how that can be related to this PR. The failure is in validation_chainstate_tests, which I don't touch here (changes are only in fuzz/addrman.cpp).

  33. theuni commented at 5:58 PM on October 5, 2021: member

    utACK 44452110f0fa7cc1bcb941a3c7b5db4b492a7b9c. Agree the failure seems unrelated, looks like some startup race.

    Thanks very much @vasild for the benchmarks. Indeed it appears the only functional change here is hitting more locks and test_before_evict is true, good to know those don't slow things down too much.

    It appears to me that AddrManDeterministic would no longer be required if AddrMan accepted a reference to a FastRandomContext and grew an equality operator, though I'm not sure there's any need for that.

  34. vasild approved
  35. vasild commented at 8:20 AM on October 6, 2021: member

    ACK 44452110f0fa7cc1bcb941a3c7b5db4b492a7b9c

  36. MarcoFalke commented at 8:27 AM on October 6, 2021: member

    Correct, the tsan failure is unrelated (known bug with boost). Sorry for missing this. Re-run the task, but it can be ignored either way.

  37. mzumsande commented at 6:16 PM on October 7, 2021: member

    ACK 44452110f0fa7cc1bcb941a3c7b5db4b492a7b9c

    Reviewed the code and did a few hours of fuzzing addrman_serdeser, and the results look as expected to me (e.g. addrman of various sizes are created for different fuzzing inputs).

    Not related to this PR, but the structure of src/test/addrman.cpp is a bit confusing to me, maybe the fuzz target data_stream_addr_man should be moved from the beginning of the file to the other targets.

  38. in src/test/fuzz/addrman.cpp:305 in 44452110f0
     301 | @@ -307,7 +302,7 @@ FUZZ_TARGET_INIT(addrman_serdeser, initialize_addrman)
     302 |  
     303 |      CDataStream data_stream(SER_NETWORK, PROTOCOL_VERSION);
     304 |  
     305 | -    addr_man1.Fill();
     306 | +    FillAddrman(addr_man1, fuzzed_data_provider);
    


    mzumsande commented at 12:56 AM on October 8, 2021:

    Not related to the changes in this PR, but a general observation on the changed fuzz test: I just noticed that addrman_serdeser is currently the slowest (>60 minutes, slower almost by a factor of 2 compared to the second slowest one) of fuzz tests when run for the qa asset corpus (CI Link), so it seems to be the current bottleneck for a CI run to finish. I wonder if it this is still in the acceptable range, or whether it would make sense to ease the parameters a bit in a follow-up so that it would fill addrman with less addresses.

  39. fanquake merged this on Oct 8, 2021
  40. fanquake closed this on Oct 8, 2021

  41. jnewbery deleted the branch on Oct 8, 2021
  42. sidhujag referenced this in commit 79fe0fcfe7 on Oct 8, 2021
  43. DrahtBot locked this on Oct 30, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-15 06:14 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me