Skip to content

Commit 629d054

Browse files
committed
Remove CGC from data_availability checker
1 parent cf4104a commit 629d054

File tree

17 files changed

+202
-171
lines changed

17 files changed

+202
-171
lines changed

beacon_node/beacon_chain/src/beacon_chain.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2993,6 +2993,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
29932993
pub async fn verify_block_for_gossip(
29942994
self: &Arc<Self>,
29952995
block: Arc<SignedBeaconBlock<T::EthSpec>>,
2996+
custody_columns_count: usize,
29962997
) -> Result<GossipVerifiedBlock<T>, BlockError> {
29972998
let chain = self.clone();
29982999
self.task_executor
@@ -3002,7 +3003,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
30023003
let slot = block.slot();
30033004
let graffiti_string = block.message().body().graffiti().as_utf8_lossy();
30043005

3005-
match GossipVerifiedBlock::new(block, &chain) {
3006+
match GossipVerifiedBlock::new(block, &chain, custody_columns_count) {
30063007
Ok(verified) => {
30073008
let commitments_formatted = verified.block.commitments_formatted();
30083009
debug!(
@@ -7224,10 +7225,6 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
72247225
block_root: Hash256,
72257226
block_data: AvailableBlockData<T::EthSpec>,
72267227
) -> Result<Option<StoreOp<T::EthSpec>>, String> {
7227-
// TODO(das) we currently store all subnet sampled columns. Tracking issue to exclude non
7228-
// custody columns: https://github.com/sigp/lighthouse/issues/6465
7229-
let _custody_columns_count = self.data_availability_checker.get_sampling_column_count();
7230-
72317228
match block_data {
72327229
AvailableBlockData::NoData => Ok(None),
72337230
AvailableBlockData::Blobs(blobs) => {

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ pub struct GossipVerifiedBlock<T: BeaconChainTypes> {
680680
pub block_root: Hash256,
681681
parent: Option<PreProcessingSnapshot<T::EthSpec>>,
682682
consensus_context: ConsensusContext<T::EthSpec>,
683+
custody_columns_count: usize,
683684
}
684685

685686
/// A wrapper around a `SignedBeaconBlock` that indicates that all signatures (except the deposit
@@ -715,6 +716,7 @@ pub trait IntoGossipVerifiedBlock<T: BeaconChainTypes>: Sized {
715716
fn into_gossip_verified_block(
716717
self,
717718
chain: &BeaconChain<T>,
719+
custody_columns_count: usize,
718720
) -> Result<GossipVerifiedBlock<T>, BlockError>;
719721
fn inner_block(&self) -> Arc<SignedBeaconBlock<T::EthSpec>>;
720722
}
@@ -723,6 +725,7 @@ impl<T: BeaconChainTypes> IntoGossipVerifiedBlock<T> for GossipVerifiedBlock<T>
723725
fn into_gossip_verified_block(
724726
self,
725727
_chain: &BeaconChain<T>,
728+
_custody_columns_count: usize,
726729
) -> Result<GossipVerifiedBlock<T>, BlockError> {
727730
Ok(self)
728731
}
@@ -735,8 +738,9 @@ impl<T: BeaconChainTypes> IntoGossipVerifiedBlock<T> for Arc<SignedBeaconBlock<T
735738
fn into_gossip_verified_block(
736739
self,
737740
chain: &BeaconChain<T>,
741+
custody_columns_count: usize,
738742
) -> Result<GossipVerifiedBlock<T>, BlockError> {
739-
GossipVerifiedBlock::new(self, chain)
743+
GossipVerifiedBlock::new(self, chain, custody_columns_count)
740744
}
741745

742746
fn inner_block(&self) -> Arc<SignedBeaconBlock<T::EthSpec>> {
@@ -805,6 +809,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
805809
pub fn new(
806810
block: Arc<SignedBeaconBlock<T::EthSpec>>,
807811
chain: &BeaconChain<T>,
812+
custody_columns_count: usize,
808813
) -> Result<Self, BlockError> {
809814
// If the block is valid for gossip we don't supply it to the slasher here because
810815
// we assume it will be transformed into a fully verified block. We *do* need to supply
@@ -814,19 +819,22 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
814819
// The `SignedBeaconBlock` and `SignedBeaconBlockHeader` have the same canonical root,
815820
// but it's way quicker to calculate root of the header since the hash of the tree rooted
816821
// at `BeaconBlockBody` is already computed in the header.
817-
Self::new_without_slasher_checks(block, &header, chain).map_err(|e| {
818-
process_block_slash_info::<_, BlockError>(
819-
chain,
820-
BlockSlashInfo::from_early_error_block(header, e),
821-
)
822-
})
822+
Self::new_without_slasher_checks(block, &header, chain, custody_columns_count).map_err(
823+
|e| {
824+
process_block_slash_info::<_, BlockError>(
825+
chain,
826+
BlockSlashInfo::from_early_error_block(header, e),
827+
)
828+
},
829+
)
823830
}
824831

825832
/// As for new, but doesn't pass the block to the slasher.
826833
fn new_without_slasher_checks(
827834
block: Arc<SignedBeaconBlock<T::EthSpec>>,
828835
block_header: &SignedBeaconBlockHeader,
829836
chain: &BeaconChain<T>,
837+
custody_columns_count: usize,
830838
) -> Result<Self, BlockError> {
831839
// Ensure the block is the correct structure for the fork at `block.slot()`.
832840
block
@@ -1031,6 +1039,7 @@ impl<T: BeaconChainTypes> GossipVerifiedBlock<T> {
10311039
block_root,
10321040
parent,
10331041
consensus_context,
1042+
custody_columns_count,
10341043
})
10351044
}
10361045

@@ -1175,6 +1184,7 @@ impl<T: BeaconChainTypes> SignatureVerifiedBlock<T> {
11751184
block: MaybeAvailableBlock::AvailabilityPending {
11761185
block_root: from.block_root,
11771186
block,
1187+
custody_columns_count: from.custody_columns_count,
11781188
},
11791189
block_root: from.block_root,
11801190
parent: Some(parent),

beacon_node/beacon_chain/src/block_verification_types.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ use types::{
3131
pub struct RpcBlock<E: EthSpec> {
3232
block_root: Hash256,
3333
block: RpcBlockInner<E>,
34+
custody_columns_count: usize,
3435
}
3536

3637
impl<E: EthSpec> Debug for RpcBlock<E> {
@@ -44,6 +45,10 @@ impl<E: EthSpec> RpcBlock<E> {
4445
self.block_root
4546
}
4647

48+
pub fn custody_columns_count(&self) -> usize {
49+
self.custody_columns_count
50+
}
51+
4752
pub fn as_block(&self) -> &SignedBeaconBlock<E> {
4853
match &self.block {
4954
RpcBlockInner::Block(block) => block,
@@ -104,6 +109,8 @@ impl<E: EthSpec> RpcBlock<E> {
104109
Self {
105110
block_root,
106111
block: RpcBlockInner::Block(block),
112+
// Block has zero columns
113+
custody_columns_count: 0,
107114
}
108115
}
109116

@@ -145,13 +152,16 @@ impl<E: EthSpec> RpcBlock<E> {
145152
Ok(Self {
146153
block_root,
147154
block: inner,
155+
// Block is before PeerDAS
156+
custody_columns_count: 0,
148157
})
149158
}
150159

151160
pub fn new_with_custody_columns(
152161
block_root: Option<Hash256>,
153162
block: Arc<SignedBeaconBlock<E>>,
154163
custody_columns: Vec<CustodyDataColumn<E>>,
164+
custody_columns_count: usize,
155165
spec: &ChainSpec,
156166
) -> Result<Self, AvailabilityCheckError> {
157167
let block_root = block_root.unwrap_or_else(|| get_block_root(&block));
@@ -172,6 +182,7 @@ impl<E: EthSpec> RpcBlock<E> {
172182
Ok(Self {
173183
block_root,
174184
block: inner,
185+
custody_columns_count,
175186
})
176187
}
177188

@@ -239,10 +250,12 @@ impl<E: EthSpec> ExecutedBlock<E> {
239250
MaybeAvailableBlock::AvailabilityPending {
240251
block_root: _,
241252
block: pending_block,
253+
custody_columns_count,
242254
} => Self::AvailabilityPending(AvailabilityPendingExecutedBlock::new(
243255
pending_block,
244256
import_data,
245257
payload_verification_outcome,
258+
custody_columns_count,
246259
)),
247260
}
248261
}
@@ -308,18 +321,21 @@ pub struct AvailabilityPendingExecutedBlock<E: EthSpec> {
308321
pub block: Arc<SignedBeaconBlock<E>>,
309322
pub import_data: BlockImportData<E>,
310323
pub payload_verification_outcome: PayloadVerificationOutcome,
324+
pub custody_columns_count: usize,
311325
}
312326

313327
impl<E: EthSpec> AvailabilityPendingExecutedBlock<E> {
314328
pub fn new(
315329
block: Arc<SignedBeaconBlock<E>>,
316330
import_data: BlockImportData<E>,
317331
payload_verification_outcome: PayloadVerificationOutcome,
332+
custody_columns_count: usize,
318333
) -> Self {
319334
Self {
320335
block,
321336
import_data,
322337
payload_verification_outcome,
338+
custody_columns_count,
323339
}
324340
}
325341

@@ -439,19 +455,13 @@ impl<E: EthSpec> AsBlock<E> for MaybeAvailableBlock<E> {
439455
fn as_block(&self) -> &SignedBeaconBlock<E> {
440456
match &self {
441457
MaybeAvailableBlock::Available(block) => block.as_block(),
442-
MaybeAvailableBlock::AvailabilityPending {
443-
block_root: _,
444-
block,
445-
} => block,
458+
MaybeAvailableBlock::AvailabilityPending { block, .. } => block,
446459
}
447460
}
448461
fn block_cloned(&self) -> Arc<SignedBeaconBlock<E>> {
449462
match &self {
450463
MaybeAvailableBlock::Available(block) => block.block_cloned(),
451-
MaybeAvailableBlock::AvailabilityPending {
452-
block_root: _,
453-
block,
454-
} => block.clone(),
464+
MaybeAvailableBlock::AvailabilityPending { block, .. } => block.clone(),
455465
}
456466
}
457467
fn canonical_root(&self) -> Hash256 {

beacon_node/beacon_chain/src/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,6 @@ where
10081008
slot_clock,
10091009
self.kzg.clone(),
10101010
store,
1011-
self.import_all_data_columns,
10121011
self.spec,
10131012
log.new(o!("service" => "data_availability_checker")),
10141013
)

beacon_node/beacon_chain/src/data_availability_checker.rs

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,10 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
112112
slot_clock: T::SlotClock,
113113
kzg: Arc<Kzg>,
114114
store: BeaconStore<T>,
115-
import_all_data_columns: bool,
116115
spec: Arc<ChainSpec>,
117116
log: Logger,
118117
) -> Result<Self, AvailabilityCheckError> {
119-
let custody_group_count = spec.custody_group_count(import_all_data_columns);
120-
// This should only panic if the chain spec contains invalid values.
121-
let sampling_size = spec
122-
.sampling_size(custody_group_count)
123-
.expect("should compute node sampling size from valid chain spec");
124-
125-
let inner = DataAvailabilityCheckerInner::new(
126-
OVERFLOW_LRU_CAPACITY,
127-
store,
128-
sampling_size as usize,
129-
spec.clone(),
130-
)?;
118+
let inner = DataAvailabilityCheckerInner::new(OVERFLOW_LRU_CAPACITY, store, spec.clone())?;
131119
Ok(Self {
132120
availability_cache: Arc::new(inner),
133121
slot_clock,
@@ -137,14 +125,6 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
137125
})
138126
}
139127

140-
pub fn get_sampling_column_count(&self) -> usize {
141-
self.availability_cache.sampling_column_count()
142-
}
143-
144-
pub(crate) fn is_supernode(&self) -> bool {
145-
self.get_sampling_column_count() == self.spec.number_of_columns as usize
146-
}
147-
148128
/// Checks if the block root is currenlty in the availability cache awaiting import because
149129
/// of missing components.
150130
pub fn get_execution_valid_block(
@@ -340,6 +320,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
340320
&self,
341321
block: RpcBlock<T::EthSpec>,
342322
) -> Result<MaybeAvailableBlock<T::EthSpec>, AvailabilityCheckError> {
323+
let custody_columns_count = block.custody_columns_count();
343324
let (block_root, block, blobs, data_columns) = block.deconstruct();
344325
if self.blobs_required_for_block(&block) {
345326
return if let Some(blob_list) = blobs {
@@ -353,7 +334,11 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
353334
spec: self.spec.clone(),
354335
}))
355336
} else {
356-
Ok(MaybeAvailableBlock::AvailabilityPending { block_root, block })
337+
Ok(MaybeAvailableBlock::AvailabilityPending {
338+
block_root,
339+
block,
340+
custody_columns_count,
341+
})
357342
};
358343
}
359344
if self.data_columns_required_for_block(&block) {
@@ -378,7 +363,11 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
378363
spec: self.spec.clone(),
379364
}))
380365
} else {
381-
Ok(MaybeAvailableBlock::AvailabilityPending { block_root, block })
366+
Ok(MaybeAvailableBlock::AvailabilityPending {
367+
block_root,
368+
block,
369+
custody_columns_count,
370+
})
382371
};
383372
}
384373

@@ -435,6 +424,7 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
435424
}
436425

437426
for block in blocks {
427+
let custody_columns_count = block.custody_columns_count();
438428
let (block_root, block, blobs, data_columns) = block.deconstruct();
439429

440430
let maybe_available_block = if self.blobs_required_for_block(&block) {
@@ -447,7 +437,11 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
447437
spec: self.spec.clone(),
448438
})
449439
} else {
450-
MaybeAvailableBlock::AvailabilityPending { block_root, block }
440+
MaybeAvailableBlock::AvailabilityPending {
441+
block_root,
442+
block,
443+
custody_columns_count,
444+
}
451445
}
452446
} else if self.data_columns_required_for_block(&block) {
453447
if let Some(data_columns) = data_columns {
@@ -461,7 +455,11 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
461455
spec: self.spec.clone(),
462456
})
463457
} else {
464-
MaybeAvailableBlock::AvailabilityPending { block_root, block }
458+
MaybeAvailableBlock::AvailabilityPending {
459+
block_root,
460+
block,
461+
custody_columns_count,
462+
}
465463
}
466464
} else {
467465
MaybeAvailableBlock::Available(AvailableBlock {
@@ -817,6 +815,7 @@ pub enum MaybeAvailableBlock<E: EthSpec> {
817815
AvailabilityPending {
818816
block_root: Hash256,
819817
block: Arc<SignedBeaconBlock<E>>,
818+
custody_columns_count: usize,
820819
},
821820
}
822821

0 commit comments

Comments
 (0)