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

protocols/gossipsub: Make use of prost-codec #3070

Merged
merged 21 commits into from
Nov 4, 2022

Conversation

nloadholtes
Copy link
Contributor

@nloadholtes nloadholtes commented Oct 30, 2022

Description

This is to address issue #2500 (doing one PR per crate)

  • For this PR, I have referenced the work done in protocols/dcutr and modeled this work on what was done there. I tried a few other approaches, but am submitting this one because:
    • The impact of the changes seems minimal compared to trying to get GossipsubCodec to "inherit" the prost_codec::Codec struct/traits. (Doing that seemed to touch larger number of lines/files, and I never got it to compile which I took as a warning I was going in the wrong direction.)
    • This approach seems to work from a test/compiler-messages point of view
    • I believe this code looks more like the protocol/dcutr code, and I am biased towards making a code base look consistent with itself.
  • I am still new to Rust, comments/suggestions/requests/opinions are welcomed 🙂
  • Locally the tests pass and clippy doesn't complain

Links to any relevant issues

#2500

Open Questions

Change checklist

To be completed after the above questions are answered

  • 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 -- N/A, this is a refactor and existing tests are untouched.
  • A changelog entry has been made in the appropriate crates

Depends-On: #3081

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.

Looks good so far!

protocols/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
@nloadholtes nloadholtes force-pushed the nloadholtes/2500-gossipsub-2 branch from a7575aa to 9e2b471 Compare November 2, 2022 14:07
@nloadholtes nloadholtes marked this pull request as ready for review November 2, 2022 14:07
@nloadholtes nloadholtes force-pushed the nloadholtes/2500-gossipsub-2 branch from 9e2b471 to ab1901b Compare November 2, 2022 14:08
@nloadholtes nloadholtes force-pushed the nloadholtes/2500-gossipsub-2 branch from ab1901b to 602e2ab Compare November 2, 2022 15:33
Cargo.toml Outdated Show resolved Hide resolved
protocols/gossipsub/CHANGELOG.md Outdated Show resolved Hide resolved
protocols/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
@nloadholtes nloadholtes force-pushed the nloadholtes/2500-gossipsub-2 branch from edae8f3 to c597afb Compare November 3, 2022 20:54
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 really good already, just a few more minor comments :)

CHANGELOG.md Outdated Show resolved Hide resolved
protocols/gossipsub/CHANGELOG.md Outdated Show resolved Hide resolved
protocols/gossipsub/src/error.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/protocol.rs Outdated Show resolved Hide resolved
protocols/gossipsub/src/error.rs Show resolved Hide resolved
@thomaseizinger
Copy link
Contributor

No need for force-pushes btw, we squash-merge anyway :)

nloadholtes and others added 2 commits November 3, 2022 21:28
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
@nloadholtes
Copy link
Contributor Author

Thanks for the heads up about the squashes! There was a merge conflict the other day so I've been super 👀 making sure I'm not drifting too far out of sync. (Of course since that 1 time everything has been smooth sailing 😂 )

@thomaseizinger
Copy link
Contributor

Thanks for the heads up about the squashes! There was a merge conflict the other day so I've been super eyes making sure I'm not drifting too far out of sync. (Of course since that 1 time everything has been smooth sailing joy )

You can solve the merge conflicts by just merging latest master in :)

@thomaseizinger thomaseizinger changed the title Update protocols/gossipsub to use Protobuf Codec pattern protocols/gossipsub: Make use of prost-codec Nov 4, 2022
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.

I've pushed some final patches, this LGTM!

Thanks for contributing :)

@thomaseizinger
Copy link
Contributor

I'll merge once CI is green!

@@ -22,7 +22,6 @@

use libp2p_core::identity::error::SigningError;
use libp2p_core::upgrade::ProtocolError;
use prost_codec::Error as ProstCodecError;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Style question: in Python we do that fairly often to disambiguate names. In rust the fully qualified name is preferred? (Just want to make sure my thinking is on the right track)

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 more a style-preference. I prefer full-qualified names because:

  • It saves an import line that is otherwise just noise.
  • Common crate names are easy to remember. For example, I know that we are using a crate called prost_codec in this repository. If I come across a reference to prost_codec::Error anywhere in the source-code, my brain just goes "Ah yeah, that must be the1 error type of that crate".
  • If a crate has an Error type, I can pretty much assume that it is the only Error type, otherwise the author would have named them differently (like EncodeError and DecodeError for example).

That is a lot of useful information to extract from a single line of code :)

On the contrary, if types are renamed on import:

  • I have to interrupt my code reading flow if I come across ProstCodecError, go the the use statements and check, what it actually is.
  • Not all programmers will rename it in the same pattern. Meaning I might come across a name that is unfamiliar to me, only to find out it is a type I actually know, just under a different name.

In the end, it is about efficiency in being able to understand code. Especially the last point can be quite annoying :)
When you are hunting a bug f.e. your brain is usually in "spot odd things"-mode and an unfamiliar name is "odd" but in the case of renaming types, it is usually a false-positive.

It is a style thing at the end of the day so YMMV :)

Footnotes

  1. Many crates by convention just have one error type.

@nloadholtes
Copy link
Contributor Author

Sure thing! Thank you for all your help with this. I'm going to try and tackle another protocol (and hopefully it will be smoother on the PR 😅)

@thomaseizinger
Copy link
Contributor

Need to merge #3081 before we can proceed here.

@thomaseizinger
Copy link
Contributor

Need to merge #3081 before we can proceed here.

I am using this opportunity to test mergify's "PR dependency" feature: https://docs.mergify.com/actions/queue/#merge-depends-on

@thomaseizinger
Copy link
Contributor

Need to merge #3081 before we can proceed here.

I am using this opportunity to test mergify's "PR dependency" feature: docs.mergify.com/actions/queue/#merge-depends-on

Cool! It works like a charm:

image

@jsx @mxinden @elenaf9 Look at this! :)

@mergify mergify bot merged commit 1ba9e45 into libp2p:master Nov 4, 2022
@nloadholtes nloadholtes deleted the nloadholtes/2500-gossipsub-2 branch November 4, 2022 11:42
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.

3 participants