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(gossipsub): revise symbol naming to follow conventions #3303

Merged
merged 23 commits into from
Jan 27, 2023

Conversation

StemCll
Copy link
Contributor

@StemCll StemCll commented Jan 2, 2023

Description

Changes regarding the #2217

Notes

Links to any relevant issues

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

@mergify
Copy link
Contributor

mergify bot commented Jan 3, 2023

This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏

@StemCll StemCll force-pushed the chore/rename_gossipsub_symbols branch 2 times, most recently from 268e519 to e2e3e51 Compare January 4, 2023 15:24
@StemCll StemCll changed the title WIP: refactor(gossipsub): gossipsub naming revision Refactor(gossipsub): gossipsub naming revision Jan 5, 2023
@StemCll StemCll changed the title Refactor(gossipsub): gossipsub naming revision refactor(gossipsub): gossipsub naming revision Jan 5, 2023
@StemCll StemCll force-pushed the chore/rename_gossipsub_symbols branch from 909b206 to b13b0e1 Compare January 5, 2023 12:04
@StemCll
Copy link
Contributor Author

StemCll commented Jan 5, 2023

I have to test the changes from backwards compatibility correctness, however I think it's ready for review cc @thomaseizinger 🙏

examples/gossipsub-chat.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@thomaseizinger thomaseizinger left a 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!

Comment on lines 193 to 199
#[deprecated(
since = "0.44.0",
note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::config::Builder"
)]
pub type GossipsubBuilder = config::Builder;
Copy link
Contributor

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

Copy link
Contributor Author

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 Show resolved Hide resolved
Copy link
Contributor

@thomaseizinger thomaseizinger left a 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 :)

@@ -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;
Copy link
Contributor

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:

Suggested change
use prost::Message as ProtobufMessage;
use prost::Message as _;

Copy link
Contributor Author

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

@@ -670,7 +667,7 @@ where
}
}

// Gossipsub peers
// Behaviour peers
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

@@ -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.
Copy link
Contributor

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?

Copy link
Contributor Author

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 {
Copy link
Contributor

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.

Copy link
Contributor

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.

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 had to add type alias in error.rs too. Not sure if that's a neat solution here

protocols/gossipsub/src/lib.rs Show resolved Hide resolved
protocols/gossipsub/src/lib.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/lib.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/lib.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/behaviour.rs Outdated Show resolved Hide resolved
Comment on lines 110 to 111
/// 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.
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
/// 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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

@mergify
Copy link
Contributor

mergify bot commented Jan 11, 2023

This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏

@StemCll StemCll force-pushed the chore/rename_gossipsub_symbols branch from cba9823 to 51e2bf6 Compare January 13, 2023 16:02
@StemCll
Copy link
Contributor Author

StemCll commented Jan 13, 2023

Got a question regarding force pushing - why isn't it suitable in this repo. Couldn't find anything in Contributing guide 🤔

Personally, I force push when conflicts occur - I'm rebasing trunk and then force pushing to remote. What do you prefer in these situations?

@thomaseizinger
Copy link
Contributor

Got a question regarding force pushing - why isn't it suitable in this repo. Couldn't find anything in Contributing guide 🤔

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.

@StemCll
Copy link
Contributor Author

StemCll commented Jan 15, 2023

I've pushed some changes, but will double-check all your comments. Will mention you when ready for re-review 😄

@mergify
Copy link
Contributor

mergify bot commented Jan 18, 2023

This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏

@StemCll StemCll force-pushed the chore/rename_gossipsub_symbols branch from 2143e09 to 6e6445d Compare January 23, 2023 14:16
@StemCll
Copy link
Contributor Author

StemCll commented Jan 23, 2023

@thomaseizinger I've checked all your comments - right now the PR should be ready for review. Sorry that it took very long...

@thomaseizinger thomaseizinger changed the title refactor(gossipsub): gossipsub naming revision refactor(gossipsub): revise symbol naming to follow conventions Jan 23, 2023
Copy link
Contributor

@thomaseizinger thomaseizinger left a 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! :)

Comment on lines 173 to 174
#[deprecated(
since = "0.44.0",
note = "Use re-exports that omit `Gossipsub` prefix, i.e. `libp2p::gossipsub::HandlerError"
)]
pub type GossipsubHandlerError = HandlerError;
Copy link
Contributor

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.

Copy link
Contributor

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:

  1. Make the error module private and rename it to error_priv
  2. Make a new, inline error module that contains type aliases with deprecation notice, re-exporting the errors from error_priv
  3. 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 module
  • metrics (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 :)

Copy link
Contributor Author

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 ;)

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've created a new issue to track these changes -> #3392

Comment on lines 168 to 170

pub use self::config::{Config, ConfigBuilder, ValidationMode, Version};

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
pub use self::config::{Config, ConfigBuilder, ValidationMode, Version};
pub use self::config::{Config, ConfigBuilder, ValidationMode, Version};

Let's not use more whitespace than necessary :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

@@ -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};

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

✔️

@thomaseizinger
Copy link
Contributor

@thomaseizinger I've checked all your comments - right now the PR should be ready for review. Sorry that it took very long...

No worries at all, thank you for pushing this forward!

@mergify
Copy link
Contributor

mergify bot commented Jan 26, 2023

This pull request has merge conflicts. Could you please resolve them @StemCll? 🙏

@StemCll StemCll force-pushed the chore/rename_gossipsub_symbols branch from 6e6445d to d9efbc3 Compare January 26, 2023 18:53
thomaseizinger
thomaseizinger previously approved these changes Jan 26, 2023
Copy link
Contributor

@thomaseizinger thomaseizinger left a 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 :)

protocols/gossipsub/CHANGELOG.md Outdated Show resolved Hide resolved
@mergify mergify bot dismissed thomaseizinger’s stale review January 26, 2023 21:27

Approvals have been dismissed because the PR was updated after the send-it label was applied.

thomaseizinger
thomaseizinger previously approved these changes Jan 27, 2023
@mergify mergify bot dismissed thomaseizinger’s stale review January 27, 2023 01:14

Approvals have been dismissed because the PR was updated after the send-it label was applied.

@mergify mergify bot merged commit ab59af4 into libp2p:master Jan 27, 2023
@StemCll StemCll deleted the chore/rename_gossipsub_symbols branch February 22, 2023 17:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants