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

Refactor to prepare whitelist peers #2297

Merged
merged 44 commits into from
Mar 14, 2022
Merged

Conversation

AureliaDolo
Copy link
Contributor

@AureliaDolo AureliaDolo commented Feb 15, 2022

To prepare for #1946

I mostly created the PeerType variant and refactored a lot accordingly.

In a nutshell, instead of having many not so related indexes, we have now one index and one config per peer type. I tried my best match on peer types and avoid if as much as possible (if you see something other than stuff == PeerType::default() , there may be an underlying issue), and hide complexity is smaller methods.

@AureliaDolo AureliaDolo marked this pull request as draft February 15, 2022 16:02
@AureliaDolo
Copy link
Contributor Author

AureliaDolo commented Feb 15, 2022

A few points before you take a look:

  • I didn't worked on the tests yet
  • There is still a lot of copy pasting, I had to review in order to see if 1/ I didn't made mistakes 2/ there are some factorization opportunities and how to do them
  • I'm not sure AT ALL with what I did with the banned peers
  • good luck with the review 🍀

edit: the latter points have been resolved, but you could still use some luck :)

@AureliaDolo AureliaDolo changed the title Introduce PeerType enum and associated configs and counters. Add whitelisted peers (and slight refacto) Feb 15, 2022
@AureliaDolo AureliaDolo self-assigned this Feb 16, 2022
Copy link
Contributor Author

@AureliaDolo AureliaDolo left a comment

Choose a reason for hiding this comment

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

I'm considedring having more of a hashmap peertype -> peerConnectionCount what do you think ? @massalabs/core-team

But first making things as generic as possible

massa-network/src/peer_info_database.rs Outdated Show resolved Hide resolved
massa-network/src/peer_info_database.rs Outdated Show resolved Hide resolved
@AureliaDolo
Copy link
Contributor Author

And I'm really wondering what to do with the banned variant, I'd happily take any suggestions

@AureliaDolo
Copy link
Contributor Author

I'm working on fixing the tests, but let me know if you have any suggestions, especially on code readability

@AureliaDolo AureliaDolo marked this pull request as ready for review February 17, 2022 13:46
@AureliaDolo
Copy link
Contributor Author

AureliaDolo commented Feb 17, 2022

If you have any scenario ideas with whitelist peers, I'd take them.

To do next (maybe in some follow ups, maybe here)

yvan-sraka
yvan-sraka previously approved these changes Feb 21, 2022
Copy link
Contributor

@yvan-sraka yvan-sraka left a comment

Choose a reason for hiding this comment

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

My personal belief is we should merge that PR as it since a lot of good refactorings was already done here, and all the items of the checklist you gave should be done as followups issues/PRs!

One last tweak/code change before merging could be to annotate function that share the same pattern but only differ by their types as "mostly duplicated" since they could be refactored in a second pass using generics :)

@AureliaDolo AureliaDolo changed the title Add whitelisted peers (and slight refacto) Refactor to prepare whitelist peers Feb 21, 2022
@AureliaDolo
Copy link
Contributor Author

One last tweak/code change before merging could be to annotate function that share the same pattern but only differ by their types as "mostly duplicated" since they could be refactored in a second pass using generics :)

I'll move them around yet again to make more sense

@AurelienFT
Copy link
Contributor

@AureliaDolo I have made a proposition to resolve some problems and improve genericity here : #2379 it's based on your PR. I have made a new PR instead of review because the changes suggested are too big.

@AureliaDolo AureliaDolo requested a review from damip March 7, 2022 15:03
@AurelienFT
Copy link
Contributor

@AureliaDolo It's possible that my refactor broke some tests. Do you want me to fix this or you will do it ?

AurelienFT
AurelienFT previously approved these changes Mar 9, 2022
Copy link
Contributor

@AurelienFT AurelienFT left a comment

Choose a reason for hiding this comment

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

As I have work partially on that I'm agree on this new design. Well tested. Nice refactor :)

@damip damip dismissed their stale review March 9, 2022 10:33

most points were corrected but I didn't do a whole new pass

yvan-sraka
yvan-sraka previously approved these changes Mar 10, 2022
Copy link
Contributor

@yvan-sraka yvan-sraka left a comment

Choose a reason for hiding this comment

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

LGTM! That's always a nice thing to use an Enum rather than several conflicting boolean fields, nice refactoring here ✨

@AureliaDolo
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Mar 10, 2022

Merge conflict.

Copy link
Contributor

@AurelienFT AurelienFT left a comment

Choose a reason for hiding this comment

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

The merge don't change anything related to this PR.

@AureliaDolo
Copy link
Contributor Author

bors merge

@bors
Copy link
Contributor

bors bot commented Mar 14, 2022

Build succeeded:

@bors bors bot merged commit fb6c442 into main Mar 14, 2022
@bors bors bot deleted the feature/network/whitelist_peers branch March 14, 2022 08:46
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.

5 participants