-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Remove p2pservice networkcodec trait #2388
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.
Generally I like the decoupling you're achieving here. I think we could do some simplifications by reducing the number of traits, and for example just having one GossipSubCodec
trait and oneRequestResponseReadWrite
trait. Both of these could be generic over the data format if needed.
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.
Nice one 👍
Left just some nitpics and a question
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.
Approved, but I'd prefer to see d4e2198 reverted.
crates/services/p2p/src/codecs.rs
Outdated
/// Returns the serialized object as a slice. | ||
fn as_bytes(&self) -> Cow<[u8]>; | ||
/// Returns the serialized object as a Vector. | ||
fn to_vec(self) -> Vec<u8>; |
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 think using Cow is strictly better than Vec here. See my comment in the other thread.
This reverts commit d4e2198.
…odec-trait # Conflicts: # CHANGELOG.md
Rename function to higlight how it works
Linked Issues/PRs
Closes #2368
Description
In the P2P service, we couple together GossipSub and RequestResponse codecs in a
NetworkCodec
trait. In practice, this coupling is not necessary as the two codecs use different Messages and different logics for encoding/deconding messages. The only thing that they share in common is using Postcard as the data format to serialize and deserialize data, but this is not made clear in the network trait.This PR is a rework of Codecs in the libp2p service, which deletes the
NetworkCodec
trait and therefore the coupling betweenGossipSubCodec
andRequestResponseCodec
. In particular:are moved to a struct
Postcardthat implements the
DataFormat` trait,BoundedCodec
struct that implements theRequestResponse::Codec
trait for anyDataFormat
supersedes the oldPostcardCodec
.UnboundedCodec
struct that implements theGossipsubCodec trait for any
DataFormatsupersedes the old
PostcardCodec`,request_response::protocols
module`,Gossipsub
andRequestResponse
.TODO:
Checklist
Before requesting review
After merging, notify other teams
[Add or remove entries as needed]