pub fn start_update_service<T: SlotClock + 'static, E: EthSpec>(
    core_duties_service: Arc<DutiesService<T, E>>,
    mut block_service_tx: Sender<BlockServiceNotification>,
) {
    /*
     * Spawn the task which updates the map of pubkey to validator index.
     */
    let duties_service = core_duties_service.clone();
    core_duties_service.context.executor.spawn(
        async move {
            loop {
                // Run this poll before the wait, this should hopefully download all the indices
                // before the block/attestation tasks need them.
                poll_validator_indices(&duties_service).await;

                if let Some(duration) = duties_service.slot_clock.duration_to_next_slot() {
                    sleep(duration).await;
                } else {
                    // Just sleep for one slot if we are unable to read the system clock, this gives
                    // us an opportunity for the clock to eventually come good.
                    sleep(duties_service.slot_clock.slot_duration()).await;
                }
            }
        },
        "duties_service_indices",
    );

    /*
     * Spawn the task which keeps track of local block proposal duties.
     */
    let duties_service = core_duties_service.clone();
    let log = core_duties_service.context.log().clone();
    core_duties_service.context.executor.spawn(
        async move {
            loop {
                if let Some(duration) = duties_service.slot_clock.duration_to_next_slot() {
                    sleep(duration).await;
                } else {
                    // Just sleep for one slot if we are unable to read the system clock, this gives
                    // us an opportunity for the clock to eventually come good.
                    sleep(duties_service.slot_clock.slot_duration()).await;
                    continue;
                }

                if let Err(e) = poll_beacon_proposers(&duties_service, &mut block_service_tx).await
                {
                    error!(
                       log,
                       "Failed to poll beacon proposers";
                       "error" => ?e
                    )
                }
            }
        },
        "duties_service_proposers",
    );

    /*
     * Spawn the task which keeps track of local attestation duties.
     */
    let duties_service = core_duties_service.clone();
    let log = core_duties_service.context.log().clone();
    core_duties_service.context.executor.spawn(
        async move {
            loop {
                if let Some(duration) = duties_service.slot_clock.duration_to_next_slot() {
                    sleep(duration).await;
                } else {
                    // Just sleep for one slot if we are unable to read the system clock, this gives
                    // us an opportunity for the clock to eventually come good.
                    sleep(duties_service.slot_clock.slot_duration()).await;
                    continue;
                }

                if let Err(e) = poll_beacon_attesters(&duties_service).await {
                    error!(
                       log,
                       "Failed to poll beacon attesters";
                       "error" => ?e
                    );
                }
            }
        },
        "duties_service_attesters",
    );
}
/// Start the service that periodically polls the beacon node for validator duties. This will start
/// several sub-services.
///
/// ## Notes
///
/// The loops in this function are structured such that a new instance of that task will only start
/// once the current one is finished. This means that if a task happens to take more than one slot
/// to run, we might skip a slot. This is unfortunate, however the alternative is to *always*
/// process every slot, which has the chance of creating a theoretically unlimited backlog of tasks.
/// It was a conscious decision to choose to drop tasks on an overloaded/latent system rather than
/// overload it even more.
Start the service that periodically polls the beacon node for validator duties. This will start
several sub-services.
Start the service that periodically polls the beacon node for validator duties . This will start several sub - services .
pub fn start_update_service<T: SlotClock + 'static, E: EthSpec>(
    core_duties_service: Arc<DutiesService<T, E>>,
    mut block_service_tx: Sender<BlockServiceNotification>,
) {
    /*
     * Spawn the task which updates the map of pubkey to validator index.
     */
    let duties_service = core_duties_service.clone();
    core_duties_service.context.executor.spawn(
        async move {
            loop {
                // Run this poll before the wait, this should hopefully download all the indices
                // before the block/attestation tasks need them.
                poll_validator_indices(&duties_service).await;
                if let Some(duration) = duties_service.slot_clock.duration_to_next_slot() {
                    sleep(duration).await;
                } else {
                    // Just sleep for one slot if we are unable to read the system clock, this gives
                    // us an opportunity for the clock to eventually come good.
                    sleep(duties_service.slot_clock.slot_duration()).await;
                }
            }
        },
        "duties_service_indices",
    );
    /*
     * Spawn the task which keeps track of local block proposal duties.
     */
    let duties_service = core_duties_service.clone();
    let log = core_duties_service.context.log().clone();
    core_duties_service.context.executor.spawn(
        async move {
            loop {
                if let Some(duration) = duties_service.slot_clock.duration_to_next_slot() {
                    sleep(duration).await;
                } else {
                    // Just sleep for one slot if we are unable to read the system clock, this gives
                    // us an opportunity for the clock to eventually come good.
                    sleep(duties_service.slot_clock.slot_duration()).await;
                    continue;
                }
                if let Err(e) = poll_beacon_proposers(&duties_service, &mut block_service_tx).await
                {
                    error!(
                       log,
                       "Failed to poll beacon proposers";
                       "error" => ?e
                    )
                }
            }
        },
        "duties_service_proposers",
    );
    /*
     * Spawn the task which keeps track of local attestation duties.
     */
    let duties_service = core_duties_service.clone();
    let log = core_duties_service.context.log().clone();
    core_duties_service.context.executor.spawn(
        async move {
            loop {
                if let Some(duration) = duties_service.slot_clock.duration_to_next_slot() {
                    sleep(duration).await;
                } else {
                    // Just sleep for one slot if we are unable to read the system clock, this gives
                    // us an opportunity for the clock to eventually come good.
                    sleep(duties_service.slot_clock.slot_duration()).await;
                    continue;
                }
                if let Err(e) = poll_beacon_attesters(&duties_service).await {
                    error!(
                       log,
                       "Failed to poll beacon attesters";
                       "error" => ?e
                    );
                }
            }
        },
        "duties_service_attesters",
    );
}
pub fn start_update_service < T : SlotClock + ' static , E : EthSpec > ( core_duties_service : Arc < DutiesService < T , E > > , mut block_service_tx : Sender < BlockServiceNotification > , ) { /*
     * Spawn the task which updates the map of pubkey to validator index.
     */ let duties_service = core_duties_service . clone ( ) ; core_duties_service . context . executor . spawn ( async move { loop { // Run this poll before the wait, this should hopefully download all the indices // before the block/attestation tasks need them. poll_validator_indices ( & duties_service ) . await ; if let Some ( duration ) = duties_service . slot_clock . duration_to_next_slot ( ) { sleep ( duration ) . await ; } else { // Just sleep for one slot if we are unable to read the system clock, this gives // us an opportunity for the clock to eventually come good. sleep ( duties_service . slot_clock . slot_duration ( ) ) . await ; } } } , " " , ) ; /*
     * Spawn the task which keeps track of local block proposal duties.
     */ let duties_service = core_duties_service . clone ( ) ; let log = core_duties_service . context . log ( ) . clone ( ) ; core_duties_service . context . executor . spawn ( async move { loop { if let Some ( duration ) = duties_service . slot_clock . duration_to_next_slot ( ) { sleep ( duration ) . await ; } else { // Just sleep for one slot if we are unable to read the system clock, this gives // us an opportunity for the clock to eventually come good. sleep ( duties_service . slot_clock . slot_duration ( ) ) . await ; continue ; } if let Err ( e ) = poll_beacon_proposers ( & duties_service , & mut block_service_tx ) . await { error ! ( log " " " " e ) } } } , " " , ) ; /*
     * Spawn the task which keeps track of local attestation duties.
     */ let duties_service = core_duties_service . clone ( ) ; let log = core_duties_service . context . log ( ) . clone ( ) ; core_duties_service . context . executor . spawn ( async move { loop { if let Some ( duration ) = duties_service . slot_clock . duration_to_next_slot ( ) { sleep ( duration ) . await ; } else { // Just sleep for one slot if we are unable to read the system clock, this gives // us an opportunity for the clock to eventually come good. sleep ( duties_service . slot_clock . slot_duration ( ) ) . await ; continue ; } if let Err ( e ) = poll_beacon_attesters ( & duties_service ) . await { error ! ( log " " " " e ) ; } } } , " " , ) ; }
Start the service that periodically polls the beacon node for validator duties.
Start the service that periodically polls the beacon node for validator duties .
core_duties_service
Arc<DutiesService<T, E>>
block_service_tx
Sender<BlockServiceNotification>
notes
The loops in this function are structured such that a new instance of that task will only start
once the current one is finished. This means that if a task happens to take more than one slot
to run, we might skip a slot. This is unfortunate, however the alternative is to *always
process every slot, which has the chance of creating a theoretically unlimited backlog of tasks.
It was a conscious decision to choose to drop tasks on an overloaded/latent system rather than
overload it even more.
The loops in this function are structured such that a new instance of that task will only start once the current one is finished . This means that if a task happens to take more than one slot to run we might skip a slot . This is unfortunate however the alternative is to * always process every slot which has the chance of creating a theoretically unlimited backlog of tasks . It was a conscious decision to choose to drop tasks on an overloaded / latent system rather than overload it even more .