Skip to content

Commit b4704ea

Browse files
authored
Fulu update to spec v1.6.0-alpha.4 (#7890)
Fulu update to spec [v1.6.0-alpha.4](https://github.com/ethereum/consensus-specs/releases/tag/v1.6.0-alpha.4). - Make `number_of_columns` a preset - Optimise `get_custody_groups` to avoid computing if cgc = 128 - Add support for additional typenum values in type_dispatch macro
1 parent 95882bf commit b4704ea

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+214
-400
lines changed

beacon_node/beacon_chain/benches/benches.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ use criterion::{Criterion, black_box, criterion_group, criterion_main};
77
use bls::Signature;
88
use kzg::{KzgCommitment, KzgProof};
99
use types::{
10-
BeaconBlock, BeaconBlockDeneb, Blob, BlobsList, ChainSpec, EmptyBlock, EthSpec, KzgProofs,
10+
BeaconBlock, BeaconBlockFulu, Blob, BlobsList, ChainSpec, EmptyBlock, EthSpec, KzgProofs,
1111
MainnetEthSpec, SignedBeaconBlock, beacon_block_body::KzgCommitments,
1212
};
1313

1414
fn create_test_block_and_blobs<E: EthSpec>(
1515
num_of_blobs: usize,
1616
spec: &ChainSpec,
1717
) -> (SignedBeaconBlock<E>, BlobsList<E>, KzgProofs<E>) {
18-
let mut block = BeaconBlock::Deneb(BeaconBlockDeneb::empty(spec));
18+
let mut block = BeaconBlock::Fulu(BeaconBlockFulu::empty(spec));
1919
let mut body = block.body_mut();
2020
let blob_kzg_commitments = body.blob_kzg_commitments_mut().unwrap();
2121
*blob_kzg_commitments =
@@ -27,7 +27,7 @@ fn create_test_block_and_blobs<E: EthSpec>(
2727
.map(|_| Blob::<E>::default())
2828
.collect::<Vec<_>>()
2929
.into();
30-
let proofs = vec![KzgProof::empty(); num_of_blobs * spec.number_of_columns as usize].into();
30+
let proofs = vec![KzgProof::empty(); num_of_blobs * E::number_of_columns()].into();
3131

3232
(signed_block, blobs, proofs)
3333
}

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1247,8 +1247,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
12471247

12481248
if self.spec.is_peer_das_enabled_for_epoch(block.epoch()) {
12491249
if let Some(columns) = self.store.get_data_columns(block_root)? {
1250-
let num_required_columns = self.spec.number_of_columns / 2;
1251-
let reconstruction_possible = columns.len() >= num_required_columns as usize;
1250+
let num_required_columns = T::EthSpec::number_of_columns() / 2;
1251+
let reconstruction_possible = columns.len() >= num_required_columns;
12521252
if reconstruction_possible {
12531253
reconstruct_blobs(&self.kzg, &columns, None, &block, &self.spec)
12541254
.map(Some)

beacon_node/beacon_chain/src/block_verification_types.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ pub use crate::data_availability_checker::{AvailableBlock, MaybeAvailableBlock};
33
use crate::data_column_verification::{CustodyDataColumn, CustodyDataColumnList};
44
use crate::{PayloadVerificationOutcome, get_block_root};
55
use derivative::Derivative;
6+
use ssz_types::VariableList;
67
use state_processing::ConsensusContext;
78
use std::fmt::{Debug, Formatter};
89
use std::sync::Arc;
910
use types::blob_sidecar::BlobIdentifier;
1011
use types::{
11-
BeaconBlockRef, BeaconState, BlindedPayload, BlobSidecarList, ChainSpec, Epoch, EthSpec,
12-
Hash256, RuntimeVariableList, SignedBeaconBlock, SignedBeaconBlockHeader, Slot,
12+
BeaconBlockRef, BeaconState, BlindedPayload, BlobSidecarList, Epoch, EthSpec, Hash256,
13+
SignedBeaconBlock, SignedBeaconBlockHeader, Slot,
1314
};
1415

1516
/// A block that has been received over RPC. It has 2 internal variants:
@@ -151,7 +152,6 @@ impl<E: EthSpec> RpcBlock<E> {
151152
block_root: Option<Hash256>,
152153
block: Arc<SignedBeaconBlock<E>>,
153154
custody_columns: Vec<CustodyDataColumn<E>>,
154-
spec: &ChainSpec,
155155
) -> Result<Self, AvailabilityCheckError> {
156156
let block_root = block_root.unwrap_or_else(|| get_block_root(&block));
157157

@@ -161,10 +161,7 @@ impl<E: EthSpec> RpcBlock<E> {
161161
}
162162
// Treat empty data column lists as if they are missing.
163163
let inner = if !custody_columns.is_empty() {
164-
RpcBlockInner::BlockAndCustodyColumns(
165-
block,
166-
RuntimeVariableList::new(custody_columns, spec.number_of_columns as usize)?,
167-
)
164+
RpcBlockInner::BlockAndCustodyColumns(block, VariableList::new(custody_columns)?)
168165
} else {
169166
RpcBlockInner::Block(block)
170167
};

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
446446
.map(CustodyDataColumn::into_inner)
447447
.collect::<Vec<_>>();
448448
let all_data_columns =
449-
RuntimeVariableList::from_vec(all_data_columns, self.spec.number_of_columns as usize);
449+
RuntimeVariableList::from_vec(all_data_columns, T::EthSpec::number_of_columns());
450450

451451
// verify kzg for all data columns at once
452452
if !all_data_columns.is_empty() {

beacon_node/beacon_chain/src/data_availability_checker/overflow_lru_cache.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<T: BeaconChainTypes> DataAvailabilityCheckerInner<T> {
591591
};
592592

593593
// If we're sampling all columns, it means we must be custodying all columns.
594-
let total_column_count = self.spec.number_of_columns as usize;
594+
let total_column_count = T::EthSpec::number_of_columns();
595595
let received_column_count = pending_components.verified_data_columns.len();
596596

597597
if pending_components.reconstruction_started {

beacon_node/beacon_chain/src/data_column_verification.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ use kzg::{Error as KzgError, Kzg};
1212
use proto_array::Block;
1313
use slot_clock::SlotClock;
1414
use ssz_derive::{Decode, Encode};
15+
use ssz_types::VariableList;
1516
use std::iter;
1617
use std::marker::PhantomData;
1718
use std::sync::Arc;
1819
use tracing::{debug, instrument};
1920
use types::data_column_sidecar::ColumnIndex;
2021
use types::{
2122
BeaconStateError, ChainSpec, DataColumnSidecar, DataColumnSubnetId, EthSpec, Hash256,
22-
RuntimeVariableList, SignedBeaconBlockHeader, Slot,
23+
SignedBeaconBlockHeader, Slot,
2324
};
2425

2526
/// An error occurred while validating a gossip data column.
@@ -315,7 +316,8 @@ impl<E: EthSpec> KzgVerifiedDataColumn<E> {
315316
}
316317
}
317318

318-
pub type CustodyDataColumnList<E> = RuntimeVariableList<CustodyDataColumn<E>>;
319+
pub type CustodyDataColumnList<E> =
320+
VariableList<CustodyDataColumn<E>, <E as EthSpec>::NumberOfColumns>;
319321

320322
/// Data column that we must custody
321323
#[derive(Debug, Derivative, Clone, Encode, Decode)]
@@ -479,7 +481,7 @@ pub fn validate_data_column_sidecar_for_gossip<T: BeaconChainTypes, O: Observati
479481
chain: &BeaconChain<T>,
480482
) -> Result<GossipVerifiedDataColumn<T, O>, GossipDataColumnError> {
481483
let column_slot = data_column.slot();
482-
verify_data_column_sidecar(&data_column, &chain.spec)?;
484+
verify_data_column_sidecar(&data_column)?;
483485
verify_index_matches_subnet(&data_column, subnet, &chain.spec)?;
484486
verify_sidecar_not_from_future_slot(chain, column_slot)?;
485487
verify_slot_greater_than_latest_finalized_slot(chain, column_slot)?;
@@ -533,9 +535,8 @@ pub fn validate_data_column_sidecar_for_gossip<T: BeaconChainTypes, O: Observati
533535
/// Verify if the data column sidecar is valid.
534536
fn verify_data_column_sidecar<E: EthSpec>(
535537
data_column: &DataColumnSidecar<E>,
536-
spec: &ChainSpec,
537538
) -> Result<(), GossipDataColumnError> {
538-
if data_column.index >= spec.number_of_columns {
539+
if data_column.index >= E::number_of_columns() as u64 {
539540
return Err(GossipDataColumnError::InvalidColumnIndex(data_column.index));
540541
}
541542
if data_column.kzg_commitments.is_empty() {

beacon_node/beacon_chain/src/kzg_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn blobs_to_data_column_sidecars<E: EthSpec>(
185185
let signed_block_header = block.signed_block_header();
186186

187187
let proof_chunks = cell_proofs
188-
.chunks_exact(spec.number_of_columns as usize)
188+
.chunks_exact(E::number_of_columns())
189189
.collect::<Vec<_>>();
190190

191191
// NOTE: assumes blob sidecars are ordered by index
@@ -243,7 +243,7 @@ pub(crate) fn build_data_column_sidecars<E: EthSpec>(
243243
blob_cells_and_proofs_vec: Vec<CellsAndKzgProofs>,
244244
spec: &ChainSpec,
245245
) -> Result<DataColumnSidecarList<E>, String> {
246-
let number_of_columns = spec.number_of_columns as usize;
246+
let number_of_columns = E::number_of_columns();
247247
let max_blobs_per_block = spec
248248
.max_blobs_per_block(signed_block_header.message.slot.epoch(E::slots_per_epoch()))
249249
as usize;
@@ -495,7 +495,7 @@ mod test {
495495
.kzg_commitments_merkle_proof()
496496
.unwrap();
497497

498-
assert_eq!(column_sidecars.len(), spec.number_of_columns as usize);
498+
assert_eq!(column_sidecars.len(), E::number_of_columns());
499499
for (idx, col_sidecar) in column_sidecars.iter().enumerate() {
500500
assert_eq!(col_sidecar.index, idx as u64);
501501

@@ -530,7 +530,7 @@ mod test {
530530
)
531531
.unwrap();
532532

533-
for i in 0..spec.number_of_columns as usize {
533+
for i in 0..E::number_of_columns() {
534534
assert_eq!(reconstructed_columns.get(i), column_sidecars.get(i), "{i}");
535535
}
536536
}

beacon_node/beacon_chain/src/observed_data_sidecars.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ impl<E: EthSpec> ObservableDataSidecar for DataColumnSidecar<E> {
5858
self.index
5959
}
6060

61-
fn max_num_of_items(spec: &ChainSpec, _slot: Slot) -> usize {
62-
spec.number_of_columns as usize
61+
fn max_num_of_items(_spec: &ChainSpec, _slot: Slot) -> usize {
62+
E::number_of_columns()
6363
}
6464
}
6565

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,8 +2358,7 @@ where
23582358
.into_iter()
23592359
.map(CustodyDataColumn::from_asserted_custody)
23602360
.collect::<Vec<_>>();
2361-
RpcBlock::new_with_custody_columns(Some(block_root), block, custody_columns, &self.spec)
2362-
.unwrap()
2361+
RpcBlock::new_with_custody_columns(Some(block_root), block, custody_columns).unwrap()
23632362
} else {
23642363
let blobs = self.chain.get_blobs(&block_root).unwrap().blobs();
23652364
RpcBlock::new(Some(block_root), block, blobs).unwrap()
@@ -2386,7 +2385,7 @@ where
23862385
.filter(|d| sampling_columns.contains(&d.index))
23872386
.map(CustodyDataColumn::from_asserted_custody)
23882387
.collect::<Vec<_>>();
2389-
RpcBlock::new_with_custody_columns(Some(block_root), block, columns, &self.spec)?
2388+
RpcBlock::new_with_custody_columns(Some(block_root), block, columns)?
23902389
} else {
23912390
RpcBlock::new_without_blobs(Some(block_root), block)
23922391
}
@@ -3310,7 +3309,7 @@ fn generate_data_column_sidecars_from_block<E: EthSpec>(
33103309
// load the precomputed column sidecar to avoid computing them for every block in the tests.
33113310
let template_data_columns = RuntimeVariableList::<DataColumnSidecar<E>>::from_ssz_bytes(
33123311
TEST_DATA_COLUMN_SIDECARS_SSZ,
3313-
spec.number_of_columns as usize,
3312+
E::number_of_columns(),
33143313
)
33153314
.unwrap();
33163315

beacon_node/beacon_chain/src/validator_custody.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<E: EthSpec> CustodyContext<E> {
197197
) -> Result<(), String> {
198198
let mut ordered_custody_columns = vec![];
199199
for custody_index in all_custody_groups_ordered {
200-
let columns = compute_columns_for_custody_group(custody_index, spec)
200+
let columns = compute_columns_for_custody_group::<E>(custody_index, spec)
201201
.map_err(|e| format!("Failed to compute columns for custody group {e:?}"))?;
202202
ordered_custody_columns.extend(columns);
203203
}
@@ -303,7 +303,7 @@ impl<E: EthSpec> CustodyContext<E> {
303303
/// Returns the count of columns this node must _sample_ for a block at `epoch` to import.
304304
pub fn num_of_data_columns_to_sample(&self, epoch: Epoch, spec: &ChainSpec) -> usize {
305305
let custody_group_count = self.custody_group_count_at_epoch(epoch, spec);
306-
spec.sampling_size_columns(custody_group_count)
306+
spec.sampling_size_columns::<E>(custody_group_count)
307307
.expect("should compute node sampling size from valid chain spec")
308308
}
309309

@@ -641,7 +641,7 @@ mod tests {
641641
let expected_sampling_columns = &all_custody_groups_ordered
642642
.iter()
643643
.flat_map(|custody_index| {
644-
compute_columns_for_custody_group(*custody_index, &spec)
644+
compute_columns_for_custody_group::<E>(*custody_index, &spec)
645645
.expect("should compute columns for custody group")
646646
})
647647
.collect::<Vec<_>>()[0..sampling_size];

0 commit comments

Comments
 (0)