-
Notifications
You must be signed in to change notification settings - Fork 1k
Gloas backfill #9575
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
hopinheimer
wants to merge
6
commits into
sigp:unstable
Choose a base branch
from
hopinheimer:gloas-backfill
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.
+227
−46
Open
Gloas backfill #9575
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
33b5c93
Implement backfill for envelope
hopinheimer fa385c3
Merge branch 'unstable' of github.com:sigp/lighthouse into gloas-back…
hopinheimer b0e2421
Merge branch 'unstable' of github.com:sigp/lighthouse into gloas-back…
hopinheimer bd75324
Fix pre gloas path for 0-blob count
hopinheimer 19d99b4
Adopt tests to envelope paradigm
hopinheimer 76b4ab6
Blob coupling fix
hopinheimer 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| use crate::data_availability_checker::{AvailableBlock, AvailableBlockData}; | ||
| use crate::payload_envelope_verification::AvailableEnvelope; | ||
| use crate::{BeaconChain, BeaconChainTypes, WhenSlotSkipped, metrics}; | ||
| use fixed_bytes::FixedBytesExtended; | ||
| use itertools::Itertools; | ||
|
|
@@ -15,6 +16,12 @@ use strum::IntoStaticStr; | |
| use tracing::{debug, debug_span, instrument}; | ||
| use types::{Hash256, Slot}; | ||
|
|
||
| /// An available block together with its optional Gloas payload envelope, as produced by | ||
| /// `RangeSyncBlock::into_available_block` and consumed by `import_historical_block_batch`. | ||
| /// | ||
| /// The envelope is `None` for pre-Gloas blocks (and for Gloas blocks with no payload data). | ||
| pub type AvailableBlockWithEnvelope<E> = (AvailableBlock<E>, Option<AvailableEnvelope<E>>); | ||
|
Member
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. We have a RangeSyncBlock with a gloas variant that you should use instead |
||
|
|
||
| /// Use a longer timeout on the pubkey cache. | ||
| /// | ||
| /// It's ok if historical sync is stalled due to writes from forwards block processing. | ||
|
|
@@ -37,6 +44,9 @@ pub enum HistoricalBlockError { | |
| IndexOutOfBounds, | ||
| /// Logic error: should never occur. | ||
| MissingOldestBlockRoot { slot: Slot }, | ||
| /// A Gloas block that expects blob data was provided without its payload envelope, so the | ||
| /// required data columns cannot be verified or persisted. Caller should retry/penalize. | ||
| MissingEnvelope { block_root: Hash256 }, | ||
| /// Internal store error | ||
| StoreError(StoreError), | ||
| } | ||
|
|
@@ -70,7 +80,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> { | |
| #[instrument(skip_all)] | ||
| pub fn import_historical_block_batch( | ||
| &self, | ||
| mut blocks: Vec<AvailableBlock<T::EthSpec>>, | ||
| mut blocks: Vec<AvailableBlockWithEnvelope<T::EthSpec>>, | ||
| ) -> Result<usize, HistoricalBlockError> { | ||
| let anchor_info = self.store.get_anchor_info(); | ||
| let blob_info = self.store.get_blob_info(); | ||
|
|
@@ -80,7 +90,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> { | |
| // | ||
| // This allows for reimport of the blobs/columns for the finalized block after checkpoint | ||
| // sync. | ||
| let num_relevant = blocks.partition_point(|available_block| { | ||
| let num_relevant = blocks.partition_point(|(available_block, _envelope)| { | ||
| available_block.block().slot() <= anchor_info.oldest_block_slot | ||
| }); | ||
|
|
||
|
|
@@ -107,12 +117,42 @@ impl<T: BeaconChainTypes> BeaconChain<T> { | |
| let mut new_oldest_blob_slot = blob_info.oldest_blob_slot; | ||
| let mut new_oldest_data_column_slot = data_column_info.oldest_data_column_slot; | ||
|
|
||
| // Track the child block's bid `parent_block_hash` while iterating backwards, in order to | ||
| // determine each Gloas block's payload status. Per `process_parent_execution_payload` in | ||
| // the spec, a block's payload was revealed on chain (the block is "full") iff its child's | ||
| // bid `parent_block_hash` equals its own bid `block_hash`. A withheld ("empty") payload | ||
| // never has an envelope or data columns, so none can be required during backfill. | ||
| // | ||
| // Initialize from the current anchor block, which is the child of the newest block in the | ||
| // batch. If the newest block *is* the anchor block being re-imported, this yields a | ||
| // self-comparison that is always false, making its envelope optional — its data was | ||
| // already stored during checkpoint sync. | ||
| let mut child_bid_parent_hash = blocks_to_import | ||
| .last() | ||
| .filter(|(available_block, _envelope)| { | ||
| available_block.block().fork_name_unchecked().gloas_enabled() | ||
| }) | ||
| .and_then(|_| { | ||
| self.block_root_at_slot(anchor_info.oldest_block_slot, WhenSlotSkipped::None) | ||
| .ok() | ||
| .flatten() | ||
| }) | ||
| .and_then(|root| self.get_blinded_block(&root).ok().flatten()) | ||
| .and_then(|child_block| { | ||
| child_block | ||
| .message() | ||
| .body() | ||
| .signed_execution_payload_bid() | ||
| .ok() | ||
| .map(|bid| bid.message.parent_block_hash) | ||
| }); | ||
|
|
||
| let mut blob_batch = Vec::<KeyValueStoreOp>::new(); | ||
| let mut cold_batch = Vec::with_capacity(blocks_to_import.len()); | ||
| let mut hot_batch = Vec::with_capacity(blocks_to_import.len()); | ||
| let mut signed_blocks = Vec::with_capacity(blocks_to_import.len()); | ||
|
|
||
| for available_block in blocks_to_import.into_iter().rev() { | ||
| for (available_block, envelope) in blocks_to_import.into_iter().rev() { | ||
| let (block_root, block, block_data) = available_block.deconstruct(); | ||
|
|
||
| if block.slot() == anchor_info.oldest_block_slot { | ||
|
|
@@ -171,6 +211,54 @@ impl<T: BeaconChainTypes> BeaconChain<T> { | |
| blob_batch.extend(self.store.convert_to_kv_batch(vec![op])?); | ||
| } | ||
|
|
||
| // Whether this block's execution payload was revealed on chain ("full" block). Only | ||
| // ever true for Gloas blocks, as earlier forks have no bid. See the comment on | ||
| // `child_bid_parent_hash` above. | ||
| let payload_revealed = block | ||
| .message() | ||
| .body() | ||
| .signed_execution_payload_bid() | ||
| .ok() | ||
| .zip(child_bid_parent_hash) | ||
| .is_some_and(|(bid, child_parent_hash)| { | ||
| bid.message.block_hash == child_parent_hash | ||
| }); | ||
|
|
||
| // Persist the Gloas payload envelope and its data columns. For Gloas blocks the data | ||
| // columns are carried by the envelope rather than the block's `block_data`, so they | ||
| // must be stored from here. | ||
| match envelope { | ||
| Some(envelope) => { | ||
| let (signed_envelope, columns) = envelope.deconstruct(); | ||
| if !columns.is_empty() { | ||
| new_oldest_data_column_slot = Some(block.slot()); | ||
| if let Some(op) = self.get_blobs_or_columns_store_op( | ||
| block_root, | ||
| block.slot(), | ||
| AvailableBlockData::DataColumns(columns), | ||
| ) { | ||
| blob_batch.extend(self.store.convert_to_kv_batch(vec![op])?); | ||
| } | ||
| } | ||
| self.store.payload_envelope_as_kv_store_ops( | ||
| &block_root, | ||
| &signed_envelope, | ||
| &mut hot_batch, | ||
| ); | ||
| } | ||
| None => { | ||
| // A Gloas block whose payload was revealed must be accompanied by its | ||
| // envelope: the spec requires envelopes to be served over the same retention | ||
| // window as blocks, and we must persist it to serve it over RPC and for | ||
| // state reconstruction — even when it carries no blobs. Blocks with withheld | ||
| // ("empty") payloads never have an envelope, and pre-Gloas blocks carry | ||
| // their blob data in `block_data`. | ||
| if payload_revealed { | ||
| return Err(HistoricalBlockError::MissingEnvelope { block_root }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Store block roots, including at all skip slots in the freezer DB. | ||
| for slot in (block.slot().as_u64()..prev_block_slot.as_u64()).rev() { | ||
| debug!(%slot, ?block_root, "Storing frozen block to root mapping"); | ||
|
|
@@ -183,6 +271,13 @@ impl<T: BeaconChainTypes> BeaconChain<T> { | |
|
|
||
| prev_block_slot = block.slot(); | ||
| expected_block_root = block.message().parent_root(); | ||
| // This block is the child of the next (older) block in the iteration. | ||
| child_bid_parent_hash = block | ||
| .message() | ||
| .body() | ||
| .signed_execution_payload_bid() | ||
| .ok() | ||
| .map(|bid| bid.message.parent_block_hash); | ||
| signed_blocks.push(block); | ||
|
|
||
| // If we've reached genesis, add the genesis block root to the batch for all slots | ||
|
|
||
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.
AvailableBlock isn't really a concept post-gloas (blocks are always available by default). Once you move to
RangeSyncBlockthis should probably change toSignedBeaconBlock