-
Notifications
You must be signed in to change notification settings - Fork 971
Gloas payload envelope processing [WIP] #8806
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
16
commits into
sigp:unstable
Choose a base branch
from
eserilev:gloas-payload-processing
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,629
−34
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
43c24d3
init payload processing
eserilev a4b993f
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 8204241
Progress
eserilev 22f3fd4
Continue
eserilev 9f972d1
progress
eserilev f637a68
Import payload flow
eserilev 4c70392
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 5796864
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 47782a6
delay cache, and remove some todos
eserilev 7d0d438
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev 72fe220
Import logs
eserilev 64c30b8
Merge conflicts
eserilev 1859bc2
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev fd9d4a7
Merge branch 'unstable' of https://github.com/sigp/lighthouse into gl…
eserilev de2362a
Fix compilation error
eserilev b525fe0
Fix
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,197 @@ | ||
| //! This module provides the `EnvelopeTimesCache` which contains information regarding payload | ||
| //! envelope timings. | ||
| //! | ||
| //! This provides `BeaconChain` and associated functions with access to the timestamps of when a | ||
| //! payload envelope was observed, verified, executed, and imported. | ||
| //! This allows for better traceability and allows us to determine the root cause for why an | ||
| //! envelope was imported late. | ||
| //! This allows us to distinguish between the following scenarios: | ||
| //! - The envelope was observed late. | ||
| //! - Consensus verification was slow. | ||
| //! - Execution verification was slow. | ||
| //! - The DB write was slow. | ||
| use eth2::types::{Hash256, Slot}; | ||
| use std::collections::HashMap; | ||
| use std::time::Duration; | ||
|
|
||
| type BlockRoot = Hash256; | ||
|
|
||
| #[derive(Clone, Default)] | ||
| pub struct EnvelopeTimestamps { | ||
| /// When the envelope was first observed (gossip or RPC). | ||
| pub observed: Option<Duration>, | ||
| /// When consensus verification (state transition) completed. | ||
| pub consensus_verified: Option<Duration>, | ||
| /// When execution layer verification started. | ||
| pub started_execution: Option<Duration>, | ||
| /// When execution layer verification completed. | ||
| pub executed: Option<Duration>, | ||
| /// When the envelope was imported into the DB. | ||
| pub imported: Option<Duration>, | ||
| } | ||
|
|
||
| /// Delay data for envelope processing, computed relative to the slot start time. | ||
| #[derive(Debug, Default)] | ||
| pub struct EnvelopeDelays { | ||
| /// Time after start of slot we saw the envelope. | ||
| pub observed: Option<Duration>, | ||
| /// The time it took to complete consensus verification of the envelope. | ||
| pub consensus_verification_time: Option<Duration>, | ||
| /// The time it took to complete execution verification of the envelope. | ||
| pub execution_time: Option<Duration>, | ||
| /// Time after execution until the envelope was imported. | ||
| pub imported: Option<Duration>, | ||
| } | ||
|
|
||
| impl EnvelopeDelays { | ||
| fn new(times: EnvelopeTimestamps, slot_start_time: Duration) -> EnvelopeDelays { | ||
| let observed = times | ||
| .observed | ||
| .and_then(|observed_time| observed_time.checked_sub(slot_start_time)); | ||
| let consensus_verification_time = times | ||
| .consensus_verified | ||
| .and_then(|consensus_verified| consensus_verified.checked_sub(times.observed?)); | ||
| let execution_time = times | ||
| .executed | ||
| .and_then(|executed| executed.checked_sub(times.started_execution?)); | ||
| let imported = times | ||
| .imported | ||
| .and_then(|imported_time| imported_time.checked_sub(times.executed?)); | ||
| EnvelopeDelays { | ||
| observed, | ||
| consensus_verification_time, | ||
| execution_time, | ||
| imported, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct EnvelopeTimesCacheValue { | ||
| pub slot: Slot, | ||
| pub timestamps: EnvelopeTimestamps, | ||
| pub peer_id: Option<String>, | ||
| } | ||
|
|
||
| impl EnvelopeTimesCacheValue { | ||
| fn new(slot: Slot) -> Self { | ||
| EnvelopeTimesCacheValue { | ||
| slot, | ||
| timestamps: Default::default(), | ||
| peer_id: None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Default)] | ||
| pub struct EnvelopeTimesCache { | ||
| pub cache: HashMap<BlockRoot, EnvelopeTimesCacheValue>, | ||
| } | ||
|
|
||
| impl EnvelopeTimesCache { | ||
| /// Set the observation time for `block_root` to `timestamp` if `timestamp` is less than | ||
| /// any previous timestamp at which this envelope was observed. | ||
| pub fn set_time_observed( | ||
| &mut self, | ||
| block_root: BlockRoot, | ||
| slot: Slot, | ||
| timestamp: Duration, | ||
| peer_id: Option<String>, | ||
| ) { | ||
| let entry = self | ||
| .cache | ||
| .entry(block_root) | ||
| .or_insert_with(|| EnvelopeTimesCacheValue::new(slot)); | ||
| match entry.timestamps.observed { | ||
| Some(existing) if existing <= timestamp => { | ||
| // Existing timestamp is earlier, do nothing. | ||
| } | ||
| _ => { | ||
| entry.timestamps.observed = Some(timestamp); | ||
| entry.peer_id = peer_id; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Set the timestamp for `field` if that timestamp is less than any previously known value. | ||
| fn set_time_if_less( | ||
| &mut self, | ||
| block_root: BlockRoot, | ||
| slot: Slot, | ||
| field: impl Fn(&mut EnvelopeTimestamps) -> &mut Option<Duration>, | ||
| timestamp: Duration, | ||
| ) { | ||
| let entry = self | ||
| .cache | ||
| .entry(block_root) | ||
| .or_insert_with(|| EnvelopeTimesCacheValue::new(slot)); | ||
| let existing_timestamp = field(&mut entry.timestamps); | ||
| if existing_timestamp.is_none_or(|prev| timestamp < prev) { | ||
| *existing_timestamp = Some(timestamp); | ||
| } | ||
| } | ||
|
|
||
| pub fn set_time_consensus_verified( | ||
| &mut self, | ||
| block_root: BlockRoot, | ||
| slot: Slot, | ||
| timestamp: Duration, | ||
| ) { | ||
| self.set_time_if_less( | ||
| block_root, | ||
| slot, | ||
| |timestamps| &mut timestamps.consensus_verified, | ||
| timestamp, | ||
| ) | ||
| } | ||
|
|
||
| pub fn set_time_started_execution( | ||
| &mut self, | ||
| block_root: BlockRoot, | ||
| slot: Slot, | ||
| timestamp: Duration, | ||
| ) { | ||
| self.set_time_if_less( | ||
| block_root, | ||
| slot, | ||
| |timestamps| &mut timestamps.started_execution, | ||
| timestamp, | ||
| ) | ||
| } | ||
|
|
||
| pub fn set_time_executed(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) { | ||
| self.set_time_if_less( | ||
| block_root, | ||
| slot, | ||
| |timestamps| &mut timestamps.executed, | ||
| timestamp, | ||
| ) | ||
| } | ||
|
|
||
| pub fn set_time_imported(&mut self, block_root: BlockRoot, slot: Slot, timestamp: Duration) { | ||
| self.set_time_if_less( | ||
| block_root, | ||
| slot, | ||
| |timestamps| &mut timestamps.imported, | ||
| timestamp, | ||
| ) | ||
| } | ||
|
|
||
| pub fn get_envelope_delays( | ||
| &self, | ||
| block_root: BlockRoot, | ||
| slot_start_time: Duration, | ||
| ) -> EnvelopeDelays { | ||
| if let Some(entry) = self.cache.get(&block_root) { | ||
| EnvelopeDelays::new(entry.timestamps.clone(), slot_start_time) | ||
| } else { | ||
| EnvelopeDelays::default() | ||
| } | ||
| } | ||
|
|
||
| /// Prune the cache to only store the most recent 2 epochs. | ||
| pub fn prune(&mut self, current_slot: Slot) { | ||
| self.cache | ||
| .retain(|_, entry| entry.slot > current_slot.saturating_sub(64_u64)); | ||
| } | ||
| } |
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 |
|---|---|---|
|
|
@@ -112,12 +112,17 @@ impl<T: BeaconChainTypes> PayloadNotifier<T> { | |
| if let Some(precomputed_status) = self.payload_verification_status { | ||
| Ok(precomputed_status) | ||
| } else { | ||
| notify_new_payload(&self.chain, self.block.message()).await | ||
| notify_new_payload( | ||
| &self.chain, | ||
| self.block.message().tree_hash_root(), | ||
| self.block.message().try_into()?, | ||
| ) | ||
| .await | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// Verify that `execution_payload` contained by `block` is considered valid by an execution | ||
| /// Verify that `execution_payload` associated with `beacon_block_root` is considered valid by an execution | ||
| /// engine. | ||
| /// | ||
| /// ## Specification | ||
|
|
@@ -126,17 +131,20 @@ impl<T: BeaconChainTypes> PayloadNotifier<T> { | |
| /// contains a few extra checks by running `partially_verify_execution_payload` first: | ||
| /// | ||
| /// https://github.com/ethereum/consensus-specs/blob/v1.1.9/specs/bellatrix/beacon-chain.md#notify_new_payload | ||
| async fn notify_new_payload<T: BeaconChainTypes>( | ||
| pub async fn notify_new_payload<T: BeaconChainTypes>( | ||
| chain: &Arc<BeaconChain<T>>, | ||
| block: BeaconBlockRef<'_, T::EthSpec>, | ||
| beacon_block_root: Hash256, | ||
| new_payload_request: NewPayloadRequest<'_, T::EthSpec>, | ||
| ) -> Result<PayloadVerificationStatus, BlockError> { | ||
| let execution_layer = chain | ||
| .execution_layer | ||
| .as_ref() | ||
| .ok_or(ExecutionPayloadError::NoExecutionConnection)?; | ||
|
|
||
| let execution_block_hash = block.execution_payload()?.block_hash(); | ||
| let new_payload_response = execution_layer.notify_new_payload(block.try_into()?).await; | ||
| let execution_block_hash = new_payload_request.execution_payload_ref().block_hash(); | ||
| let new_payload_response = execution_layer | ||
| .notify_new_payload(new_payload_request.clone()) | ||
| .await; | ||
|
|
||
| match new_payload_response { | ||
| Ok(status) => match status { | ||
|
|
@@ -152,10 +160,11 @@ async fn notify_new_payload<T: BeaconChainTypes>( | |
| ?validation_error, | ||
| ?latest_valid_hash, | ||
| ?execution_block_hash, | ||
| root = ?block.tree_hash_root(), | ||
| graffiti = block.body().graffiti().as_utf8_lossy(), | ||
| proposer_index = block.proposer_index(), | ||
| slot = %block.slot(), | ||
| // TODO(gloas) are these other logs important? | ||
| root = ?beacon_block_root, | ||
| // graffiti = block.body().graffiti().as_utf8_lossy(), | ||
| // proposer_index = block.proposer_index(), | ||
| // slot = %block.slot(), | ||
| method = "new_payload", | ||
| "Invalid execution payload" | ||
| ); | ||
|
|
@@ -178,11 +187,11 @@ async fn notify_new_payload<T: BeaconChainTypes>( | |
| { | ||
| // This block has not yet been applied to fork choice, so the latest block that was | ||
| // imported to fork choice was the parent. | ||
| let latest_root = block.parent_root(); | ||
| let latest_root = new_payload_request.parent_beacon_block_root()?; | ||
|
|
||
| chain | ||
| .process_invalid_execution_payload(&InvalidationOperation::InvalidateMany { | ||
| head_block_root: latest_root, | ||
| head_block_root: *latest_root, | ||
| always_invalidate_head: false, | ||
| latest_valid_ancestor: latest_valid_hash, | ||
| }) | ||
|
|
@@ -197,10 +206,11 @@ async fn notify_new_payload<T: BeaconChainTypes>( | |
| warn!( | ||
| ?validation_error, | ||
| ?execution_block_hash, | ||
| root = ?block.tree_hash_root(), | ||
| graffiti = block.body().graffiti().as_utf8_lossy(), | ||
| proposer_index = block.proposer_index(), | ||
| slot = %block.slot(), | ||
| // TODO(gloas) are these other logs important? | ||
| root = ?beacon_block_root, | ||
| // graffiti = block.body().graffiti().as_utf8_lossy(), | ||
| // proposer_index = block.proposer_index(), | ||
| // slot = %block.slot(), | ||
|
Comment on lines
+209
to
+213
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would like to delete these as well |
||
| method = "new_payload", | ||
| "Invalid execution payload block hash" | ||
| ); | ||
|
|
||
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.
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.
we wont have this info post gloas, I'd like to delete these fields if thats okay