mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 09:16:00 +00:00
Thread TTD into execution layer
This commit is contained in:
@@ -147,10 +147,15 @@ where
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let terminal_total_difficulty = config
|
||||||
|
.terminal_total_difficulty_override
|
||||||
|
.unwrap_or(spec.terminal_total_difficulty);
|
||||||
|
|
||||||
let execution_layer = if let Some(execution_endpoints) = config.execution_endpoints {
|
let execution_layer = if let Some(execution_endpoints) = config.execution_endpoints {
|
||||||
let context = runtime_context.service_context("exec".into());
|
let context = runtime_context.service_context("exec".into());
|
||||||
let execution_layer = ExecutionLayer::from_urls(
|
let execution_layer = ExecutionLayer::from_urls(
|
||||||
execution_endpoints,
|
execution_endpoints,
|
||||||
|
terminal_total_difficulty,
|
||||||
context.executor.clone(),
|
context.executor.clone(),
|
||||||
context.log().clone(),
|
context.log().clone(),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use sensitive_url::SensitiveUrl;
|
|||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use types::{Graffiti, PublicKeyBytes};
|
use types::{Graffiti, PublicKeyBytes, Uint256};
|
||||||
|
|
||||||
/// Default directory name for the freezer database under the top-level data dir.
|
/// Default directory name for the freezer database under the top-level data dir.
|
||||||
const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db";
|
const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db";
|
||||||
@@ -75,7 +75,7 @@ pub struct Config {
|
|||||||
pub chain: beacon_chain::ChainConfig,
|
pub chain: beacon_chain::ChainConfig,
|
||||||
pub eth1: eth1::Config,
|
pub eth1: eth1::Config,
|
||||||
pub execution_endpoints: Option<Vec<SensitiveUrl>>,
|
pub execution_endpoints: Option<Vec<SensitiveUrl>>,
|
||||||
pub total_terminal_difficulty_override: Option<u64>,
|
pub terminal_total_difficulty_override: Option<Uint256>,
|
||||||
pub http_api: http_api::Config,
|
pub http_api: http_api::Config,
|
||||||
pub http_metrics: http_metrics::Config,
|
pub http_metrics: http_metrics::Config,
|
||||||
pub monitoring_api: Option<monitoring_api::Config>,
|
pub monitoring_api: Option<monitoring_api::Config>,
|
||||||
@@ -97,7 +97,7 @@ impl Default for Config {
|
|||||||
sync_eth1_chain: false,
|
sync_eth1_chain: false,
|
||||||
eth1: <_>::default(),
|
eth1: <_>::default(),
|
||||||
execution_endpoints: None,
|
execution_endpoints: None,
|
||||||
total_terminal_difficulty_override: None,
|
terminal_total_difficulty_override: None,
|
||||||
disabled_forks: Vec::new(),
|
disabled_forks: Vec::new(),
|
||||||
graffiti: Graffiti::default(),
|
graffiti: Graffiti::default(),
|
||||||
http_api: <_>::default(),
|
http_api: <_>::default(),
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ impl From<ApiError> for Error {
|
|||||||
|
|
||||||
struct Inner {
|
struct Inner {
|
||||||
engines: Engines<HttpJsonRpc>,
|
engines: Engines<HttpJsonRpc>,
|
||||||
total_terminal_difficulty: Uint256,
|
terminal_total_difficulty: Uint256,
|
||||||
executor: TaskExecutor,
|
executor: TaskExecutor,
|
||||||
log: Logger,
|
log: Logger,
|
||||||
}
|
}
|
||||||
@@ -43,7 +43,7 @@ pub struct ExecutionLayer {
|
|||||||
impl ExecutionLayer {
|
impl ExecutionLayer {
|
||||||
pub fn from_urls(
|
pub fn from_urls(
|
||||||
urls: Vec<SensitiveUrl>,
|
urls: Vec<SensitiveUrl>,
|
||||||
total_terminal_difficulty: Uint256,
|
terminal_total_difficulty: Uint256,
|
||||||
executor: TaskExecutor,
|
executor: TaskExecutor,
|
||||||
log: Logger,
|
log: Logger,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, Error> {
|
||||||
@@ -61,7 +61,7 @@ impl ExecutionLayer {
|
|||||||
engines,
|
engines,
|
||||||
log: log.clone(),
|
log: log.clone(),
|
||||||
},
|
},
|
||||||
total_terminal_difficulty,
|
terminal_total_difficulty,
|
||||||
executor,
|
executor,
|
||||||
log,
|
log,
|
||||||
};
|
};
|
||||||
@@ -81,8 +81,8 @@ impl ExecutionLayer {
|
|||||||
&self.inner.executor
|
&self.inner.executor
|
||||||
}
|
}
|
||||||
|
|
||||||
fn total_terminal_difficulty(&self) -> Uint256 {
|
fn terminal_total_difficulty(&self) -> Uint256 {
|
||||||
self.inner.total_terminal_difficulty
|
self.inner.terminal_total_difficulty
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log(&self) -> &Logger {
|
fn log(&self) -> &Logger {
|
||||||
@@ -226,7 +226,7 @@ impl ExecutionLayer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn find_ttd_block_hash(&self) -> Result<Option<Hash256>, Error> {
|
pub async fn get_pow_block_at_total_difficulty(&self) -> Result<Option<Hash256>, Error> {
|
||||||
self.engines()
|
self.engines()
|
||||||
.first_success(|engine| async move {
|
.first_success(|engine| async move {
|
||||||
let mut ttd_exceeding_block = None;
|
let mut ttd_exceeding_block = None;
|
||||||
@@ -236,7 +236,7 @@ impl ExecutionLayer {
|
|||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
if block.total_difficulty >= self.total_terminal_difficulty() {
|
if block.total_difficulty >= self.terminal_total_difficulty() {
|
||||||
ttd_exceeding_block = Some(block.block_hash);
|
ttd_exceeding_block = Some(block.block_hash);
|
||||||
|
|
||||||
block = engine.api.get_block_by_hash(block.parent_hash).await?;
|
block = engine.api.get_block_by_hash(block.parent_hash).await?;
|
||||||
|
|||||||
@@ -224,7 +224,7 @@ pub fn get_config<E: EthSpec>(
|
|||||||
client_config.execution_endpoints = Some(client_config.eth1.endpoints.clone());
|
client_config.execution_endpoints = Some(client_config.eth1.endpoints.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(total_terminal_difficulty) =
|
if let Some(terminal_total_difficulty) =
|
||||||
clap_utils::parse_optional(cli_args, "total-terminal-difficulty-override")?
|
clap_utils::parse_optional(cli_args, "total-terminal-difficulty-override")?
|
||||||
{
|
{
|
||||||
if client_config.execution_endpoints.is_none() {
|
if client_config.execution_endpoints.is_none() {
|
||||||
@@ -234,7 +234,7 @@ pub fn get_config<E: EthSpec>(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
client_config.total_terminal_difficulty_override = Some(total_terminal_difficulty);
|
client_config.terminal_total_difficulty_override = Some(terminal_total_difficulty);
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(freezer_dir) = cli_args.value_of("freezer-dir") {
|
if let Some(freezer_dir) = cli_args.value_of("freezer-dir") {
|
||||||
|
|||||||
Reference in New Issue
Block a user