-
Notifications
You must be signed in to change notification settings - Fork 1k
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(gossipsub): revise symbol naming to follow conventions #3303
refactor(gossipsub): revise symbol naming to follow conventions #3303
Conversation
This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏 |
268e519
to
e2e3e51
Compare
909b206
to
b13b0e1
Compare
I have to test the changes from backwards compatibility correctness, however I think it's ready for review cc @thomaseizinger 🙏 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this :)
I'd spot checked it and looks alright. I'll give it a more thorough look once we have the comments resolved!
protocols/gossipsub/src/lib.rs
Outdated
#[deprecated( | ||
since = "0.44.0", | ||
note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::config::Builder" | ||
)] | ||
pub type GossipsubBuilder = config::Builder; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes. That is a tricky one.
I somewhat agree that config::Builder
is more accurate. However, we didn't call it GossipsubConfigBuilder
before so if we stick to gossipsub::Builder
now we technically aren't making the situation any worse :)
For the sake of not bike-shedding this and moving on, I'd suggest to just stick to that and keep config
private.
If somebody cares enough, they can think of a solution to improve this assuming balanced trade-offs (private/public modules, length of type names/paths, expressiveness, etc).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
b9c3218
to
d5d2a2e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks pretty good already.
I've made some inline comments, please check for yourself that we are only renaming actual types and not comments.
Another thing we've noticed in previous PRs for renaming types is that the rustdoc comments might suddenly read a bit odd if it f.e. just says Behaviour
now instead of Gossipsub
. I've not through all docs in this review yet, can you please check them?
Some of the deprecation type aliases are still missing. I can recommend to temporarily undo all changes in examples/
and tests/
and see if everything still compiles. If not, you are missing a deprecation type alias :)
protocols/gossipsub/src/types.rs
Outdated
@@ -23,7 +23,7 @@ use crate::rpc_proto; | |||
use crate::TopicHash; | |||
use libp2p_core::{connection::ConnectionId, PeerId}; | |||
use prometheus_client::encoding::EncodeLabelValue; | |||
use prost::Message; | |||
use prost::Message as ProtobufMessage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you just need to the trait to be in scope to call functions on it you can do this:
use prost::Message as ProtobufMessage; | |
use prost::Message as _; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed all occurrences in gossipsub
protocols/gossipsub/src/behaviour.rs
Outdated
@@ -670,7 +667,7 @@ where | |||
} | |||
} | |||
|
|||
// Gossipsub peers | |||
// Behaviour peers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This rename doesn't make much sense IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
protocols/gossipsub/src/behaviour.rs
Outdated
@@ -919,7 +916,7 @@ where | |||
} | |||
} | |||
|
|||
/// Gossipsub JOIN(topic) - adds topic peers to mesh and sends them GRAFT messages. | |||
/// Behaviour JOIN(topic) - adds topic peers to mesh and sends them GRAFT messages. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here. Can you revert the ones in the comments please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
@@ -88,7 +88,7 @@ impl From<SigningError> for PublishError { | |||
|
|||
/// Errors that can occur in the protocols handler. | |||
#[derive(Debug, Error)] | |||
pub enum GossipsubHandlerError { | |||
pub enum HandlerError { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module is public (unfortunately), meaning this rename needs a deprecation type alias.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While we are at it, I think it would make sense to re-export all of these from the root and add deprecation type aliases that they shouldn't be imported from the error
module so we can make it private in a future release.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to add type alias in error.rs too. Not sure if that's a neat solution here
protocols/gossipsub/src/config.rs
Outdated
/// Calling `Builder::protocol_id_prefix` will set a new prefix and retain the prefix logic. | ||
/// Calling `Builder::protocol_id` will set a custom `protocol_id` and disable the prefix logic. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// Calling `Builder::protocol_id_prefix` will set a new prefix and retain the prefix logic. | |
/// Calling `Builder::protocol_id` will set a custom `protocol_id` and disable the prefix logic. | |
/// Calling [`Builder::protocol_id_prefix`] will set a new prefix and retain the prefix logic. | |
/// Calling [`Builder::protocol_id`] will set a custom `protocol_id` and disable the prefix logic. |
Should be a proper type reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏 |
cba9823
to
51e2bf6
Compare
Got a question regarding force pushing - why isn't it suitable in this repo. Couldn't find anything in Personally, I force push when conflicts occur - I'm rebasing trunk and then force pushing to remote. What do you prefer in these situations? |
We squash-merge all PRs so the commit history within a PR is not that important and thus regular merges are fine. They also play nicely with GitHub's review interface, allowing you to review only the new commits. |
I've pushed some changes, but will double-check all your comments. Will mention you when ready for re-review 😄 |
This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏 |
2143e09
to
6e6445d
Compare
@thomaseizinger I've checked all your comments - right now the PR should be ready for review. Sorry that it took very long... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well done, only a few more comments! :)
protocols/gossipsub/src/lib.rs
Outdated
#[deprecated( | ||
since = "0.44.0", | ||
note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::HandlerError" | ||
)] | ||
pub type GossipsubHandlerError = HandlerError; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We previously didn't export this error on the root level right? I think this type alias is unnecessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is slightly related but it would be really great if we can get rid of the public error
module while we are at it. I'd prefer to not have any public modules actually. They are an easy semver hazard because types that shouldnt' be part of the public API easily slip into it.
To achieve this in a backwards-compatible way, we need to:
- Make the
error
module private and rename it toerror_priv
- Make a new, inline
error
module that contains type aliases with deprecation notice, re-exporting the errors fromerror_priv
- Export all errors in the root module (you are already doing this on line 171)
This allows us to migrate users towards importing the errors from the root module and we can remove the public error
module in a future release!
See what we did in this PR for example: https://github.com/libp2p/rust-libp2p/pull/3238/files#diff-acd49d828b2b4f41554331034dd696f7946d8c1becc7635d118435454c262cde
Everything used to be under a v2
module that now only contains deprecated type-aliases that re-export symbols from their new location. Some of the new locations are crate-private however. In other words, we will be making certain types inaccessible in a future release. That is because they should have never been part of the public API.
I see some opportunities for this in gossipsub too:
protocol
modulemetrics
(contains many public types and functions that a user doesn't need to interact with)subscription_filter
(can be completely flattened, i.e. re-export from root to shorten import paths)time_cache
(not sure why that is public at all?)
This is quite an undertaking by itself so it is probably best done in a separate PR. Let me know if you are up for it :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfectly understandable. I like this direction. I'm not sure about making V2
APIs in these kind of changes, but let's talk about it in the next PR ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've created a new issue to track these changes -> #3392
protocols/gossipsub/src/lib.rs
Outdated
|
||
pub use self::config::{Config, ConfigBuilder, ValidationMode, Version}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pub use self::config::{Config, ConfigBuilder, ValidationMode, Version}; | |
pub use self::config::{Config, ConfigBuilder, ValidationMode, Version}; |
Let's not use more whitespace than necessary :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
protocols/gossipsub/src/lib.rs
Outdated
@@ -156,18 +156,73 @@ mod types; | |||
|
|||
mod rpc_proto; | |||
|
|||
pub use self::behaviour::{Gossipsub, GossipsubEvent, MessageAuthenticity}; | |||
pub use self::behaviour::{Behaviour, Event, MessageAuthenticity}; | |||
pub use self::transform::{DataTransform, IdentityTransform}; | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
No worries at all, thank you for pushing this forward! |
This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏 |
6e6445d
to
d9efbc3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This looks good. I double checked our exports again, they all match the old types :)
Approvals have been dismissed because the PR was updated after the send-it
label was applied.
Approvals have been dismissed because the PR was updated after the send-it
label was applied.
Description
Changes regarding the #2217
Notes
Links to any relevant issues
Open Questions
Change checklist