Skip to content

Conversation

@jnewbery
Copy link
Contributor

@jnewbery jnewbery commented Nov 9, 2021

Various tidy-ups to the addrman tests.

AddrMan's friends both inherit from AddrMan, so just make the private
member protected and remove the friends.
It's only used to create a corrupted peers.dat file. We can do that directly
in a pure function.
It doesn't do anything different from the base AddrMan class.
@jnewbery jnewbery changed the title addrman: tidy-ups to unit tests addrman: tidy up unit tests Nov 9, 2021
@DrahtBot DrahtBot added the P2P label Nov 9, 2021
@DrahtBot
Copy link
Contributor

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23373 (Parse command line arguments from unit and fuzz tests, make addrman consistency check ratio easier to change by vasild)

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.

@fanquake
Copy link
Member

Concept ACK

@theStack
Copy link
Contributor

Concept ACK

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

crACK 36d3510

The cleanup looks good. Though I am not aware of how to test these changes, but the changes done in this PR seem logically sound to me.

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

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

Code review ACK 36d3510.

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

Code-review ACK 36d3510

Left two small non-critical suggestions below.

deterministic = makeDeterministic;
}
explicit AddrManTest(std::vector<bool> asmap = std::vector<bool>())
: AddrMan(asmap, /*deterministic=*/true, /* consistency_check_ratio */ 100)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, feel free to ignore:

Suggested change
: AddrMan(asmap, /*deterministic=*/true, /* consistency_check_ratio */ 100)
: AddrMan(asmap, /*deterministic=*/ true, /*consistency_check_ratio=*/ 100)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops. I'll be more consistent with these comments in future.

Copy link
Member

Choose a reason for hiding this comment

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

I think /*deterministic=*/true is the "clang-format-correct" formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Marco. That was my understanding too. I should have also formatted consistency_check_ratio in that way.

static CDataStream MakeCorruptPeersDat()
{
CDataStream s(SER_DISK, CLIENT_VERSION);
s << ::Params().MessageStart();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit, since we are already in global namespace, the scope-resolution operator could be dropped (like in AddrmanToStream above):

Suggested change
s << ::Params().MessageStart();
s << Params().MessageStart();

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'm not sure, but I think there's a preference to be more explicit when we're calling global functions like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, my assumption was that the scope-resolution operator is only preferred if there is the possibility of namespace ambiguity (e.g. in class methods). I guess it should then also be added to Params() in AddrmanToStream to be consistent. Again, not a big deal, but maybe something to include in potential follow-up PRs.

@maflcko maflcko merged commit 1ff265a into bitcoin:master Nov 12, 2021
@jnewbery jnewbery deleted the 2021-11-addrman-tidyups branch November 12, 2021 09:13
@maflcko maflcko added Tests and removed P2P labels Nov 12, 2021
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Nov 12, 2021
@bitcoin bitcoin locked and limited conversation to collaborators Nov 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants