From 652df1de79eaa26a272dfeb64c7082356c850ea1 Mon Sep 17 00:00:00 2001 From: Maciej Skrzypkowski Date: Wed, 17 Jul 2024 13:24:04 +0200 Subject: [PATCH] Checking of the epoch while sending the lookahead --- Node/src/ethereum_l1/consensus_layer.rs | 7 ++---- Node/src/main.rs | 2 +- Node/src/node/mod.rs | 31 ++++++++++++++++--------- Node/src/utils/config.rs | 2 +- 4 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Node/src/ethereum_l1/consensus_layer.rs b/Node/src/ethereum_l1/consensus_layer.rs index cde75f8..58eaa0e 100644 --- a/Node/src/ethereum_l1/consensus_layer.rs +++ b/Node/src/ethereum_l1/consensus_layer.rs @@ -13,13 +13,10 @@ impl ConsensusLayer { Ok(Self { client }) } - // First iteration we get the next lookahead by checking the actual epoch number - // this will be improved so we keep synchronization with the CL - pub async fn get_latest_lookahead(&self) -> Result, Error> { + pub async fn get_current_epoch(&self) -> Result { let header = self.client.get_beacon_header_at_head().await?; let slot = header.header.message.slot; - let epoch = slot / 32; - self.get_lookahead(epoch + 1).await + Ok(slot / 32) } pub async fn get_lookahead(&self, epoch: u64) -> Result, Error> { diff --git a/Node/src/main.rs b/Node/src/main.rs index ad7904f..8cbf4cd 100644 --- a/Node/src/main.rs +++ b/Node/src/main.rs @@ -29,7 +29,7 @@ async fn main() -> Result<(), Error> { ) .await?; let mev_boost = mev_boost::MevBoost::new(&config.mev_boost_url); - let node = node::Node::new(node_rx, avs_p2p_tx, taiko, ethereum_l1, mev_boost); + let node = node::Node::new(node_rx, avs_p2p_tx, taiko, ethereum_l1, mev_boost).await?; node.entrypoint().await?; Ok(()) } diff --git a/Node/src/node/mod.rs b/Node/src/node/mod.rs index 072007a..4fea0dd 100644 --- a/Node/src/node/mod.rs +++ b/Node/src/node/mod.rs @@ -9,24 +9,27 @@ pub struct Node { gas_used: u64, ethereum_l1: EthereumL1, _mev_boost: MevBoost, // temporary unused + epoch: u64, } impl Node { - pub fn new( + pub async fn new( node_rx: Receiver, avs_p2p_tx: Sender, taiko: Taiko, ethereum_l1: EthereumL1, mev_boost: MevBoost, - ) -> Self { - Self { + ) -> Result { + let epoch = ethereum_l1.consensus_layer.get_current_epoch().await?; + Ok(Self { taiko, node_rx: Some(node_rx), avs_p2p_tx, gas_used: 0, ethereum_l1, _mev_boost: mev_boost, - } + epoch, + }) } /// Consumes the Node and starts two loops: @@ -58,7 +61,7 @@ impl Node { } } - async fn preconfirmation_loop(&self) { + async fn preconfirmation_loop(&mut self) { loop { let start_time = tokio::time::Instant::now(); if let Err(err) = self.main_block_preconfirmation_step().await { @@ -70,7 +73,7 @@ impl Node { } } - async fn main_block_preconfirmation_step(&self) -> Result<(), Error> { + async fn main_block_preconfirmation_step(&mut self) -> Result<(), Error> { let pending_tx_lists = self .taiko .get_pending_l2_tx_lists() @@ -85,11 +88,17 @@ impl Node { self.taiko .advance_head_to_new_l2_block(pending_tx_lists.tx_lists, self.gas_used) .await?; - let lookahead = self - .ethereum_l1 - .consensus_layer - .get_latest_lookahead() - .await?; + + let current_epoch = self.ethereum_l1.consensus_layer.get_current_epoch().await?; + let lookahead = if current_epoch != self.epoch { + self.epoch = current_epoch; + self.ethereum_l1 + .consensus_layer + .get_lookahead(self.epoch + 1) + .await? + } else { + vec![] + }; self.ethereum_l1 .execution_layer .propose_new_block( diff --git a/Node/src/utils/config.rs b/Node/src/utils/config.rs index 3b0da95..857db25 100644 --- a/Node/src/utils/config.rs +++ b/Node/src/utils/config.rs @@ -74,4 +74,4 @@ L1 slot duration: {} config } -} \ No newline at end of file +}