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
[WIP] Extend round trip API to GetBlockBodies LES protocol command #1372
Conversation
trinity/protocol/les/exchanges.py
Outdated
@@ -11,20 +11,27 @@ | |||
from trinity.protocol.common.exchanges import ( | |||
BaseExchange, | |||
) | |||
# Q: What is the order to imports? and why sometimes new line between imports and sometimes not? |
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.
ordering is:
- standard library
- 3rd party
- local library
- local modules (these are all
from . import
style imports
Within each section we alphabetize and normally do whitespace breaks between libraries.
Within each of those sections
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.
ah, great! I wonder if my ide can set this order. I've done it in the past for my IntelliJ.
trinity/protocol/les/normalizers.py
Outdated
|
||
TResult = TypeVar('TResult') | ||
LESNormalizer = BaseNormalizer[Dict[str, Any], TResult] | ||
|
||
|
||
# Q: Shouldn't this be named GetBlockHeadersNormalizer? |
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.
No, because it normalizes the response which is a Blockheaders
message (responding to a GetBlockHeaders
request).
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.
ah! makes sense
trinity/protocol/les/trackers.py
Outdated
] | ||
|
||
|
||
# Q: Where can I find the signature for this class? |
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.
I don't know what you mean by signature
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.
I'm not sure either, feel free to hop on chat, since it may require some back-and-forth to resolve.
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.
ah, i just meant the input arguments
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.
There's probably room to extract some repeated logic into new methods in trinity/protocol/common
, but I wouldn't worry about that refactor until all the tests pass.
trinity/protocol/les/handlers.py
Outdated
|
||
|
||
class LESExchangeHandler(BaseChainExchangeHandler): | ||
class ETHExchangeHandler(BaseChainExchangeHandler): |
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 should stay LES
, to indicate that it's for the light protocol.
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.
ah, you're right. didn't mean to change this, actually
trinity/protocol/les/normalizers.py
Outdated
class BlockHeadersNormalizer(LESNormalizer[Tuple[BlockHeader, ...]]): | ||
@staticmethod | ||
def normalize_result(message: Dict[str, Any]) -> Tuple[BlockHeader, ...]: | ||
result = message['headers'] | ||
return result | ||
|
||
|
||
class GetBlockBodiesNormalizer(LESNormalizer[Tuple[BlockBody, ...]]): |
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.
Yeah, so for the same reason, the Get
should be dropped here. This normalizer only acts on the response value, which is sent with the BlockBodies
command.
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.
Ah got it
trinity/protocol/les/normalizers.py
Outdated
@staticmethod | ||
def normalize_result(message: Dict[str, Any]) -> Tuple[BlockBody, ...]: | ||
result = message['bodies'] | ||
return result |
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.
I'm fairly sure that we'll want to return block body bundles here, similar to how the eth version does:
py-evm/trinity/protocol/eth/normalizers.py
Lines 48 to 57 in 9ba2c1f
uncles_hashes = tuple(map( | |
compose(keccak, rlp.encode), | |
tuple(body.uncles for body in msg) | |
)) | |
transaction_roots_and_trie_data = tuple(map( | |
make_trie_root_and_nodes, | |
tuple(body.transactions for body in msg) | |
)) | |
body_bundles = tuple(zip(msg, transaction_roots_and_trie_data, uncles_hashes)) |
but everywhere msg
is in this snippet, using result
from the PR.
This is going to change the type signature of the the exchange, and so will affect the validator, etc.
trinity/protocol/les/trackers.py
Outdated
] | ||
|
||
|
||
# Q: Where can I find the signature for this class? |
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.
I'm not sure either, feel free to hop on chat, since it may require some back-and-forth to resolve.
Also, it's probably best to reduce the scope on each PR to just one exchange, in this case: |
... and excellent cute animal picture 💯 |
I agree. That was my intention too. Thanks! |
133b687
to
12fc090
Compare
Here's a suggestion for how to run a local smoke test to make sure everything is working as expected. Use the new API you created to replace this code: py-evm/trinity/sync/light/service.py Lines 170 to 172 in 7d0f188
With (roughly): block_body_bundles = peer.requests.get_block_bodies((block_hash, )) Then you'll extract the block and return it. After making that change, you should be able to run a light trinity node and use web3.py to call Note that the above change should actually be made permanently in trinity. It doesn't have to be made in this PR, but it would be okay to if you want. |
Go ahead and rebase this, fix lint, and force-push 👍 |
A kind reminder that this needs to be migrated to the new https://github.com/ethereum/trinity repository. See #1667 for detailed instructions. |
What was wrong?
The following LES command pair does not have a round trip API available to it.
GetBlockBodies -> BlockBodies
How was it fixed?
Use and/or extend the existing Handler/Manager pattern to implement round trip APIs for these command pairs. At minimum each of these should be tested at the Request level and the Peer level. Feel free to borrow patterns and test cases from the existing tests.
Cute Animal Picture