feat(l1): only use negotiated capabilities #3047
Closed
Mechanix97 wants to merge 120 commits intomainfrom
Closed
Conversation
…com:lambdaclass/ethrex into refactor/capability-struct-instead-of-tuple
…com:lambdaclass/ethrex into refactor/capability-struct-instead-of-tuple
…hrex into mecha/implement-protocols
mpaulucci
reviewed
Jun 25, 2025
| message.encode(&mut frame_data)?; | ||
| message.encode( | ||
| &mut frame_data, | ||
| &self.p2p_protocol, |
Collaborator
There was a problem hiding this comment.
why are we passing this here?
Contributor
There was a problem hiding this comment.
The parameter p2p_protocol (along with eth_protocol and snap_protocol) is used inside Message::encode to encode the message header.
However the header could be encoded just before calling Message::encode, which would allow us to remove the p2p_protocol and snap_protocol parameters, it could be something like this (we still need to pass eth_protocol to encode the message according to the right eth capability)
// Header encoding
(message.code() + message.offset(
&self.p2p_protocol,
&self.eth_protocol,
&self.snap_protocol)?
).encode(&mut frame_data);
message.encode(&mut frame_data, &self.eth_protocol)What do you think? do you prefer doing the header encoding of Message::encode?
Collaborator
|
Closing since this hasn't been worked on in some time. But we will use this PR as reference for when we work on this again. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
We need a way to ensure what version of a protocol we're using when communicating with a peer.
Description
Important
After merging this PR, we can merge this other PR from the hive repository, which adds updates the devp2p simulator to include the latest test suite.
When the connection is established with the peer we agree in the p2p protocol version (as default n 5). This happens after the handshake is done.
Then we exchange the hello messages, where we coordinate with the peer which protocols we're using. Once we agree on them, we store them in the
Capabilitiesstruct (which is shared with theRLPxCodecbehind anArc<Mutex<>>.The codec has the responsability to generate the messages to send the peers and decode the messages we receive. Now, the
p2p,ethandsnapprotocols agreed with the peers are stored in theCapabilitiesstruct. So when we need to encode/decode we know which version of the protocol has to be used.Note
TO DO:
The
Capabilitiesstruct is accessed from theRLPxCodecin theencodeanddecodefunctions.However the
encodeanddecodefunctions are sync, while accessing theCapabilitiesisasync(since we need to lock the mutex withself.capabilities.lock().await).The problem is that, even though the functions are sync, they are executed within an
asynccontext, so we cannot useblock_on(we actually have tried that and the thread just crashes), so we need to find a way to fix this.The logic of the code offset has been improved to support differents version of the same protocol. For example, in the
eth/69version a new message is added, so the offset of the snap suite changes depending of which version of the protocol we are using.To allow the messages from different versions to be more differentiated, the
StatusandReceiptsenums were removed and now the structsStatus68,Status69,Receipts68andReceipts69are used directly (each of them implementing theRLPxMessagetrait).Much of the code introduced in the PR #2860 was removed. Only the encode/decode of status and receipt was left. The file struct created has also been deleted.
Closes #3032