Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from Jan 16, 2024

Conversation

mzumsande
Copy link
Contributor

@mzumsande mzumsande commented Jan 9, 2024

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.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 9, 2024

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

Code Coverage

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

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.

@jonatack
Copy link
Contributor

jonatack commented Jan 9, 2024

Concept ACK

@brunoerg
Copy link
Contributor

Concept ACK

@sipa
Copy link
Member

sipa commented Jan 10, 2024

utACK d536e5a

Copy link
Contributor

@jonatack jonatack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK d536e5a

@@ -111,6 +111,9 @@ class AddrMan

/**
* Attempt to add one or more addresses to addrman's new table.
* If an address already exists in addrman, the existing entry may be updated
* (e.g. adding additional service flags). If the existing entry is in the new table,
* it may be added to more buckets, improving the probability of selection.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_).

Copy link
Contributor Author

@mzumsande mzumsande Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

src/net_processing.cpp Outdated Show resolved Hide resolved
BOOST_CHECK_EQUAL(vAddr5.size(), 1U);
BOOST_CHECK_EQUAL(vAddr5.at(0).nServices, NODE_NETWORK);

// Adding service flags even works when the addr is in Tried
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Adding service flags even works when the addr is in Tried
// Adding service flags even works when the addr is in Tried; see `AddSingle()`

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment on lines 113 to +115
* Attempt to add one or more addresses to addrman's new table.
* If an address already exists in addrman, the existing entry may be updated
* (e.g. adding additional service flags). If the existing entry is in the new table,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Service flags are handled differently, depending on whether
validated (if received from the peer) or unvalidated (received
via gossip relay).
@mzumsande
Copy link
Contributor Author

d536e5a to 74ebd4d: Addressed feedback

Copy link
Member

@furszy furszy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 74ebd4d

Copy link
Contributor

@brunoerg brunoerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK 74ebd4d

@achow101
Copy link
Member

ACK 74ebd4d

@achow101 achow101 merged commit 5711da6 into bitcoin:master Jan 16, 2024
16 checks passed
@jonatack
Copy link
Contributor

Post-merge ACK 74ebd4d

@mzumsande mzumsande deleted the 202401_addrman_serviceflags branch January 17, 2024 19:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants