@@ -79,6 +79,7 @@ use std::path::PathBuf;
7979use std:: pin:: Pin ;
8080use std:: str:: FromStr ;
8181use std:: sync:: Arc ;
82+ use store:: BlobSidecarListFromRoot ;
8283use sysinfo:: { System , SystemExt } ;
8384use system_health:: { observe_nat, observe_system_health_bn} ;
8485use task_spawner:: { Priority , TaskSpawner } ;
@@ -4747,7 +4748,6 @@ pub fn serve<T: BeaconChainTypes>(
47474748 task_spawner : TaskSpawner < T :: EthSpec > ,
47484749 chain : Arc < BeaconChain < T > > | {
47494750 task_spawner. spawn_async_with_rejection ( Priority :: P1 , async move {
4750- let mut results = Vec :: new ( ) ;
47514751 let deneb_start_slot =
47524752 if let Some ( deneb_fork_epoch) = chain. spec . deneb_fork_epoch {
47534753 deneb_fork_epoch. start_slot ( T :: EthSpec :: slots_per_epoch ( ) )
@@ -4756,51 +4756,77 @@ pub fn serve<T: BeaconChainTypes>(
47564756 "No Deneb fork scheduled" . to_string ( ) ,
47574757 ) ) ;
47584758 } ;
4759- let start_slot = query. start_slot . unwrap_or ( deneb_start_slot) ;
4759+ let start_slot = query. start_slot ;
4760+
47604761 if start_slot < deneb_start_slot {
47614762 return Err ( warp_utils:: reject:: custom_bad_request ( format ! (
47624763 "start_slot ({}) must be >= deneb fork slot ({})" ,
47634764 start_slot, deneb_start_slot
47644765 ) ) ) ;
47654766 }
4766- // Maybe use chain.canonical_head.cached_head().head_slot()??
4767- let Ok ( current_head_slot) = chain. slot ( ) else {
4768- return Err ( warp_utils:: reject:: custom_bad_request (
4769- "Failed to get current head slot" . to_string ( ) ,
4770- ) ) ;
4771- } ;
47724767
4773- let end_slot = query. end_slot . unwrap_or ( current_head_slot ) ;
4768+ let end_slot = query. end_slot ;
47744769 if end_slot < start_slot {
47754770 return Err ( warp_utils:: reject:: custom_bad_request ( format ! (
47764771 "end_slot ({}) must be >= start_slot ({})" ,
47774772 end_slot, start_slot
47784773 ) ) ) ;
47794774 }
47804775
4776+ let verify = query. verify . unwrap_or ( true ) ;
4777+
4778+ let mut blob_count = 0 ;
4779+ let mut blobs_missing: Vec < u64 > = Vec :: new ( ) ;
4780+ let mut blobs_invalid: Vec < u64 > = Vec :: new ( ) ;
4781+
47814782 for slot in start_slot. as_u64 ( ) ..=end_slot. as_u64 ( ) {
47824783 if let Ok ( ( root, _, _) ) = BlockId :: from_slot ( Slot :: from ( slot) ) . root ( & chain)
47834784 {
4784- if let Ok ( blob_list_res) = chain. store . get_blobs ( & root) {
4785- if let Some ( blob_list) = blob_list_res. blobs ( ) {
4786- if let Err ( _e) =
4787- verify_kzg_for_blob_list ( blob_list. iter ( ) , & chain. kzg )
4788- {
4789- results. push ( BlobsVerificationData {
4790- block_root : root,
4791- slot : slot. into ( ) ,
4792- blobs_exist : true ,
4793- blobs_stored : false ,
4794- blobs_verified : true ,
4795- } ) ;
4785+ match chain. store . get_blobs ( & root) {
4786+ Ok ( blob_list) => {
4787+ match blob_list {
4788+ BlobSidecarListFromRoot :: NoBlobs => {
4789+ // This means that no blobs exist for this slot.
4790+ continue ;
4791+ }
4792+ BlobSidecarListFromRoot :: NoRoot => {
4793+ // This means that there are blobs missing for this slot.
4794+ blobs_missing. push ( slot) ;
4795+ }
4796+ BlobSidecarListFromRoot :: Blobs ( blob_list) => {
4797+ blob_count += blob_list. len ( ) ;
4798+ // Optionally verify each blob_list.
4799+ if verify
4800+ && verify_kzg_for_blob_list (
4801+ blob_list. iter ( ) ,
4802+ & chain. kzg ,
4803+ )
4804+ . is_err ( )
4805+ {
4806+ blobs_invalid. push ( slot) ;
4807+ }
4808+ }
47964809 }
47974810 }
4811+ Err ( _) => {
4812+ // An error here means that we could not decode the blob list.
4813+ // This likely means a corrupted database.
4814+ blobs_invalid. push ( slot) ;
4815+ }
47984816 }
47994817 }
4818+ // An Err here means the block does not exist. This is fine assuming the node is synced.
48004819 }
4820+
48014821 Ok :: < _ , warp:: reject:: Rejection > (
4802- warp:: reply:: json ( & api_types:: GenericResponse :: from ( results) )
4803- . into_response ( ) ,
4822+ warp:: reply:: json ( & api_types:: GenericResponse :: from (
4823+ BlobsVerificationData {
4824+ blob_count,
4825+ blobs_missing,
4826+ blobs_invalid,
4827+ } ,
4828+ ) )
4829+ . into_response ( ) ,
48044830 )
48054831 } )
48064832 } ,
0 commit comments