doc, test: test and explain service flag handling #29213

pull mzumsande wants to merge 1 commits into bitcoin:master from mzumsande:202401_addrman_serviceflags changing 3 files +34 −2
  1. mzumsande commented at 9:52 PM on January 9, 2024: contributor

    Service flags received from the peer-to-peer network are handled differently, depending on how we receive them. If received directly from an outbound peer the flags belong to, they replace existing flags. If received via gossip relay (so that anyone could send them), new flags are added, but existing ones but cannot be overwritten.

    Document that and add test coverage for it.

  2. DrahtBot commented at 9:52 PM on January 9, 2024: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage

    For detailed information about the code coverage, see the test coverage report.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK furszy, brunoerg, achow101
    Stale ACK sipa, jonatack

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

  3. jonatack commented at 10:00 PM on January 9, 2024: member

    Concept ACK

  4. mzumsande force-pushed on Jan 9, 2024
  5. brunoerg commented at 1:07 PM on January 10, 2024: contributor

    Concept ACK

  6. sipa commented at 1:27 PM on January 10, 2024: member

    utACK d536e5a6325d1885224f36debdcc5245b94efe8a

  7. DrahtBot requested review from jonatack on Jan 10, 2024
  8. DrahtBot requested review from brunoerg on Jan 10, 2024
  9. in src/addrman.h:116 in d536e5a632 outdated
     110 | @@ -111,6 +111,9 @@ class AddrMan
     111 |  
     112 |      /**
     113 |       * Attempt to add one or more addresses to addrman's new table.
     114 | +     * If an address already exists in addrman, the existing entry may be updated
     115 | +     * (e.g. adding additional service flags). If the existing entry is in the new table,
     116 | +     * it may be added to more buckets, improving the probability of selection.
    


    jonatack commented at 8:40 PM on January 12, 2024:

    Perhaps add a "see AddSingle()" mention somewhere in here, as the logic referred to here is in that method called from this one (Add/Add_).


    mzumsande commented at 9:16 PM on January 15, 2024:

    I think it's better if the header doesn't refer to implementation details. If I remember correctly, this logic used to be in Add(), then Add_(), now AddSingle(), and I don't think it's nice if we have to update addrman.h for refactors like that.

  10. in src/net_processing.cpp:3381 in d536e5a632 outdated
    3375 | @@ -3376,6 +3376,9 @@ void PeerManagerImpl::ProcessMessage(CNode& pfrom, const std::string& msg_type,
    3376 |          vRecv >> CNetAddr::V1(addrMe);
    3377 |          if (!pfrom.IsInboundConn())
    3378 |          {
    3379 | +            // Overwrites potentially existing services. In contrast to this,
    3380 | +            // unvalidated services received via gossip relay are only
    3381 | +            // ever added but cannot replace existing ones.
    


    jonatack commented at 9:23 PM on January 12, 2024:

    It seems to me this might be helpful and the message names are unlikely to change.

                 // Overwrites potentially existing services. In contrast to this,
    -            // unvalidated services received via gossip relay are only
    -            // ever added but cannot replace existing ones.
    +            // unvalidated services received via gossip relay in ADDR/ADDRV2
    +            // messages are only ever added but do not replace existing ones.
    

    mzumsande commented at 9:14 PM on January 15, 2024:

    done

  11. in src/test/addrman_tests.cpp:1119 in d536e5a632 outdated
    1114 | +    BOOST_CHECK(addrman->Good(addr)); // addr has NODE_NONE
    1115 | +    std::vector<CAddress> vAddr5{addrman->GetAddr(/*max_addresses=*/0, /*max_pct=*/0, /*network=*/std::nullopt)};
    1116 | +    BOOST_CHECK_EQUAL(vAddr5.size(), 1U);
    1117 | +    BOOST_CHECK_EQUAL(vAddr5.at(0).nServices, NODE_NETWORK);
    1118 | +
    1119 | +    // Adding service flags even works when the addr is in Tried
    


    jonatack commented at 9:43 PM on January 12, 2024:
        // Adding service flags even works when the addr is in Tried; see `AddSingle()`
    

    mzumsande commented at 9:19 PM on January 15, 2024:

    similar to above, I don't like referring to implementation details in comments unless really necessary.

  12. jonatack commented at 9:45 PM on January 12, 2024: member

    ACK d536e5a6325d1885224f36debdcc5245b94efe8a

  13. DrahtBot added the label CI failed on Jan 15, 2024
  14. in src/addrman.h:115 in d536e5a632 outdated
     110 | @@ -111,6 +111,9 @@ class AddrMan
     111 |  
     112 |      /**
     113 |       * Attempt to add one or more addresses to addrman's new table.
     114 | +     * If an address already exists in addrman, the existing entry may be updated
     115 | +     * (e.g. adding additional service flags). If the existing entry is in the new table,
    


    furszy commented at 12:57 PM on January 15, 2024:

    It is not immediately clear that additional services flags may be added, but the return value could still be false. And the same seems to happen for the AddrInfo timestamp. It can also be updated while the return value remains false.


    mzumsande commented at 9:13 PM on January 15, 2024:

    I think that followed from the @return doc, but it wasn't so obvious that adding an existing addr to another new bucket also affects the return value; Changed the @return description to true if at least one address is successfully added, or added to an additional bucket. Unaffected by updates.

  15. doc, test: Test and explain service flag handling
    Service flags are handled differently, depending on whether
    validated (if received from the peer) or unvalidated (received
    via gossip relay).
    74ebd4d135
  16. mzumsande force-pushed on Jan 15, 2024
  17. mzumsande commented at 9:21 PM on January 15, 2024: contributor

    d536e5a to 74ebd4d: Addressed feedback

  18. furszy commented at 9:24 PM on January 15, 2024: member

    ACK 74ebd4d1359edce82a134dfcd3da9840f8d206e2

  19. DrahtBot requested review from jonatack on Jan 15, 2024
  20. DrahtBot requested review from sipa on Jan 15, 2024
  21. DrahtBot removed the label CI failed on Jan 15, 2024
  22. brunoerg approved
  23. brunoerg commented at 1:26 PM on January 16, 2024: contributor

    utACK 74ebd4d1359edce82a134dfcd3da9840f8d206e2

  24. achow101 commented at 6:29 PM on January 16, 2024: member

    ACK 74ebd4d1359edce82a134dfcd3da9840f8d206e2

  25. achow101 merged this on Jan 16, 2024
  26. achow101 closed this on Jan 16, 2024

  27. jonatack commented at 6:59 PM on January 16, 2024: member

    Post-merge ACK 74ebd4d1359edce82a134dfcd3da9840f8d206e2

  28. mzumsande deleted the branch on Jan 17, 2024
  29. bitcoin locked this on Jan 16, 2025

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-17 03:13 UTC

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