Skip to content

Commit

Permalink
Checking of the epoch while sending the lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
mskrzypkows committed Jul 17, 2024
1 parent 9aafb16 commit 652df1d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
7 changes: 2 additions & 5 deletions Node/src/ethereum_l1/consensus_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Vec<ProposerDuty>, Error> {
pub async fn get_current_epoch(&self) -> Result<u64, Error> {
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<Vec<ProposerDuty>, Error> {
Expand Down
2 changes: 1 addition & 1 deletion Node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
31 changes: 20 additions & 11 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
avs_p2p_tx: Sender<String>,
taiko: Taiko,
ethereum_l1: EthereumL1,
mev_boost: MevBoost,
) -> Self {
Self {
) -> Result<Self, Error> {
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:
Expand Down Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion Node/src/utils/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,4 @@ L1 slot duration: {}

config
}
}
}

0 comments on commit 652df1d

Please sign in to comment.