Skip to content

Commit 0659f7d

Browse files
committed
Squash merge of #3047
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
1 parent 9000571 commit 0659f7d

File tree

5 files changed

+98
-0
lines changed

5 files changed

+98
-0
lines changed

beacon_node/client/src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,9 @@ where
725725
execution_layer.spawn_clean_proposer_preparation_routine::<TSlotClock, TEthSpec>(
726726
beacon_chain.slot_clock.clone(),
727727
);
728+
729+
// Spawns a routine that polls the `exchange_transition_configuration` endpoint.
730+
execution_layer.spawn_transition_configuration_poll(beacon_chain.spec.clone());
728731
}
729732
}
730733

beacon_node/execution_layer/src/engine_api.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use serde::{Deserialize, Serialize};
66
pub const LATEST_TAG: &str = "latest";
77

88
use crate::engines::ForkChoiceState;
9+
pub use json_structures::TransitionConfigurationV1;
910
pub use types::{Address, EthSpec, ExecutionBlockHash, ExecutionPayload, Hash256, Uint256};
1011

1112
pub mod auth;
@@ -87,6 +88,11 @@ pub trait EngineApi {
8788
forkchoice_state: ForkChoiceState,
8889
payload_attributes: Option<PayloadAttributes>,
8990
) -> Result<ForkchoiceUpdatedResponse, Error>;
91+
92+
async fn exchange_transition_configuration_v1(
93+
&self,
94+
transition_configuration: TransitionConfigurationV1,
95+
) -> Result<TransitionConfigurationV1, Error>;
9096
}
9197

9298
#[derive(Clone, Copy, Debug, PartialEq)]

beacon_node/execution_layer/src/engine_api/http.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ pub const ENGINE_GET_PAYLOAD_TIMEOUT: Duration = Duration::from_secs(2);
3737
pub const ENGINE_FORKCHOICE_UPDATED_V1: &str = "engine_forkchoiceUpdatedV1";
3838
pub const ENGINE_FORKCHOICE_UPDATED_TIMEOUT: Duration = Duration::from_millis(500);
3939

40+
pub const ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1: &str =
41+
"engine_exchangeTransitionConfigurationV1";
42+
pub const ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1_TIMEOUT: Duration =
43+
Duration::from_millis(100);
44+
4045
pub struct HttpJsonRpc {
4146
pub client: Client,
4247
pub url: SensitiveUrl,
@@ -192,6 +197,23 @@ impl EngineApi for HttpJsonRpc {
192197

193198
Ok(response.into())
194199
}
200+
201+
async fn exchange_transition_configuration_v1(
202+
&self,
203+
transition_configuration: TransitionConfigurationV1,
204+
) -> Result<TransitionConfigurationV1, Error> {
205+
let params = json!([transition_configuration]);
206+
207+
let response = self
208+
.rpc_request(
209+
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1,
210+
params,
211+
ENGINE_EXCHANGE_TRANSITION_CONFIGURATION_V1_TIMEOUT,
212+
)
213+
.await?;
214+
215+
Ok(response)
216+
}
195217
}
196218

197219
#[cfg(test)]

beacon_node/execution_layer/src/engine_api/json_structures.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,15 @@ impl From<ForkchoiceUpdatedResponse> for JsonForkchoiceUpdatedV1Response {
363363
}
364364
}
365365

366+
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
367+
#[serde(rename_all = "camelCase")]
368+
pub struct TransitionConfigurationV1 {
369+
pub terminal_total_difficulty: Uint256,
370+
pub terminal_block_hash: ExecutionBlockHash,
371+
#[serde(with = "eth2_serde_utils::u64_hex_be")]
372+
pub terminal_block_number: u64,
373+
}
374+
366375
/// Serializes the `logs_bloom` field of an `ExecutionPayload`.
367376
pub mod serde_logs_bloom {
368377
use super::*;

beacon_node/execution_layer/src/lib.rs

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ const EXECUTION_BLOCKS_LRU_CACHE_SIZE: usize = 128;
5151
const DEFAULT_SUGGESTED_FEE_RECIPIENT: [u8; 20] =
5252
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1];
5353

54+
const CONFIG_POLL_INTERVAL: Duration = Duration::from_secs(60);
55+
5456
#[derive(Debug)]
5557
pub enum Error {
5658
NoEngines,
@@ -388,6 +390,18 @@ impl ExecutionLayer {
388390
self.spawn(preparation_cleaner, "exec_preparation_cleanup");
389391
}
390392

393+
/// Spawns a routine that polls the `exchange_transition_configuration` endpoint.
394+
pub fn spawn_transition_configuration_poll(&self, spec: ChainSpec) {
395+
let routine = |el: ExecutionLayer| async move {
396+
loop {
397+
el.exchange_transition_configuration(&spec).await;
398+
sleep(CONFIG_POLL_INTERVAL).await;
399+
}
400+
};
401+
402+
self.spawn(routine, "exec_config_poll");
403+
}
404+
391405
/// Returns `true` if there is at least one synced and reachable engine.
392406
pub async fn is_synced(&self) -> bool {
393407
self.engines().any_synced().await
@@ -636,6 +650,50 @@ impl ExecutionLayer {
636650
)
637651
}
638652

653+
pub async fn exchange_transition_configuration(&self, spec: &ChainSpec) {
654+
let local = TransitionConfigurationV1 {
655+
terminal_total_difficulty: spec.terminal_total_difficulty,
656+
terminal_block_hash: spec.terminal_block_hash,
657+
// TODO(paul): confirm that we don't know this value.
658+
//
659+
// See:
660+
//
661+
// https://discord.com/channels/595666850260713488/692062809701482577/947988779203977307
662+
terminal_block_number: 0,
663+
};
664+
665+
let broadcast_results = self
666+
.engines()
667+
.broadcast(|engine| engine.api.exchange_transition_configuration_v1(local))
668+
.await;
669+
670+
for (i, result) in broadcast_results.iter().enumerate() {
671+
match result {
672+
Ok(remote) => {
673+
if local.terminal_total_difficulty != remote.terminal_total_difficulty
674+
|| local.terminal_block_hash != remote.terminal_block_hash
675+
{
676+
error!(
677+
self.log(),
678+
"Execution client config mismatch";
679+
"msg" => "ensure lighthouse and the execution client are up-to-date and \
680+
configured consistently",
681+
"execution_endpoint" => i,
682+
"remote" => ?remote,
683+
"local" => ?local,
684+
)
685+
}
686+
}
687+
Err(e) => error!(
688+
self.log(),
689+
"Unable to get transition config";
690+
"error" => ?e,
691+
"execution_endpoint" => i,
692+
),
693+
}
694+
}
695+
}
696+
639697
/// Used during block production to determine if the merge has been triggered.
640698
///
641699
/// ## Specification

0 commit comments

Comments
 (0)