This repository was archived by the owner on Nov 6, 2020. It is now read-only.
Macros to define subprotocol packet ids in chain sync#10340
Closed
elferdo wants to merge 16 commits into
Closed
Conversation
added 16 commits
February 4, 2019 16:23
explicit when calling "SyncRequester::send_packet". * Remove "SyncIO::send" and leave only "SyncIO::send_protocol"
|
It looks like @elferdo signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
Contributor
Author
|
Sorry, had some issues with git. I need to create a new PR. |
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
This PR elaborates on comments by @tomusdrw in #10315
Synchronization of a node's blockchain with other nodes happens through an exchange of packets over the network. In parity we support a number of different synchronization protocols that are transmitted and received as devp2p subprotocols.
In devp2p, subprotocol and the particular message within it are identified with a single number instead of two, one for protocol and one for message. Care must be taken to ensure that each type of package within each subprotocol gets a globally unique id that does not collide with other subprotocols.
This PR is a first proposal of a derive-macro that can be applied to an enum and attributes for the enum variants. Code would possibly look like the following:
Benefits of the approach:
from_u8so that ids read from the network can be directly converted to the appropriate identifier.from_u8method returns anOption<Packet>PacketDrawbacks:
PacketInfoand its methodprotocol(). The constants returned in the method must be already defined outside the scope of this macro.The first version of the PR is lacking error checks.