@@ -5,8 +5,7 @@ use std::sync::Arc;
55
66use crate :: beacon_chain:: { BeaconChain , BeaconChainTypes } ;
77use crate :: block_verification:: {
8- BlockSlashInfo , cheap_state_advance_to_obtain_committees, get_validator_pubkey_cache,
9- process_block_slash_info,
8+ BlockSlashInfo , get_validator_pubkey_cache, process_block_slash_info,
109} ;
1110use crate :: kzg_utils:: { validate_blob, validate_blobs} ;
1211use crate :: observed_data_sidecars:: { ObservationStrategy , Observe } ;
@@ -494,59 +493,32 @@ pub fn validate_blob_sidecar_for_gossip<T: BeaconChainTypes, O: ObservationStrat
494493 }
495494
496495 let proposer_shuffling_root =
497- if parent_block. slot . epoch ( T :: EthSpec :: slots_per_epoch ( ) ) == blob_epoch {
498- parent_block
499- . next_epoch_shuffling_id
500- . shuffling_decision_block
501- } else {
502- parent_block. root
503- } ;
504-
505- let proposer_opt = chain
506- . beacon_proposer_cache
507- . lock ( )
508- . get_slot :: < T :: EthSpec > ( proposer_shuffling_root, blob_slot) ;
509-
510- let ( proposer_index, fork) = if let Some ( proposer) = proposer_opt {
511- ( proposer. index , proposer. fork )
512- } else {
513- debug ! (
514- %block_root,
515- %blob_index,
516- "Proposer shuffling cache miss for blob verification"
517- ) ;
518- let ( parent_state_root, mut parent_state) = chain
519- . store
520- . get_advanced_hot_state ( block_parent_root, blob_slot, parent_block. state_root )
521- . map_err ( |e| GossipBlobError :: BeaconChainError ( Box :: new ( e. into ( ) ) ) ) ?
522- . ok_or_else ( || {
523- BeaconChainError :: DBInconsistent ( format ! (
524- "Missing state for parent block {block_parent_root:?}" ,
525- ) )
526- } ) ?;
527-
528- let state = cheap_state_advance_to_obtain_committees :: < _ , GossipBlobError > (
529- & mut parent_state,
530- Some ( parent_state_root) ,
531- blob_slot,
532- & chain. spec ,
533- ) ?;
534-
535- let epoch = state. current_epoch ( ) ;
536- let proposers = state. get_beacon_proposer_indices ( epoch, & chain. spec ) ?;
537- let proposer_index = * proposers
538- . get ( blob_slot. as_usize ( ) % T :: EthSpec :: slots_per_epoch ( ) as usize )
539- . ok_or_else ( || BeaconChainError :: NoProposerForSlot ( blob_slot) ) ?;
540-
541- // Prime the proposer shuffling cache with the newly-learned value.
542- chain. beacon_proposer_cache . lock ( ) . insert (
543- blob_epoch,
544- proposer_shuffling_root,
545- proposers,
546- state. fork ( ) ,
547- ) ?;
548- ( proposer_index, state. fork ( ) )
496+ parent_block. proposer_shuffling_root_for_child_block ( blob_epoch, & chain. spec ) ;
497+
498+ let Some ( proposer) = chain. with_proposer_cache (
499+ proposer_shuffling_root,
500+ blob_epoch,
501+ |cache| cache. get_slot :: < T :: EthSpec > ( proposer_shuffling_root, blob_slot) ,
502+ || {
503+ debug ! (
504+ %block_root,
505+ index = %blob_index,
506+ "Proposer shuffling cache miss for blob verification"
507+ ) ;
508+ chain
509+ . store
510+ . get_advanced_hot_state ( block_parent_root, blob_slot, parent_block. state_root )
511+ . map_err ( |e| GossipBlobError :: BeaconChainError ( Box :: new ( e. into ( ) ) ) )
512+ } ,
513+ ) ?
514+ else {
515+ return Err ( BeaconChainError :: DBInconsistent ( format ! (
516+ "Missing state for parent block {block_parent_root:?}" ,
517+ ) )
518+ . into ( ) ) ;
549519 } ;
520+ let proposer_index = proposer. index ;
521+ let fork = proposer. fork ;
550522
551523 // Signature verify the signed block header.
552524 let signature_is_valid = {
0 commit comments