[addrman] De-duplicate Add() function #22627

pull amitiuttarwar wants to merge 1 commits into bitcoin:master from amitiuttarwar:2021-08-merge-add changing 5 files +42 −68
  1. amitiuttarwar commented at 10:10 PM on August 4, 2021: contributor

    This PR merges the two definitions of this overloaded function to reduce code duplication.

    When these functions were introduced in https://github.com/bitcoin/bitcoin/commit/5fee401fe14aa6459428a26a82f764db70a6a0b9, there were multiple places that invoked Add() with a single addr and a vector of addrs each, so it made sense to overload the function. I could see how the small difference in log statement was more meaningful when a peer was added via IRC :)

    Now, the definition of Add() that takes in a single address is only invoked from the hidden/test-only RPC addpeeraddress. These changes should not cause any observable difference, and are covered by the existing tests that use this RPC endpoint.

  2. amitiuttarwar added the label Refactoring on Aug 4, 2021
  3. ghost commented at 10:15 PM on August 4, 2021: none

    when a peer was added via IRC :)

    IRC?

  4. sipa commented at 10:17 PM on August 4, 2021: member

    Before DNS seeds existed, bitcoin would connect to a specific IRC server, join a channel, and look for other nodes joining that channel, and then insert those to its IP address database.

  5. practicalswift commented at 10:18 PM on August 4, 2021: contributor

    Concept ACK

    +3 −17 is nice

  6. ghost commented at 10:20 PM on August 4, 2021: none

    Before DNS seeds existed, bitcoin would connect to a specific IRC server, join a channel, and look for other nodes joining that channel, and then insert those to its IP address database.

    Interesting. TIL. Thanks @sipa

    I think Joinmarket does something similar for peers participating in coinjoin.

  7. Zero-1729 commented at 11:23 PM on August 4, 2021: contributor

    Concept ACK

  8. lsilva01 commented at 12:07 AM on August 5, 2021: contributor

    Concept ACK https://github.com/bitcoin/bitcoin/pull/22627/commits/6ef302effb2f99a538855011f781481d0eb208e8

    However this change breaks test\addrman_tests.cpp test. Maybe keeping the removed Add(const CAddress &addr ...) method as a proxy to bool Add(const std::vector<CAddress> &vAddr, ...) can prevent this.

    bool Add(const CAddress &addr, const CNetAddr& source, int64_t nTimePenalty = 0)
            EXCLUSIVE_LOCKS_REQUIRED(!cs)
    {
        std::vector<CAddress> vAddr{addr};
        return Add(vAddr, source, nTimePenalty);
    }
    
  9. amitiuttarwar commented at 12:37 AM on August 5, 2021: contributor

    oops, tests! marking as draft until I resolve 😛

  10. amitiuttarwar marked this as a draft on Aug 5, 2021
  11. amitiuttarwar force-pushed on Aug 5, 2021
  12. 0xB10C commented at 7:43 AM on August 5, 2021: member

    Concept ACK

  13. fanquake deleted a comment on Aug 5, 2021
  14. theStack commented at 9:09 AM on August 5, 2021: member

    Concept ACK

  15. amitiuttarwar commented at 5:37 PM on August 5, 2021: contributor

    The two CI failures seem unrelated. They both fail with:

    test/miner_tests.cpp:219:32: error: use of undeclared identifier 'VERSIONBITS_TOP_BITS'

    This PR doesn't touch miner_tests, and that file does not call CAddrMan::Add(). It passes locally on this branch as well as rebased on master. I suspect its something strange with the auto-merge to master, since #22277 was just merged.

    That said, I'm going to leave this in a draft so it doesn't cause conflict with #20233- that change is more important :)

  16. jnewbery commented at 5:37 PM on August 5, 2021: member

    Concept ACK

  17. mzumsande commented at 5:55 PM on August 5, 2021: member

    The CI failures were fixed with #22630.

    Concept ACK

  18. DrahtBot commented at 10:10 AM on August 6, 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:

    • #22697 (addrman: Remove CAddrMan::Clear() function 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.

  19. jnewbery commented at 10:46 AM on August 13, 2021: member

    #20233 has been merged. I'm happy to review this once it's been rebased on master.

  20. [addrman] Merge the two Add() functions
    Merge the two definitions of this overloaded function to reduce code
    duplication.
    60e0cbdd57
  21. amitiuttarwar force-pushed on Aug 16, 2021
  22. amitiuttarwar marked this as ready for review on Aug 16, 2021
  23. amitiuttarwar commented at 3:43 PM on August 16, 2021: contributor

    rebased on master, ready for review!

  24. jnewbery commented at 4:18 PM on August 16, 2021: member

    Code review ACK 60e0cbdd574bb9109bcad1e0c27c7936a534a0e7

    Nice cleanup

  25. Zero-1729 commented at 9:32 PM on August 16, 2021: contributor

    crACK 60e0cbd

    LGTM 🧉

  26. fanquake approved
  27. fanquake commented at 2:04 AM on August 17, 2021: member

    ACK 60e0cbdd574bb9109bcad1e0c27c7936a534a0e7

  28. fanquake referenced this in commit f3dbd1c2b2 on Aug 17, 2021
  29. fanquake commented at 2:08 AM on August 17, 2021: member

    This has been merged in f3dbd1c2b2bc2b8edae657f79a2d31820b428e86.

  30. fanquake closed this on Aug 17, 2021

  31. sidhujag referenced this in commit e1cc4184f2 on Aug 20, 2021
  32. DrahtBot locked this on Aug 18, 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-20 18:14 UTC

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