Skip to content

Commit

Permalink
Merge branch 'ms/lookahead_pointer_fix' into e2e-devnet
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailUshakoff committed Oct 2, 2024
2 parents 5e0220e + 2ac45f1 commit f503111
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
15 changes: 6 additions & 9 deletions Node/src/ethereum_l1/slot_clock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,6 @@ impl SlotClock {
}
}

// returns current real timestamp, the shift is reduced
pub fn get_real_time_for_contract(&self) -> Result<u64, Error> {
Ok(
(std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH)?
+ self.slot_duration)
.as_secs(),
)
}

pub fn get_slots_per_epoch(&self) -> u64 {
self.slots_per_epoch
}
Expand Down Expand Up @@ -134,6 +125,12 @@ impl SlotClock {
Ok(start_of_slot.as_secs())
}

// returns real timestamp, the shift is reduced
pub fn get_real_slot_begin_timestamp_for_contract(&self, slot: Slot) -> Result<u64, Error> {
let start_of_slot = self.start_of(slot)? + self.slot_duration;
Ok(start_of_slot.as_secs())
}

pub fn get_epoch_for_timestamp(&self, timestamp: u64) -> Result<Epoch, Error> {
let slot = self.slot_of(Duration::from_secs(timestamp))?;
Ok(slot / self.slots_per_epoch)
Expand Down
20 changes: 8 additions & 12 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::{
taiko::{l2_tx_lists::RPCReplyL2TxLists, Taiko},
utils::types::*,
};
use anyhow::{anyhow as any_err, Error};
use anyhow::Error;
use commit::L2TxListsCommit;
use operator::{Operator, Status as OperatorStatus};
use preconfirmation_helper::PreconfirmationHelper;
Expand Down Expand Up @@ -484,13 +484,12 @@ impl Node {
&pending_tx_lists_bytes,
proof.clone(),
);
self.send_preconfirmations_to_the_avs_p2p(preconf_message.clone())
.await?;
self.send_preconfirmations_to_the_avs_p2p(preconf_message.clone());
self.taiko
.advance_head_to_new_l2_block(pending_tx_lists.tx_lists)
.await?;

let lookahead_pointer = self.operator.get_lookahead_pointer()?;
let lookahead_pointer = self.operator.get_lookahead_pointer(current_slot)?;
let tx = self
.ethereum_l1
.execution_layer
Expand Down Expand Up @@ -537,17 +536,14 @@ impl Node {
Ok(())
}

async fn send_preconfirmations_to_the_avs_p2p(
&self,
message: PreconfirmationMessage,
) -> Result<(), Error> {
fn send_preconfirmations_to_the_avs_p2p(&self, message: PreconfirmationMessage) {
debug!(
"Send message to p2p, tx list hash: {}",
hex::encode(message.tx_list_hash)
);
self.node_to_p2p_tx
.send(message.into())
.await
.map_err(|e| any_err!("Failed to send message to node_to_p2p_tx: {}", e))

if let Err(err) = self.node_to_p2p_tx.try_send(message.into()) {
error!("Failed to send message to node_to_p2p_tx: {}", err);
}
}
}
12 changes: 8 additions & 4 deletions Node/src/node/operator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,16 +129,19 @@ impl Operator {
Ok(())
}

pub fn get_lookahead_pointer(&mut self) -> Result<u64, Error> {
let contract_timestamp = self.ethereum_l1.slot_clock.get_real_time_for_contract()?;
pub fn get_lookahead_pointer(&mut self, slot: Slot) -> Result<u64, Error> {
let slot_begin_timestamp = self
.ethereum_l1
.slot_clock
.get_real_slot_begin_timestamp_for_contract(slot)?;

let lookahead_pointer = self
.lookahead_preconfer_buffer
.iter()
.position(|entry| {
entry.preconfer == self.ethereum_l1.execution_layer.get_preconfer_address()
&& contract_timestamp > entry.prevTimestamp
&& contract_timestamp <= entry.timestamp
&& slot_begin_timestamp > entry.prevTimestamp
&& slot_begin_timestamp <= entry.timestamp
})
.ok_or_else(|| {
let buffer_str = self
Expand All @@ -152,6 +155,7 @@ impl Operator {
})
.collect::<Vec<String>>()
.join("; ");
debug!("slot_begin_timestamp: {}", slot_begin_timestamp);
debug!("Lookahead buffer: [{}]", buffer_str);
anyhow::anyhow!("get_lookahead_params: Preconfer not found in lookahead")
})? as u64;
Expand Down

0 comments on commit f503111

Please sign in to comment.