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

Connect Warp Sync to Proper Packets #692

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hayesgm
Copy link
Contributor

@hayesgm hayesgm commented Dec 1, 2018

This patch connects Warp Sync to the correct packets that come back from Parity when warp syncing. There were a few issues with the algorithm for determining packet ids. It appears that each capability has a size (to allow for protocol upgrades) and we skip that many before the next protocol. These aren't documented from come by Parity's source code. Additionally, it appears that once you negotiate a protocol, you still use the offests from Pv62 but from the higher negotiated ids. It's all a bit weird, but this seems to get everything working. Finally, we had an issue with default map getting called a lot, so we instead opt to hard-code the value and try to pass nil around instead of default map.

This patch connects Warp Sync to the correct packets that come back from Parity when warp syncing. There were a few issues with the algorithm for determining packet ids. It appears that each capability has a size (to allow for protocol upgrades) and we skip that many before the next protocol. These aren't documented from come by Parity's source code. Additionally, it appears that once you negotiate a protocol, you still use the offests from Pv62 but from the higher negotiated ids. It's all a bit weird, but this seems to get everything working. Finally, we had an issue with default map getting called *a lot*, so we instead opt to hard-code the value and try to pass nil around instead of default map.
Copy link
Contributor

@willmeister willmeister left a comment

Choose a reason for hiding this comment

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

Looks good -- good catch on the reserved slots 👍

@@ -100,6 +100,6 @@ defmodule ExWire.DEVp2p.Session do
"""
@spec compatible_capabilities?(t) :: boolean()
def compatible_capabilities?(%__MODULE__{packet_id_map: packet_id_map}) do
packet_id_map != PacketIdMap.default_map()
Map.has_key?(packet_id_map.ids_to_modules, 0x10)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hardcoding 0x10 here presumes to know how PacketIdMap works. Pretty safe assumption, but might work better as a function of PacketIdMap.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, and I don't think this PR has tests passing yet, since I wanted to get some design review. I wasn't sure what's the best way to say "We have compatibility" but having a 0x10 status packet seems to be pretty common on protocols. Also, it's faster to verify than the previous solution, even if possibly less accurate.

@hayesgm
Copy link
Contributor Author

hayesgm commented Dec 19, 2018

@willmeister Was this otherwise addressed in a different PR that you made?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants