mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-01 13:47:16 +00:00
Fix timing issue in obtaining the Fork (#2158)
## Issue Addressed
Related PR: https://github.com/sigp/lighthouse/pull/2137#issuecomment-754712492
The Fork is required for VC to perform signing. Currently, it is not guaranteed that the Fork has been obtained at the point of the signing as the Fork is obtained at after ForkService starts. We will see the [error](851a4dca3c/validator_client/src/validator_store.rs (L127)) if VC could not perform the signing due to the timing issue.
> Unable to get Fork for signing
## Proposed Changes
Obtain the Fork on `init_from_beacon_node` to fix the timing issue.
This commit is contained in:
@@ -27,6 +27,7 @@ use block_service::{BlockService, BlockServiceBuilder};
|
||||
use clap::ArgMatches;
|
||||
use duties_service::{DutiesService, DutiesServiceBuilder};
|
||||
use environment::RuntimeContext;
|
||||
use eth2::types::StateId;
|
||||
use eth2::{reqwest::ClientBuilder, BeaconNodeHttpClient, StatusCode, Url};
|
||||
use fork_service::{ForkService, ForkServiceBuilder};
|
||||
use futures::channel::mpsc;
|
||||
@@ -43,7 +44,7 @@ use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::{SystemTime, UNIX_EPOCH};
|
||||
use tokio::time::{sleep, Duration};
|
||||
use types::{EthSpec, Hash256};
|
||||
use types::{EthSpec, Fork, Hash256};
|
||||
use validator_store::ValidatorStore;
|
||||
|
||||
/// The interval between attempts to contact the beacon node during startup.
|
||||
@@ -234,7 +235,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
BeaconNodeFallback::new(candidates, context.eth2_config.spec.clone(), log.clone());
|
||||
|
||||
// Perform some potentially long-running initialization tasks.
|
||||
let (genesis_time, genesis_validators_root) = tokio::select! {
|
||||
let (genesis_time, genesis_validators_root, fork) = tokio::select! {
|
||||
tuple = init_from_beacon_node(&beacon_nodes, &context) => tuple?,
|
||||
() = context.executor.exit() => return Err("Shutting down".to_string())
|
||||
};
|
||||
@@ -255,6 +256,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
start_fallback_updater_service(context.clone(), beacon_nodes.clone())?;
|
||||
|
||||
let fork_service = ForkServiceBuilder::new()
|
||||
.fork(fork)
|
||||
.slot_clock(slot_clock.clone())
|
||||
.beacon_nodes(beacon_nodes.clone())
|
||||
.log(log.clone())
|
||||
@@ -394,7 +396,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
async fn init_from_beacon_node<E: EthSpec>(
|
||||
beacon_nodes: &BeaconNodeFallback<SystemTimeSlotClock, E>,
|
||||
context: &RuntimeContext<E>,
|
||||
) -> Result<(u64, Hash256), String> {
|
||||
) -> Result<(u64, Hash256, Fork), String> {
|
||||
loop {
|
||||
beacon_nodes.update_unready_candidates().await;
|
||||
let num_available = beacon_nodes.num_available().await;
|
||||
@@ -453,7 +455,33 @@ async fn init_from_beacon_node<E: EthSpec>(
|
||||
sleep(RETRY_DELAY).await;
|
||||
};
|
||||
|
||||
Ok((genesis.genesis_time, genesis.genesis_validators_root))
|
||||
let fork = loop {
|
||||
match beacon_nodes
|
||||
.first_success(RequireSynced::No, |node| async move {
|
||||
node.get_beacon_states_fork(StateId::Head).await
|
||||
})
|
||||
.await
|
||||
{
|
||||
Ok(Some(fork)) => break fork.data,
|
||||
Ok(None) => {
|
||||
info!(
|
||||
context.log(),
|
||||
"Failed to get fork, state not found";
|
||||
);
|
||||
}
|
||||
Err(errors) => {
|
||||
error!(
|
||||
context.log(),
|
||||
"Failed to get fork";
|
||||
"error" => %errors
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
sleep(RETRY_DELAY).await;
|
||||
};
|
||||
|
||||
Ok((genesis.genesis_time, genesis.genesis_validators_root, fork))
|
||||
}
|
||||
|
||||
async fn wait_for_genesis<E: EthSpec>(
|
||||
|
||||
Reference in New Issue
Block a user