-
Notifications
You must be signed in to change notification settings - Fork 810
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
Generalize block available time metric for PeerDAS #6850
Open
dapplion
wants to merge
1
commit into
sigp:unstable
Choose a base branch
from
dapplion:observed-times-peerdas
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.
+61
−16
Open
Changes from all commits
Commits
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 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 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 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ use ssz_derive::{Decode, Encode}; | |
use std::iter; | ||
use std::marker::PhantomData; | ||
use std::sync::Arc; | ||
use std::time::Duration; | ||
use types::data_column_sidecar::{ColumnIndex, DataColumnIdentifier}; | ||
use types::{ | ||
BeaconStateError, ChainSpec, DataColumnSidecar, DataColumnSubnetId, EthSpec, Hash256, | ||
|
@@ -233,11 +234,17 @@ impl<T: BeaconChainTypes, O: ObservationStrategy> GossipVerifiedDataColumn<T, O> | |
#[ssz(struct_behaviour = "transparent")] | ||
pub struct KzgVerifiedDataColumn<E: EthSpec> { | ||
data: Arc<DataColumnSidecar<E>>, | ||
#[ssz(skip_serializing, skip_deserializing)] | ||
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. Do we still need |
||
seen_timestamp: Duration, | ||
} | ||
|
||
impl<E: EthSpec> KzgVerifiedDataColumn<E> { | ||
pub fn new(data_column: Arc<DataColumnSidecar<E>>, kzg: &Kzg) -> Result<Self, KzgError> { | ||
verify_kzg_for_data_column(data_column, kzg) | ||
pub fn new( | ||
data_column: Arc<DataColumnSidecar<E>>, | ||
kzg: &Kzg, | ||
seen_timestamp: Duration, | ||
) -> Result<Self, KzgError> { | ||
verify_kzg_for_data_column(data_column, kzg, seen_timestamp) | ||
} | ||
pub fn to_data_column(self) -> Arc<DataColumnSidecar<E>> { | ||
self.data | ||
|
@@ -293,29 +300,38 @@ impl<E: EthSpec> CustodyDataColumn<E> { | |
#[ssz(struct_behaviour = "transparent")] | ||
pub struct KzgVerifiedCustodyDataColumn<E: EthSpec> { | ||
data: Arc<DataColumnSidecar<E>>, | ||
#[ssz(skip_serializing, skip_deserializing)] | ||
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. sam as above |
||
seen_timestamp: Duration, | ||
} | ||
|
||
impl<E: EthSpec> KzgVerifiedCustodyDataColumn<E> { | ||
/// Mark a column as custody column. Caller must ensure that our current custody requirements | ||
/// include this column | ||
pub fn from_asserted_custody(kzg_verified: KzgVerifiedDataColumn<E>) -> Self { | ||
Self { | ||
seen_timestamp: kzg_verified.seen_timestamp, | ||
data: kzg_verified.to_data_column(), | ||
} | ||
} | ||
|
||
/// Verify a column already marked as custody column | ||
pub fn new(data_column: CustodyDataColumn<E>, kzg: &Kzg) -> Result<Self, KzgError> { | ||
verify_kzg_for_data_column(data_column.clone_arc(), kzg)?; | ||
pub fn new( | ||
data_column: CustodyDataColumn<E>, | ||
kzg: &Kzg, | ||
seen_timestamp: Duration, | ||
) -> Result<Self, KzgError> { | ||
verify_kzg_for_data_column(data_column.clone_arc(), kzg, seen_timestamp)?; | ||
Ok(Self { | ||
data: data_column.data, | ||
seen_timestamp, | ||
}) | ||
} | ||
|
||
pub fn reconstruct_columns( | ||
kzg: &Kzg, | ||
partial_set_of_columns: &[Self], | ||
spec: &ChainSpec, | ||
seen_timestamp: Duration, | ||
) -> Result<Vec<KzgVerifiedCustodyDataColumn<E>>, KzgError> { | ||
let all_data_columns = reconstruct_data_columns( | ||
kzg, | ||
|
@@ -329,7 +345,10 @@ impl<E: EthSpec> KzgVerifiedCustodyDataColumn<E> { | |
Ok(all_data_columns | ||
.into_iter() | ||
.map(|data| { | ||
KzgVerifiedCustodyDataColumn::from_asserted_custody(KzgVerifiedDataColumn { data }) | ||
KzgVerifiedCustodyDataColumn::from_asserted_custody(KzgVerifiedDataColumn { | ||
data, | ||
seen_timestamp, | ||
}) | ||
}) | ||
.collect::<Vec<_>>()) | ||
} | ||
|
@@ -347,6 +366,10 @@ impl<E: EthSpec> KzgVerifiedCustodyDataColumn<E> { | |
pub fn index(&self) -> ColumnIndex { | ||
self.data.index | ||
} | ||
|
||
pub fn seen_timestamp(&self) -> Duration { | ||
self.seen_timestamp | ||
} | ||
} | ||
|
||
/// Complete kzg verification for a `DataColumnSidecar`. | ||
|
@@ -355,10 +378,14 @@ impl<E: EthSpec> KzgVerifiedCustodyDataColumn<E> { | |
pub fn verify_kzg_for_data_column<E: EthSpec>( | ||
data_column: Arc<DataColumnSidecar<E>>, | ||
kzg: &Kzg, | ||
seen_timestamp: Duration, | ||
) -> Result<KzgVerifiedDataColumn<E>, KzgError> { | ||
let _timer = metrics::start_timer(&metrics::KZG_VERIFICATION_DATA_COLUMN_SINGLE_TIMES); | ||
validate_data_columns(kzg, iter::once(&data_column))?; | ||
Ok(KzgVerifiedDataColumn { data: data_column }) | ||
Ok(KzgVerifiedDataColumn { | ||
data: data_column, | ||
seen_timestamp, | ||
}) | ||
} | ||
|
||
/// Complete kzg verification for a list of `DataColumnSidecar`s. | ||
|
@@ -383,6 +410,7 @@ pub fn validate_data_column_sidecar_for_gossip<T: BeaconChainTypes, O: Observati | |
subnet: u64, | ||
chain: &BeaconChain<T>, | ||
) -> Result<GossipVerifiedDataColumn<T, O>, GossipDataColumnError> { | ||
let seen_timestamp = chain.slot_clock.now_duration().unwrap_or_default(); | ||
let column_slot = data_column.slot(); | ||
verify_data_column_sidecar(&data_column, &chain.spec)?; | ||
verify_index_matches_subnet(&data_column, subnet, &chain.spec)?; | ||
|
@@ -394,8 +422,9 @@ pub fn validate_data_column_sidecar_for_gossip<T: BeaconChainTypes, O: Observati | |
verify_slot_higher_than_parent(&parent_block, column_slot)?; | ||
verify_proposer_and_signature(&data_column, &parent_block, chain)?; | ||
let kzg = &chain.kzg; | ||
let kzg_verified_data_column = verify_kzg_for_data_column(data_column.clone(), kzg) | ||
.map_err(GossipDataColumnError::InvalidKzgProof)?; | ||
let kzg_verified_data_column = | ||
verify_kzg_for_data_column(data_column.clone(), kzg, seen_timestamp) | ||
.map_err(GossipDataColumnError::InvalidKzgProof)?; | ||
|
||
chain | ||
.observed_slashable | ||
|
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.
On one hand I think would be a bit more consistent if we put it after reconstruction, and right before we add the columns to
put_kzg_verified_data_columns
, similar to elsewhere; On the other hand, we can argue that we have these columns once we see the last column that triggered reconstruction. I don't see an issue going either way.One scenario i can think of is -
now
now + t
now + t
, not the reconstructed columns that made the block available.Another scenario
now
now + t
make_available
again here (bug), but it doesnt change the last seem timestamp, stillnow + t
(bug issue: #6439)
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.
Not suggesting a change here - but if you think it makes sense to use the timestamp before reconstruction (i.e. the last data column that triggered reconstruction to make this block available), we can remove this TODO