Skip to content

Commit

Permalink
Fix failing test and add verify inclusion test.
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmygchen committed May 15, 2024
1 parent 6c95821 commit 768e24f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 24 deletions.
23 changes: 5 additions & 18 deletions beacon_node/beacon_chain/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2584,26 +2584,13 @@ pub fn generate_rand_block_and_data_columns<E: EthSpec>(
rng: &mut impl Rng,
) -> (
SignedBeaconBlock<E, FullPayload<E>>,
Vec<DataColumnSidecar<E>>,
Vec<Arc<DataColumnSidecar<E>>>,
) {
let (block, blobs) = generate_rand_block_and_blobs(fork_name, num_blobs, rng);
let blob = blobs.first().expect("should have at least 1 blob");

let data_columns = (0..E::number_of_columns())
.map(|index| DataColumnSidecar {
index: index as u64,
column: <_>::default(),
kzg_commitments: block
.message()
.body()
.blob_kzg_commitments()
.unwrap()
.clone(),
kzg_proofs: (vec![]).into(),
signed_block_header: blob.signed_block_header.clone(),
kzg_commitments_inclusion_proof: <_>::default(),
})
.collect::<Vec<_>>();
let blob: BlobsList<E> = blobs.into_iter().map(|b| b.blob).collect::<Vec<_>>().into();
let data_columns = DataColumnSidecar::build_sidecars(&blob, &block, &KZG)
.unwrap()
.into();

(block, data_columns)
}
14 changes: 8 additions & 6 deletions beacon_node/network/src/sync/block_lookups/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ impl TestRig {
generate_rand_block_and_blobs::<E>(fork_name, num_blobs, rng)
}

fn rand_block_and_data_columns(&mut self) -> (SignedBeaconBlock<E>, Vec<DataColumnSidecar<E>>) {
fn rand_block_and_data_columns(
&mut self,
) -> (SignedBeaconBlock<E>, Vec<Arc<DataColumnSidecar<E>>>) {
let num_blobs = NumBlobs::Number(1);
generate_rand_block_and_data_columns::<E>(self.fork_name, num_blobs, &mut self.rng)
}
Expand Down Expand Up @@ -640,7 +642,7 @@ impl TestRig {
fn complete_valid_sampling_column_requests(
&mut self,
sampling_ids: SamplingIds,
data_columns: Vec<DataColumnSidecar<E>>,
data_columns: Vec<Arc<DataColumnSidecar<E>>>,
) {
for (id, column_index) in sampling_ids {
self.log(&format!("return valid data column for {column_index}"));
Expand All @@ -654,7 +656,7 @@ impl TestRig {
fn complete_valid_sampling_column_request(
&mut self,
id: DataColumnsByRootRequestId,
data_column: DataColumnSidecar<E>,
data_column: Arc<DataColumnSidecar<E>>,
) {
let block_root = data_column.block_root();
let column_index = data_column.index;
Expand All @@ -677,7 +679,7 @@ impl TestRig {
fn complete_valid_custody_request(
&mut self,
sampling_ids: SamplingIds,
data_columns: Vec<DataColumnSidecar<E>>,
data_columns: Vec<Arc<DataColumnSidecar<E>>>,
missing_components: bool,
) {
let lookup_id = if let DataColumnsByRootRequester::Custody(id) =
Expand Down Expand Up @@ -720,14 +722,14 @@ impl TestRig {
fn complete_data_columns_by_root_request(
&mut self,
id: DataColumnsByRootRequestId,
data_column: DataColumnSidecar<E>,
data_column: Arc<DataColumnSidecar<E>>,
) {
let peer_id = PeerId::random();
// Send chunk
self.send_sync_message(SyncMessage::RpcDataColumn {
request_id: SyncRequestId::DataColumnsByRoot(id),
peer_id,
data_column: Some(Arc::new(data_column)),
data_column: Some(data_column),
seen_timestamp: timestamp_now(),
});
// Send stream termination
Expand Down
1 change: 1 addition & 0 deletions consensus/types/src/data_column_sidecar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ mod test {
col_sidecar.kzg_commitments_inclusion_proof,
block_kzg_commitments_inclusion_proof
);
assert!(col_sidecar.verify_inclusion_proof());
}
}

Expand Down

0 comments on commit 768e24f

Please sign in to comment.