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

feat: support multiple shared caps #5363

Merged
merged 13 commits into from
Nov 8, 2023
Merged

feat: support multiple shared caps #5363

merged 13 commits into from
Nov 8, 2023

Conversation

mattsse
Copy link
Collaborator

@mattsse mattsse commented Nov 8, 2023

Extracted parts from #2981 that are required for #5360

The underlying P2P stream is now no longer limited to eth and can handle any shared caps

@mattsse mattsse changed the title Matt/extract caps features feat: support multiple shared caps Nov 8, 2023
@mattsse mattsse added the A-networking Related to networking in general label Nov 8, 2023
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

I have one question about the offset, but the rest looks good to me

@@ -539,7 +539,7 @@ where

// all messages sent in this stream are subprotocol messages, so we need to switch the
// message id based on the offset
compressed[0] = item[0] + this.shared_capability.offset();
compressed[0] = item[0] + MAX_RESERVED_MESSAGE_ID + 1;
Copy link
Member

Choose a reason for hiding this comment

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

is this right? it's not clear to me why we can use a constant here / stop using the offset

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this is correct because the offset is reserved + 1

see how the offsets are determined:

// Message IDs are assumed to be compact from ID 0x10 onwards (0x00-0x0f is reserved for the
// "p2p" capability) and given to each shared (equal-version, equal-name) capability in
// alphabetic order.
let mut offset = MAX_RESERVED_MESSAGE_ID + 1;

so what this does here it strips away the reserved offset so that the ID aligns with the first shared capability

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm adding some docs and maybe change the behaviour here so that it perhaps always normalizes messages or also returns the matching capability

Copy link
Member

Choose a reason for hiding this comment

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

thx for the docs, yeah, this makes sense. for eth plus another capability we'd need to add the offset for the second capability somewhere else right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the offsets are computed after the initial handshake, but atm the caller of the p2p is responsible for matching the message id to a shared cap.
for example, shared caps:: [("eth", 10), ("other", 5)] the p2p stream would yield messages with first byte [0..14] (total number of messages), the reserved offset is already subtracted here.
for a single cap the message can be deserialized directly, but with multiple, we'd need to check, for example first byte 12 would actually belong to "other" and we'd need to subtract the number of messages of "eth" before

I'll make this more ergonomic in followups

@@ -460,7 +460,7 @@ where
// * `eth/67` is reserved message IDs 0x10 - 0x19.
// * `qrs/65` is reserved message IDs 0x1a - 0x21.
//
decompress_buf[0] = bytes[0] - this.shared_capability.offset();
decompress_buf[0] = bytes[0] - MAX_RESERVED_MESSAGE_ID - 1;
Copy link
Member

Choose a reason for hiding this comment

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

same q here about the offset

@mattsse mattsse requested a review from Rjected November 8, 2023 19:18
Copy link
Member

@Rjected Rjected left a comment

Choose a reason for hiding this comment

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

I like the docs, this makes sense now

@@ -539,7 +539,7 @@ where

// all messages sent in this stream are subprotocol messages, so we need to switch the
// message id based on the offset
compressed[0] = item[0] + this.shared_capability.offset();
compressed[0] = item[0] + MAX_RESERVED_MESSAGE_ID + 1;
Copy link
Member

Choose a reason for hiding this comment

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

thx for the docs, yeah, this makes sense. for eth plus another capability we'd need to add the offset for the second capability somewhere else right?

@mattsse mattsse added this pull request to the merge queue Nov 8, 2023
Merged via the queue into main with commit 011494d Nov 8, 2023
25 checks passed
@mattsse mattsse deleted the matt/extract-caps-features branch November 8, 2023 20:43
@gakonst gakonst mentioned this pull request Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-networking Related to networking in general
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants