@@ -617,48 +617,45 @@ impl<T: BeaconChainTypes> DataAvailabilityChecker<T> {
617617 ) ) ;
618618 } ;
619619
620- let data_columns_to_publish = all_data_columns
621- . into_iter ( )
622- . filter ( |d| !existing_column_indices. contains ( & d. index ( ) ) )
623- . collect :: < Vec < _ > > ( ) ;
624-
625- let Some ( slot) = data_columns_to_publish
626- . first ( )
627- . map ( |d| d. as_data_column ( ) . slot ( ) )
628- else {
620+ let Some ( slot) = all_data_columns. first ( ) . map ( |d| d. as_data_column ( ) . slot ( ) ) else {
629621 return Ok ( DataColumnReconstructionResult :: RecoveredColumnsNotImported (
630622 "No new columns to import and publish" ,
631623 ) ) ;
632624 } ;
633625
626+ let columns_to_sample = self
627+ . custody_context ( )
628+ . sampling_columns_for_epoch ( slot. epoch ( T :: EthSpec :: slots_per_epoch ( ) ) , & self . spec ) ;
629+
630+ // We only need to import and publish columns that we need to sample
631+ // and columns that we haven't already received
632+ let data_columns_to_import_and_publish = all_data_columns
633+ . into_iter ( )
634+ . filter ( |d| {
635+ columns_to_sample. contains ( & d. index ( ) )
636+ && !existing_column_indices. contains ( & d. index ( ) )
637+ } )
638+ . collect :: < Vec < _ > > ( ) ;
639+
634640 metrics:: stop_timer ( timer) ;
635641 metrics:: inc_counter_by (
636642 & metrics:: DATA_AVAILABILITY_RECONSTRUCTED_COLUMNS ,
637- data_columns_to_publish . len ( ) as u64 ,
643+ data_columns_to_import_and_publish . len ( ) as u64 ,
638644 ) ;
639645
640646 debug ! (
641- count = data_columns_to_publish . len( ) ,
647+ count = data_columns_to_import_and_publish . len( ) ,
642648 ?block_root,
643649 %slot,
644650 "Reconstructed columns"
645651 ) ;
646652
647- let columns_to_sample = self
648- . custody_context ( )
649- . sampling_columns_for_epoch ( slot. epoch ( T :: EthSpec :: slots_per_epoch ( ) ) , & self . spec ) ;
650- let data_columns_to_import: Vec < _ > = data_columns_to_publish
651- . iter ( )
652- . filter ( |column| columns_to_sample. contains ( & column. index ( ) ) )
653- . cloned ( )
654- . collect ( ) ;
655-
656653 self . availability_cache
657- . put_kzg_verified_data_columns ( * block_root, data_columns_to_import )
654+ . put_kzg_verified_data_columns ( * block_root, data_columns_to_import_and_publish . clone ( ) )
658655 . map ( |availability| {
659656 DataColumnReconstructionResult :: Success ( (
660657 availability,
661- data_columns_to_publish
658+ data_columns_to_import_and_publish
662659 . into_iter ( )
663660 . map ( |d| d. clone_arc ( ) )
664661 . collect :: < Vec < _ > > ( ) ,
0 commit comments