-
Notifications
You must be signed in to change notification settings - Fork 988
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
protocols/gossipsub: Make use of prost-codec
#3070
Conversation
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.
Looks good so far!
a7575aa
to
9e2b471
Compare
9e2b471
to
ab1901b
Compare
ab1901b
to
602e2ab
Compare
…code impl with the Codec.decode() call
…he event of a None.
edae8f3
to
c597afb
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 really good already, just a few more minor comments :)
No need for force-pushes btw, we squash-merge anyway :) |
Co-authored-by: Thomas Eizinger <thomas@eizinger.io>
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 😂 ) |
You can solve the merge conflicts by just merging latest master in :) |
prost-codec
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 pushed some final patches, this LGTM!
Thanks for contributing :)
I'll merge once CI is green! |
protocols/gossipsub/src/error.rs
Outdated
@@ -22,7 +22,6 @@ | |||
|
|||
use libp2p_core::identity::error::SigningError; | |||
use libp2p_core::upgrade::ProtocolError; | |||
use prost_codec::Error as ProstCodecError; |
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.
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)
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 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 toprost_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 onlyError
type, otherwise the author would have named them differently (likeEncodeError
andDecodeError
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 theuse
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
-
Many crates by convention just have one error type. ↩
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 😅) |
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 |
Cool! It works like a charm: |
Description
This is to address issue #2500 (doing one PR per crate)
protocols/dcutr
and modeled this work on what was done there. I tried a few other approaches, but am submitting this one because:GossipsubCodec
to "inherit" theprost_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.)protocol/dcutr
code, and I am biased towards making a code base look consistent with itself.Links to any relevant issues
#2500
Open Questions
Change checklist
To be completed after the above questions are answered
Depends-On: #3081