Skip to content

Commit

Permalink
Squash merge of #3047
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit b5a711f
Author: Paul Hauner <[email protected]>
Date:   Fri Mar 4 13:10:57 2022 +1100

    Remove "number" rename

commit 3f287d0
Author: Paul Hauner <[email protected]>
Date:   Fri Mar 4 10:46:26 2022 +1100

    Fix method naming

commit b870f70
Author: Paul Hauner <[email protected]>
Date:   Tue Mar 1 10:06:37 2022 +1100

    Add transition config method
  • Loading branch information
paulhauner committed Mar 4, 2022
1 parent b783e86 commit 8537e81
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions beacon_node/client/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,9 @@ where
execution_layer.spawn_clean_proposer_preparation_routine::<TSlotClock, TEthSpec>(
beacon_chain.slot_clock.clone(),
);

// Spawns a routine that polls the `exchange_transition_configuration` endpoint.
execution_layer.spawn_transition_configuration_poll(beacon_chain.spec.clone());
}
}

Expand Down
6 changes: 6 additions & 0 deletions beacon_node/execution_layer/src/engine_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
pub const LATEST_TAG: &str = "latest";

use crate::engines::ForkChoiceState;
pub use json_structures::TransitionConfigurationV1;
pub use types::{Address, EthSpec, ExecutionBlockHash, ExecutionPayload, Hash256, Uint256};

pub mod auth;
Expand Down Expand Up @@ -87,6 +88,11 @@ pub trait EngineApi {
forkchoice_state: ForkChoiceState,
payload_attributes: Option<PayloadAttributes>,
) -> Result<ForkchoiceUpdatedResponse, Error>;

async fn exchange_transition_configuration_v1(
&self,
transition_configuration: TransitionConfigurationV1,
) -> Result<TransitionConfigurationV1, Error>;
}

#[derive(Clone, Copy, Debug, PartialEq)]
Expand Down
22 changes: 22 additions & 0 deletions beacon_node/execution_layer/src/engine_api/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ pub const ENGINE_GET_PAYLOAD_TIMEOUT: Duration = Duration::from_secs(2);
pub const ENGINE_FORKCHOICE_UPDATED_V1: &str = "engine_forkchoiceUpdatedV1";
pub const ENGINE_FORKCHOICE_UPDATED_TIMEOUT: Duration = Duration::from_millis(500);

pub const ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1: &str =
"engine_exchangeTransitionConfigurationV1";
pub const ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1_TIMEOUT: Duration =
Duration::from_millis(100);

pub struct HttpJsonRpc {
pub client: Client,
pub url: SensitiveUrl,
Expand Down Expand Up @@ -192,6 +197,23 @@ impl EngineApi for HttpJsonRpc {

Ok(response.into())
}

async fn exchange_transition_configuration_v1(
&self,
transition_configuration: TransitionConfigurationV1,
) -> Result<TransitionConfigurationV1, Error> {
let params = json!([transition_configuration]);

let response = self
.rpc_request(
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1,
params,
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1_TIMEOUT,
)
.await?;

Ok(response)
}
}

#[cfg(test)]
Expand Down
9 changes: 9 additions & 0 deletions beacon_node/execution_layer/src/engine_api/json_structures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,15 @@ impl From<ForkchoiceUpdatedResponse> for JsonForkchoiceUpdatedV1Response {
}
}

#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TransitionConfigurationV1 {
pub terminal_total_difficulty: Uint256,
pub terminal_block_hash: ExecutionBlockHash,
#[serde(with = "eth2_serde_utils::u64_hex_be")]
pub terminal_block_number: u64,
}

/// Serializes the `logs_bloom` field of an `ExecutionPayload`.
pub mod serde_logs_bloom {
use super::*;
Expand Down
58 changes: 58 additions & 0 deletions beacon_node/execution_layer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ const EXECUTION_BLOCKS_LRU_CACHE_SIZE: usize = 128;
const DEFAULT_SUGGESTED_FEE_RECIPIENT: [u8; 20] =
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];

const CONFIG_POLL_INTERVAL: Duration = Duration::from_secs(60);

#[derive(Debug)]
pub enum Error {
NoEngines,
Expand Down Expand Up @@ -388,6 +390,18 @@ impl ExecutionLayer {
self.spawn(preparation_cleaner, "exec_preparation_cleanup");
}

/// Spawns a routine that polls the `exchange_transition_configuration` endpoint.
pub fn spawn_transition_configuration_poll(&self, spec: ChainSpec) {
let routine = |el: ExecutionLayer| async move {
loop {
el.exchange_transition_configuration(&spec).await;
sleep(CONFIG_POLL_INTERVAL).await;
}
};

self.spawn(routine, "exec_config_poll");
}

/// Returns `true` if there is at least one synced and reachable engine.
pub async fn is_synced(&self) -> bool {
self.engines().any_synced().await
Expand Down Expand Up @@ -636,6 +650,50 @@ impl ExecutionLayer {
)
}

pub async fn exchange_transition_configuration(&self, spec: &ChainSpec) {
let local = TransitionConfigurationV1 {
terminal_total_difficulty: spec.terminal_total_difficulty,
terminal_block_hash: spec.terminal_block_hash,
// TODO(paul): confirm that we don't know this value.
//
// See:
//
// https://discord.com/channels/595666850260713488/692062809701482577/947988779203977307
terminal_block_number: 0,
};

let broadcast_results = self
.engines()
.broadcast(|engine| engine.api.exchange_transition_configuration_v1(local))
.await;

for (i, result) in broadcast_results.iter().enumerate() {
match result {
Ok(remote) => {
if local.terminal_total_difficulty != remote.terminal_total_difficulty
|| local.terminal_block_hash != remote.terminal_block_hash
{
error!(
self.log(),
"Execution client config mismatch";
"msg" => "ensure lighthouse and the execution client are up-to-date and \
configured consistently",
"execution_endpoint" => i,
"remote" => ?remote,
"local" => ?local,
)
}
}
Err(e) => error!(
self.log(),
"Unable to get transition config";
"error" => ?e,
"execution_endpoint" => i,
),
}
}
}

/// Used during block production to determine if the merge has been triggered.
///
/// ## Specification
Expand Down

0 comments on commit 8537e81

Please sign in to comment.