pub fn produce_block(
        &self,
        randao_reveal: Signature,
        slot: Slot,
        validator_graffiti: Option<Graffiti>,
    ) -> Result<BeaconBlockAndState<T::EthSpec>, BlockProductionError> {
        metrics::inc_counter(&metrics::BLOCK_PRODUCTION_REQUESTS);
        let _complete_timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_TIMES);

        // Producing a block requires the tree hash cache, so clone a full state corresponding to
        // the head from the snapshot cache. Unfortunately we can't move the snapshot out of the
        // cache (which would be fast), because we need to re-process the block after it has been
        // signed. If we miss the cache or we're producing a block that conflicts with the head,
        // fall back to getting the head from `slot - 1`.
        let state_load_timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_STATE_LOAD_TIMES);
        let head_info = self
            .head_info()
            .map_err(BlockProductionError::UnableToGetHeadInfo)?;
        let (state, state_root_opt) = if head_info.slot < slot {
            // Normal case: proposing a block atop the current head. Use the snapshot cache.
            if let Some(pre_state) = self
                .snapshot_cache
                .try_read_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT)
                .and_then(|snapshot_cache| {
                    snapshot_cache.get_state_for_block_production(head_info.block_root)
                })
            {
                (pre_state.pre_state, pre_state.state_root)
            } else {
                warn!(
                    self.log,
                    "Block production cache miss";
                    "message" => "this block is more likely to be orphaned",
                    "slot" => slot,
                );
                let state = self
                    .state_at_slot(slot - 1, StateSkipConfig::WithStateRoots)
                    .map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;

                (state, None)
            }
        } else {
            warn!(
                self.log,
                "Producing block that conflicts with head";
                "message" => "this block is more likely to be orphaned",
                "slot" => slot,
            );
            let state = self
                .state_at_slot(slot - 1, StateSkipConfig::WithStateRoots)
                .map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;

            (state, None)
        };
        drop(state_load_timer);

        self.produce_block_on_state(
            state,
            state_root_opt,
            slot,
            randao_reveal,
            validator_graffiti,
        )
    }
/// Produce a new block at the given `slot`.
///
/// The produced block will not be inherently valid, it must be signed by a block producer.
/// Block signing is out of the scope of this function and should be done by a separate program.
Produce a new block at the given `slot`.
The produced block will not be inherently valid, it must be signed by a block producer.
Block signing is out of the scope of this function and should be done by a separate program.
Produce a new block at the given ` slot ` . The produced block will not be inherently valid it must be signed by a block producer . Block signing is out of the scope of this function and should be done by a separate program .
pub fn produce_block(
        &self,
        randao_reveal: Signature,
        slot: Slot,
        validator_graffiti: Option<Graffiti>,
    ) -> Result<BeaconBlockAndState<T::EthSpec>, BlockProductionError> {
        metrics::inc_counter(&metrics::BLOCK_PRODUCTION_REQUESTS);
        let _complete_timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_TIMES);
        // Producing a block requires the tree hash cache, so clone a full state corresponding to
        // the head from the snapshot cache. Unfortunately we can't move the snapshot out of the
        // cache (which would be fast), because we need to re-process the block after it has been
        // signed. If we miss the cache or we're producing a block that conflicts with the head,
        // fall back to getting the head from `slot - 1`.
        let state_load_timer = metrics::start_timer(&metrics::BLOCK_PRODUCTION_STATE_LOAD_TIMES);
        let head_info = self
            .head_info()
            .map_err(BlockProductionError::UnableToGetHeadInfo)?;
        let (state, state_root_opt) = if head_info.slot < slot {
            // Normal case: proposing a block atop the current head. Use the snapshot cache.
            if let Some(pre_state) = self
                .snapshot_cache
                .try_read_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT)
                .and_then(|snapshot_cache| {
                    snapshot_cache.get_state_for_block_production(head_info.block_root)
                })
            {
                (pre_state.pre_state, pre_state.state_root)
            } else {
                warn!(
                    self.log,
                    "Block production cache miss";
                    "message" => "this block is more likely to be orphaned",
                    "slot" => slot,
                );
                let state = self
                    .state_at_slot(slot - 1, StateSkipConfig::WithStateRoots)
                    .map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;
                (state, None)
            }
        } else {
            warn!(
                self.log,
                "Producing block that conflicts with head";
                "message" => "this block is more likely to be orphaned",
                "slot" => slot,
            );
            let state = self
                .state_at_slot(slot - 1, StateSkipConfig::WithStateRoots)
                .map_err(|_| BlockProductionError::UnableToProduceAtSlot(slot))?;
            (state, None)
        };
        drop(state_load_timer);
        self.produce_block_on_state(
            state,
            state_root_opt,
            slot,
            randao_reveal,
            validator_graffiti,
        )
    }
pub fn produce_block ( & self , randao_reveal : Signature , slot : Slot , validator_graffiti : Option < Graffiti > , ) -> Result < BeaconBlockAndState < T :: EthSpec > , BlockProductionError > { metrics :: inc_counter ( & metrics :: BLOCK_PRODUCTION_REQUESTS ) ; let _complete_timer = metrics :: start_timer ( & metrics :: BLOCK_PRODUCTION_TIMES ) ; // Producing a block requires the tree hash cache, so clone a full state corresponding to // the head from the snapshot cache. Unfortunately we can't move the snapshot out of the // cache (which would be fast), because we need to re-process the block after it has been // signed. If we miss the cache or we're producing a block that conflicts with the head, // fall back to getting the head from `slot - 1`. let state_load_timer = metrics :: start_timer ( & metrics :: BLOCK_PRODUCTION_STATE_LOAD_TIMES ) ; let head_info = self . head_info ( ) . map_err ( BlockProductionError :: UnableToGetHeadInfo ) ? ; let ( state , state_root_opt ) = if head_info . slot < slot { // Normal case: proposing a block atop the current head. Use the snapshot cache. if let Some ( pre_state ) = self . snapshot_cache . try_read_for ( BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT ) . and_then ( | snapshot_cache | { snapshot_cache . get_state_for_block_production ( head_info . block_root ) } ) { ( pre_state . pre_state , pre_state . state_root ) } else { warn ! ( self log " " " " " " " " slot ) ; let state = self . state_at_slot ( slot - 1 , StateSkipConfig :: WithStateRoots ) . map_err ( | _ | BlockProductionError :: UnableToProduceAtSlot ( slot ) ) ? ; ( state , None ) } } else { warn ! ( self log " " " " " " " " slot ) ; let state = self . state_at_slot ( slot - 1 , StateSkipConfig :: WithStateRoots ) . map_err ( | _ | BlockProductionError :: UnableToProduceAtSlot ( slot ) ) ? ; ( state , None ) } ; drop ( state_load_timer ) ; self . produce_block_on_state ( state , state_root_opt , slot , randao_reveal , validator_graffiti , ) }
Produce a new block at the given `slot`.
Produce a new block at the given ` slot ` .
&self
randao_reveal
Signature
slot
Slot
validator_graffiti
Option<Graffiti>