-
Notifications
You must be signed in to change notification settings - Fork 987
Gloas serve envelope rpc #8896
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
Open
eserilev
wants to merge
36
commits into
sigp:unstable
Choose a base branch
from
eserilev:gloas-serve-envelope-rpc
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,778
−13
Open
Gloas serve envelope rpc #8896
Changes from 4 commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
ffc2b97
Serve rpc by range and by root:
eserilev e966428
fix spelling issues
eserilev 45912fb
Delete dead code
eserilev 5127054
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev ff0c05e
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 0212e84
Use max request payloads
eserilev 8378f7d
Fixes based on feedback
eserilev 81e105d
more fixes
eserilev fbc5f0d
add kzg commitment var list filling to gloas block full impl
eserilev 6cc4cd9
Add warn logs
eserilev 5b4e3ad
add missing validation
eserilev e1dce7b
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 86ff82e
Ensure payloads are canonical
eserilev c651a32
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 30bfd23
Add some tests
eserilev 7120d4b
spec.max_request_payloads
eserilev bfbb28b
fixes
eserilev d397e0f
Fixes
eserilev 99d9925
Update envelope streamer
eserilev df931fd
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 3e6afae
avoid wrapping canonical_head in Arc, impl CanonicalHeadReader on Bea…
dapplion ed8c549
remove dead BeaconBlockGloas::full() impl
dapplion 9c2ff0d
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev be9e32f
cleanup
eserilev 0769ffc
Reffactor to use adapter pattern
eserilev 54c062d
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev a9bc8a1
Fix comments
eserilev 54dfa0c
ssz size calc refactor
eserilev 12e86c3
Resolve merge conflicts
eserilev 9f72751
Merge branch 'unstable' into gloas-serve-envelope-rpc
eserilev ba57a85
debug message instead of unreachable
eserilev 9c28db2
Reject enveloeps by range req if start slot is pre-gloas
eserilev 0e4e813
Rename to envrange and envroot
eserilev 2ab336d
Comments and logs
eserilev 79e9a7c
Revert
eserilev 34fa9f3
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
138 changes: 138 additions & 0 deletions
138
beacon_node/beacon_chain/src/execution_payload_envelope_streamer.rs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| use std::sync::Arc; | ||
|
|
||
| use bls::Hash256; | ||
| use execution_layer::ExecutionLayer; | ||
| use futures::Stream; | ||
| use task_executor::TaskExecutor; | ||
| use tokio::sync::mpsc::{self, UnboundedSender}; | ||
| use tokio_stream::wrappers::UnboundedReceiverStream; | ||
| use tracing::debug; | ||
| use types::{EthSpec, SignedExecutionPayloadEnvelope}; | ||
|
|
||
| use crate::{BeaconChainError, BeaconChainTypes, BeaconStore, beacon_block_streamer::CheckCaches}; | ||
|
|
||
| type PayloadEnvelopeResult<E> = | ||
| Result<Option<Arc<SignedExecutionPayloadEnvelope<E>>>, BeaconChainError>; | ||
|
|
||
| pub struct PayloadEnvelopeStreamer<T: BeaconChainTypes> { | ||
| execution_layer: ExecutionLayer<T::EthSpec>, | ||
| store: BeaconStore<T>, | ||
| task_executor: TaskExecutor, | ||
| _check_caches: CheckCaches, | ||
| } | ||
|
|
||
| // TODO(gloas) eventually we'll need to expand this to support loading blinded payload envelopes from the db | ||
| // and fetching the execution payload from the EL. See BlockStreamer impl as an example | ||
| impl<T: BeaconChainTypes> PayloadEnvelopeStreamer<T> { | ||
| pub fn new( | ||
| execution_layer_opt: Option<ExecutionLayer<T::EthSpec>>, | ||
| store: BeaconStore<T>, | ||
| task_executor: TaskExecutor, | ||
| check_caches: CheckCaches, | ||
| ) -> Result<Arc<Self>, BeaconChainError> { | ||
| let execution_layer = execution_layer_opt | ||
| .as_ref() | ||
| .ok_or(BeaconChainError::ExecutionLayerMissing)? | ||
| .clone(); | ||
|
|
||
| Ok(Arc::new(Self { | ||
| execution_layer, | ||
| store, | ||
| task_executor, | ||
| _check_caches: check_caches, | ||
| })) | ||
| } | ||
|
|
||
| // TODO(gloas) simply a stub impl for now. Should check some exec payload envelope cache | ||
| // and return the envelope if it exists in the cache | ||
| fn check_payload_envelope_cache( | ||
| &self, | ||
| _beacon_block_root: Hash256, | ||
| ) -> Option<Arc<SignedExecutionPayloadEnvelope<T::EthSpec>>> { | ||
| // if self.check_caches == CheckCaches::Yes | ||
| None | ||
| } | ||
|
|
||
| // used when the execution engine doesn't support the payload bodies methods | ||
| async fn stream_payload_envelopes_fallback( | ||
ethDreamer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| self: Arc<Self>, | ||
| beacon_block_roots: Vec<Hash256>, | ||
| sender: UnboundedSender<(Hash256, Arc<PayloadEnvelopeResult<T::EthSpec>>)>, | ||
| ) { | ||
| debug!("Using slower fallback method of eth_getBlockByHash()"); | ||
| for beacon_block_root in beacon_block_roots { | ||
| let cached_envelope = self.check_payload_envelope_cache(beacon_block_root); | ||
|
|
||
| let envelope_result = if cached_envelope.is_some() { | ||
| Ok(cached_envelope) | ||
| } else { | ||
| // TODO(gloas) we'll want to use the execution layer directly to call | ||
| // the engine api method eth_getBlockByHash() | ||
| self.store | ||
| .get_payload_envelope(&beacon_block_root) | ||
pawanjay176 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| .map(|opt_envelope| opt_envelope.map(Arc::new)) | ||
| .map_err(BeaconChainError::DBError) | ||
| }; | ||
|
|
||
| if sender | ||
| .send((beacon_block_root, Arc::new(envelope_result))) | ||
| .is_err() | ||
| { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub async fn stream( | ||
| self: Arc<Self>, | ||
| beacon_block_roots: Vec<Hash256>, | ||
| sender: UnboundedSender<(Hash256, Arc<PayloadEnvelopeResult<T::EthSpec>>)>, | ||
| ) { | ||
| match self | ||
| .execution_layer | ||
| .get_engine_capabilities(None) | ||
| .await | ||
| .map_err(Box::new) | ||
| .map_err(BeaconChainError::EngineGetCapabilititesFailed) | ||
| { | ||
| Ok(_engine_capabilities) => { | ||
| // TODO(gloas) should check engine capabilities for get_payload_bodies_by_range_v1 | ||
| self.stream_payload_envelopes_fallback(beacon_block_roots, sender) | ||
| .await; | ||
| } | ||
| Err(e) => { | ||
| send_errors(beacon_block_roots, sender, e).await; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub fn launch_stream( | ||
| self: Arc<Self>, | ||
| beacon_block_roots: Vec<Hash256>, | ||
| ) -> impl Stream<Item = (Hash256, Arc<PayloadEnvelopeResult<T::EthSpec>>)> { | ||
| let (envelope_tx, envelope_rx) = mpsc::unbounded_channel(); | ||
| debug!( | ||
| envelopes = beacon_block_roots.len(), | ||
| "Launching a PayloadEnvelopeStreamer" | ||
| ); | ||
| let executor = self.task_executor.clone(); | ||
| executor.spawn( | ||
| self.stream(beacon_block_roots, envelope_tx), | ||
| "get_payload_envelopes_sender", | ||
| ); | ||
| UnboundedReceiverStream::new(envelope_rx) | ||
| } | ||
| } | ||
|
|
||
| async fn send_errors<E: EthSpec>( | ||
| beacon_block_roots: Vec<Hash256>, | ||
| sender: UnboundedSender<(Hash256, Arc<PayloadEnvelopeResult<E>>)>, | ||
| beacon_chain_error: BeaconChainError, | ||
| ) { | ||
| let result = Arc::new(Err(beacon_chain_error)); | ||
| for beacon_block_root in beacon_block_roots { | ||
| if sender.send((beacon_block_root, result.clone())).is_err() { | ||
| break; | ||
| } | ||
| } | ||
| } | ||
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
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
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
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
Oops, something went wrong.
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.
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.
Why don't we start with using the beacon chain here instead and do beacon_chain.execution_layer when we need to access it? that way we get to keep pretty similar logic to the beaocn block streamer.
We need the beacon_chain to access the db anyway
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.
If testing is the concern, we can take a similar approach to the fetch_blobs adapter.
Here, it seems like we need ExecutionLayer, CanonicalHead and the store all of which are present in the BeaconChain
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.
ive went with the adapter pattern