-
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
base: master
Are you sure you want to change the base?
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.
Overall looks good to me. There's a dangling todo that needs to reference an issue, and a few potentially dangerous as
conversions I'd prefer to see removed. Other than that, great stuff!
fn encode(&self, data: Self::RequestMessage) -> Result<Vec<u8>, io::Error> { | ||
match data { | ||
GossipsubBroadcastRequest::NewTx(tx) => { | ||
Ok(self.codec.encode(&*tx)?.as_bytes().into_owned()) |
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.
Nit: The dereference is redundant here.
Ok(self.codec.encode(&*tx)?.as_bytes().into_owned()) | |
Ok(self.codec.encode(&tx)?.as_bytes().into_owned()) |
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.
Done in e9f1404
{ | ||
let mut response = Vec::new(); | ||
socket | ||
.take(self.max_response_size as u64) |
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 as
conversion can theoretically error. Personally I'd prefer to use u64::try_from
explicitly instead, or as suggested before - redefine max_response_size
as a u64
.
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 as above, see #2460
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 updating! 🙏
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]