mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-21 05:44:44 +00:00
Merge remote-tracking branch 'origin/unstable' into tree-states
This commit is contained in:
@@ -40,9 +40,6 @@ use types::{
|
||||
/// Interval between polling the eth1 node for genesis information.
|
||||
pub const ETH1_GENESIS_UPDATE_INTERVAL_MILLIS: u64 = 7_000;
|
||||
|
||||
/// Timeout for checkpoint sync HTTP requests.
|
||||
pub const CHECKPOINT_SYNC_HTTP_TIMEOUT: Duration = Duration::from_secs(60);
|
||||
|
||||
/// Builds a `Client` instance.
|
||||
///
|
||||
/// ## Notes
|
||||
@@ -274,12 +271,60 @@ where
|
||||
"remote_url" => %url,
|
||||
);
|
||||
|
||||
let remote =
|
||||
BeaconNodeHttpClient::new(url, Timeouts::set_all(CHECKPOINT_SYNC_HTTP_TIMEOUT));
|
||||
let remote = BeaconNodeHttpClient::new(
|
||||
url,
|
||||
Timeouts::set_all(Duration::from_secs(
|
||||
config.chain.checkpoint_sync_url_timeout,
|
||||
)),
|
||||
);
|
||||
let slots_per_epoch = TEthSpec::slots_per_epoch();
|
||||
|
||||
debug!(context.log(), "Downloading finalized block");
|
||||
let deposit_snapshot = if config.sync_eth1_chain {
|
||||
// We want to fetch deposit snapshot before fetching the finalized beacon state to
|
||||
// ensure that the snapshot is not newer than the beacon state that satisfies the
|
||||
// deposit finalization conditions
|
||||
debug!(context.log(), "Downloading deposit snapshot");
|
||||
let deposit_snapshot_result = remote
|
||||
.get_deposit_snapshot()
|
||||
.await
|
||||
.map_err(|e| match e {
|
||||
ApiError::InvalidSsz(e) => format!(
|
||||
"Unable to parse SSZ: {:?}. Ensure the checkpoint-sync-url refers to a \
|
||||
node for the correct network",
|
||||
e
|
||||
),
|
||||
e => format!("Error fetching deposit snapshot from remote: {:?}", e),
|
||||
});
|
||||
match deposit_snapshot_result {
|
||||
Ok(Some(deposit_snapshot)) => {
|
||||
if deposit_snapshot.is_valid() {
|
||||
Some(deposit_snapshot)
|
||||
} else {
|
||||
warn!(context.log(), "Remote BN sent invalid deposit snapshot!");
|
||||
None
|
||||
}
|
||||
}
|
||||
Ok(None) => {
|
||||
warn!(
|
||||
context.log(),
|
||||
"Remote BN does not support EIP-4881 fast deposit sync"
|
||||
);
|
||||
None
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(
|
||||
context.log(),
|
||||
"Remote BN does not support EIP-4881 fast deposit sync";
|
||||
"error" => e
|
||||
);
|
||||
None
|
||||
}
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
debug!(context.log(), "Downloading finalized block");
|
||||
// Find a suitable finalized block on an epoch boundary.
|
||||
let mut block = remote
|
||||
.get_beacon_blocks_ssz::<TEthSpec>(BlockId::Finalized, &spec)
|
||||
@@ -363,9 +408,33 @@ where
|
||||
"state_root" => ?state_root,
|
||||
);
|
||||
|
||||
let service =
|
||||
deposit_snapshot.and_then(|snapshot| match Eth1Service::from_deposit_snapshot(
|
||||
config.eth1,
|
||||
context.log().clone(),
|
||||
spec,
|
||||
&snapshot,
|
||||
) {
|
||||
Ok(service) => {
|
||||
info!(
|
||||
context.log(),
|
||||
"Loaded deposit tree snapshot";
|
||||
"deposits loaded" => snapshot.deposit_count,
|
||||
);
|
||||
Some(service)
|
||||
}
|
||||
Err(e) => {
|
||||
warn!(context.log(),
|
||||
"Unable to load deposit snapshot";
|
||||
"error" => ?e
|
||||
);
|
||||
None
|
||||
}
|
||||
});
|
||||
|
||||
builder
|
||||
.weak_subjectivity_state(state, block, genesis_state)
|
||||
.map(|v| (v, None))?
|
||||
.map(|v| (v, service))?
|
||||
}
|
||||
ClientGenesis::DepositContract => {
|
||||
info!(
|
||||
@@ -458,7 +527,9 @@ where
|
||||
ClientGenesis::FromStore => builder.resume_from_db().map(|v| (v, None))?,
|
||||
};
|
||||
|
||||
self.eth1_service = eth1_service_option;
|
||||
if config.sync_eth1_chain {
|
||||
self.eth1_service = eth1_service_option;
|
||||
}
|
||||
self.beacon_chain_builder = Some(beacon_chain_builder);
|
||||
Ok(self)
|
||||
}
|
||||
@@ -789,7 +860,6 @@ where
|
||||
/// Specifies that the `Client` should use a `HotColdDB` database.
|
||||
pub fn disk_store(
|
||||
mut self,
|
||||
datadir: &Path,
|
||||
hot_path: &Path,
|
||||
cold_path: &Path,
|
||||
config: StoreConfig,
|
||||
@@ -809,10 +879,16 @@ where
|
||||
self.freezer_db_path = Some(cold_path.into());
|
||||
|
||||
let inner_spec = spec.clone();
|
||||
let deposit_contract_deploy_block = context
|
||||
.eth2_network_config
|
||||
.as_ref()
|
||||
.map(|config| config.deposit_contract_deploy_block)
|
||||
.unwrap_or(0);
|
||||
|
||||
let schema_upgrade = |db, from, to| {
|
||||
migrate_schema::<Witness<TSlotClock, TEth1Backend, _, _, _>>(
|
||||
db,
|
||||
datadir,
|
||||
deposit_contract_deploy_block,
|
||||
from,
|
||||
to,
|
||||
log,
|
||||
|
||||
@@ -43,7 +43,7 @@ pub enum ClientGenesis {
|
||||
/// The core configuration of a Lighthouse beacon node.
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
pub struct Config {
|
||||
pub data_dir: PathBuf,
|
||||
data_dir: PathBuf,
|
||||
/// Name of the directory inside the data directory where the main "hot" DB is located.
|
||||
pub db_name: String,
|
||||
/// Path where the freezer database will be located.
|
||||
@@ -106,6 +106,17 @@ impl Default for Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
/// Updates the data directory for the Client.
|
||||
pub fn set_data_dir(&mut self, data_dir: PathBuf) {
|
||||
self.data_dir = data_dir.clone();
|
||||
self.http_api.data_dir = data_dir;
|
||||
}
|
||||
|
||||
/// Gets the config's data_dir.
|
||||
pub fn data_dir(&self) -> &PathBuf {
|
||||
&self.data_dir
|
||||
}
|
||||
|
||||
/// Get the database path without initialising it.
|
||||
pub fn get_db_path(&self) -> PathBuf {
|
||||
self.get_data_dir().join(&self.db_name)
|
||||
|
||||
Reference in New Issue
Block a user