@@ -2,14 +2,11 @@ use crate::blob_verification::{verify_kzg_for_blob_list, GossipVerifiedBlob, Kzg
2
2
use crate :: block_verification_types:: {
3
3
AvailabilityPendingExecutedBlock , AvailableExecutedBlock , RpcBlock ,
4
4
} ;
5
- pub use crate :: data_availability_checker:: child_components:: ChildComponents ;
6
5
use crate :: data_availability_checker:: overflow_lru_cache:: OverflowLRUCache ;
7
6
use crate :: { BeaconChain , BeaconChainTypes , BeaconStore } ;
8
7
use kzg:: Kzg ;
9
- use slasher:: test_utils:: E ;
10
8
use slog:: { debug, error, Logger } ;
11
9
use slot_clock:: SlotClock ;
12
- use ssz_types:: FixedVector ;
13
10
use std:: fmt;
14
11
use std:: fmt:: Debug ;
15
12
use std:: num:: NonZeroUsize ;
@@ -19,7 +16,6 @@ use task_executor::TaskExecutor;
19
16
use types:: blob_sidecar:: { BlobIdentifier , BlobSidecar , FixedBlobSidecarList } ;
20
17
use types:: { BlobSidecarList , ChainSpec , Epoch , EthSpec , Hash256 , SignedBeaconBlock } ;
21
18
22
- mod child_components;
23
19
mod error;
24
20
mod overflow_lru_cache;
25
21
mod state_lru_cache;
@@ -94,68 +90,27 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
94
90
self . availability_cache . has_block ( block_root)
95
91
}
96
92
97
- pub fn get_missing_blob_ids_with ( & self , block_root : Hash256 ) -> MissingBlobs {
93
+ /// Return the required blobs `block_root` expects if the block is currenlty in the cache.
94
+ pub fn num_expected_blobs ( & self , block_root : & Hash256 ) -> Option < usize > {
98
95
self . availability_cache
99
- . with_pending_components ( & block_root, |pending_components| match pending_components {
100
- Some ( pending_components) => self . get_missing_blob_ids (
101
- block_root,
102
- pending_components
103
- . get_cached_block ( )
104
- . as_ref ( )
105
- . map ( |b| b. as_block ( ) ) ,
106
- & pending_components. verified_blobs ,
107
- ) ,
108
- None => MissingBlobs :: new_without_block ( block_root, self . is_deneb ( ) ) ,
96
+ . peek_pending_components ( block_root, |components| {
97
+ components. and_then ( |components| components. num_expected_blobs ( ) )
109
98
} )
110
99
}
111
100
112
- /// If there's no block, all possible ids will be returned that don't exist in the given blobs.
113
- /// If there no blobs, all possible ids will be returned.
114
- pub fn get_missing_blob_ids < V > (
115
- & self ,
116
- block_root : Hash256 ,
117
- block : Option < & SignedBeaconBlock < T :: EthSpec > > ,
118
- blobs : & FixedVector < Option < V > , <T :: EthSpec as EthSpec >:: MaxBlobsPerBlock > ,
119
- ) -> MissingBlobs {
120
- let Some ( current_slot) = self . slot_clock . now_or_genesis ( ) else {
121
- error ! (
122
- self . log,
123
- "Failed to read slot clock when checking for missing blob ids"
124
- ) ;
125
- return MissingBlobs :: BlobsNotRequired ;
126
- } ;
127
-
128
- let current_epoch = current_slot. epoch ( T :: EthSpec :: slots_per_epoch ( ) ) ;
129
-
130
- if self . da_check_required_for_epoch ( current_epoch) {
131
- match block {
132
- Some ( cached_block) => {
133
- let block_commitments_len = cached_block
134
- . message ( )
135
- . body ( )
136
- . blob_kzg_commitments ( )
137
- . map ( |v| v. len ( ) )
138
- . unwrap_or ( 0 ) ;
139
- let blob_ids = blobs
101
+ /// Return the set of imported blob indexes for `block_root`. Returns None if there is no block
102
+ /// component for `block_root`.
103
+ pub fn imported_blob_indexes ( & self , block_root : & Hash256 ) -> Option < Vec < u64 > > {
104
+ self . availability_cache
105
+ . peek_pending_components ( block_root, |components| {
106
+ components. map ( |components| {
107
+ components
108
+ . get_cached_blobs ( )
140
109
. iter ( )
141
- . take ( block_commitments_len)
142
- . enumerate ( )
143
- . filter_map ( |( index, blob_commitment_opt) | {
144
- blob_commitment_opt. is_none ( ) . then_some ( BlobIdentifier {
145
- block_root,
146
- index : index as u64 ,
147
- } )
148
- } )
149
- . collect ( ) ;
150
- MissingBlobs :: KnownMissing ( blob_ids)
151
- }
152
- None => {
153
- MissingBlobs :: PossibleMissing ( BlobIdentifier :: get_all_blob_ids :: < E > ( block_root) )
154
- }
155
- }
156
- } else {
157
- MissingBlobs :: BlobsNotRequired
158
- }
110
+ . filter_map ( |blob| blob. as_ref ( ) . map ( |blob| blob. blob_index ( ) ) )
111
+ . collect :: < Vec < _ > > ( )
112
+ } )
113
+ } )
159
114
}
160
115
161
116
/// Get a blob from the availability cache.
@@ -351,6 +306,18 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
351
306
. map_or ( false , |da_epoch| block_epoch >= da_epoch)
352
307
}
353
308
309
+ pub fn da_check_required_for_current_epoch ( & self ) -> bool {
310
+ let Some ( current_slot) = self . slot_clock . now_or_genesis ( ) else {
311
+ error ! (
312
+ self . log,
313
+ "Failed to read slot clock when checking for missing blob ids"
314
+ ) ;
315
+ return false ;
316
+ } ;
317
+
318
+ self . da_check_required_for_epoch ( current_slot. epoch ( T :: EthSpec :: slots_per_epoch ( ) ) )
319
+ }
320
+
354
321
/// Returns `true` if the current epoch is greater than or equal to the `Deneb` epoch.
355
322
pub fn is_deneb ( & self ) -> bool {
356
323
self . slot_clock . now ( ) . map_or ( false , |slot| {
@@ -544,61 +511,3 @@ impl<E: EthSpec> MaybeAvailableBlock<E> {
544
511
}
545
512
}
546
513
}
547
-
548
- #[ derive( Debug , Clone ) ]
549
- pub enum MissingBlobs {
550
- /// We know for certain these blobs are missing.
551
- KnownMissing ( Vec < BlobIdentifier > ) ,
552
- /// We think these blobs might be missing.
553
- PossibleMissing ( Vec < BlobIdentifier > ) ,
554
- /// Blobs are not required.
555
- BlobsNotRequired ,
556
- }
557
-
558
- impl MissingBlobs {
559
- pub fn new_without_block ( block_root : Hash256 , is_deneb : bool ) -> Self {
560
- if is_deneb {
561
- MissingBlobs :: PossibleMissing ( BlobIdentifier :: get_all_blob_ids :: < E > ( block_root) )
562
- } else {
563
- MissingBlobs :: BlobsNotRequired
564
- }
565
- }
566
- pub fn is_empty ( & self ) -> bool {
567
- match self {
568
- MissingBlobs :: KnownMissing ( v) => v. is_empty ( ) ,
569
- MissingBlobs :: PossibleMissing ( v) => v. is_empty ( ) ,
570
- MissingBlobs :: BlobsNotRequired => true ,
571
- }
572
- }
573
- pub fn contains ( & self , blob_id : & BlobIdentifier ) -> bool {
574
- match self {
575
- MissingBlobs :: KnownMissing ( v) => v. contains ( blob_id) ,
576
- MissingBlobs :: PossibleMissing ( v) => v. contains ( blob_id) ,
577
- MissingBlobs :: BlobsNotRequired => false ,
578
- }
579
- }
580
- pub fn remove ( & mut self , blob_id : & BlobIdentifier ) {
581
- match self {
582
- MissingBlobs :: KnownMissing ( v) => v. retain ( |id| id != blob_id) ,
583
- MissingBlobs :: PossibleMissing ( v) => v. retain ( |id| id != blob_id) ,
584
- MissingBlobs :: BlobsNotRequired => { }
585
- }
586
- }
587
- pub fn indices ( & self ) -> Vec < u64 > {
588
- match self {
589
- MissingBlobs :: KnownMissing ( v) => v. iter ( ) . map ( |id| id. index ) . collect ( ) ,
590
- MissingBlobs :: PossibleMissing ( v) => v. iter ( ) . map ( |id| id. index ) . collect ( ) ,
591
- MissingBlobs :: BlobsNotRequired => vec ! [ ] ,
592
- }
593
- }
594
- }
595
-
596
- impl Into < Vec < BlobIdentifier > > for MissingBlobs {
597
- fn into ( self ) -> Vec < BlobIdentifier > {
598
- match self {
599
- MissingBlobs :: KnownMissing ( v) => v,
600
- MissingBlobs :: PossibleMissing ( v) => v,
601
- MissingBlobs :: BlobsNotRequired => vec ! [ ] ,
602
- }
603
- }
604
- }
0 commit comments