From 6cf83db13f1cfef9ba3eae9c567eb952f96af004 Mon Sep 17 00:00:00 2001 From: Paul Hauner Date: Mon, 27 Sep 2021 16:11:54 +1000 Subject: [PATCH] Thread TTD into execution layer --- beacon_node/client/src/builder.rs | 5 +++++ beacon_node/client/src/config.rs | 6 +++--- beacon_node/execution_layer/src/lib.rs | 14 +++++++------- beacon_node/src/config.rs | 4 ++-- 4 files changed, 17 insertions(+), 12 deletions(-) diff --git a/beacon_node/client/src/builder.rs b/beacon_node/client/src/builder.rs index 4ae896fd30..4acee035fd 100644 --- a/beacon_node/client/src/builder.rs +++ b/beacon_node/client/src/builder.rs @@ -147,10 +147,15 @@ where 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 context = runtime_context.service_context("exec".into()); let execution_layer = ExecutionLayer::from_urls( execution_endpoints, + terminal_total_difficulty, context.executor.clone(), context.log().clone(), ) diff --git a/beacon_node/client/src/config.rs b/beacon_node/client/src/config.rs index a3791c8a9c..f21becb276 100644 --- a/beacon_node/client/src/config.rs +++ b/beacon_node/client/src/config.rs @@ -4,7 +4,7 @@ use sensitive_url::SensitiveUrl; use serde_derive::{Deserialize, Serialize}; use std::fs; 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. const DEFAULT_FREEZER_DB_DIR: &str = "freezer_db"; @@ -75,7 +75,7 @@ pub struct Config { pub chain: beacon_chain::ChainConfig, pub eth1: eth1::Config, pub execution_endpoints: Option>, - pub total_terminal_difficulty_override: Option, + pub terminal_total_difficulty_override: Option, pub http_api: http_api::Config, pub http_metrics: http_metrics::Config, pub monitoring_api: Option, @@ -97,7 +97,7 @@ impl Default for Config { sync_eth1_chain: false, eth1: <_>::default(), execution_endpoints: None, - total_terminal_difficulty_override: None, + terminal_total_difficulty_override: None, disabled_forks: Vec::new(), graffiti: Graffiti::default(), http_api: <_>::default(), diff --git a/beacon_node/execution_layer/src/lib.rs b/beacon_node/execution_layer/src/lib.rs index da58853a78..525b8fae36 100644 --- a/beacon_node/execution_layer/src/lib.rs +++ b/beacon_node/execution_layer/src/lib.rs @@ -30,7 +30,7 @@ impl From for Error { struct Inner { engines: Engines, - total_terminal_difficulty: Uint256, + terminal_total_difficulty: Uint256, executor: TaskExecutor, log: Logger, } @@ -43,7 +43,7 @@ pub struct ExecutionLayer { impl ExecutionLayer { pub fn from_urls( urls: Vec, - total_terminal_difficulty: Uint256, + terminal_total_difficulty: Uint256, executor: TaskExecutor, log: Logger, ) -> Result { @@ -61,7 +61,7 @@ impl ExecutionLayer { engines, log: log.clone(), }, - total_terminal_difficulty, + terminal_total_difficulty, executor, log, }; @@ -81,8 +81,8 @@ impl ExecutionLayer { &self.inner.executor } - fn total_terminal_difficulty(&self) -> Uint256 { - self.inner.total_terminal_difficulty + fn terminal_total_difficulty(&self) -> Uint256 { + self.inner.terminal_total_difficulty } fn log(&self) -> &Logger { @@ -226,7 +226,7 @@ impl ExecutionLayer { } } - pub async fn find_ttd_block_hash(&self) -> Result, Error> { + pub async fn get_pow_block_at_total_difficulty(&self) -> Result, Error> { self.engines() .first_success(|engine| async move { let mut ttd_exceeding_block = None; @@ -236,7 +236,7 @@ impl ExecutionLayer { .await?; loop { - if block.total_difficulty >= self.total_terminal_difficulty() { + if block.total_difficulty >= self.terminal_total_difficulty() { ttd_exceeding_block = Some(block.block_hash); block = engine.api.get_block_by_hash(block.parent_hash).await?; diff --git a/beacon_node/src/config.rs b/beacon_node/src/config.rs index 6d29d613db..b984d50477 100644 --- a/beacon_node/src/config.rs +++ b/beacon_node/src/config.rs @@ -224,7 +224,7 @@ pub fn get_config( 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")? { if client_config.execution_endpoints.is_none() { @@ -234,7 +234,7 @@ pub fn get_config( ); } - 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") {