diff --git a/Node/src/ethereum_l1/execution_layer.rs b/Node/src/ethereum_l1/execution_layer.rs index ce6a930..7bfb450 100644 --- a/Node/src/ethereum_l1/execution_layer.rs +++ b/Node/src/ethereum_l1/execution_layer.rs @@ -251,7 +251,7 @@ impl ExecutionLayer { ) .chain_id(self.l1_chain_id) .nonce(nonce) - .gas(500_000) + .gas(1_000_000) .max_fee_per_gas(20_000_000_000) .max_priority_fee_per_gas(1_000_000_000); @@ -597,7 +597,10 @@ impl ExecutionLayer { let tx = contract .forcePushLookahead(lookahead_set_params) .nonce(self.get_preconfer_nonce().await?) - .gas(1_000_000); + .gas(10_000_000) + .max_fee_per_gas(20_000_000_000) + .max_priority_fee_per_gas(1_000_000_000); + match tx.send().await { Ok(receipt) => { tracing::debug!("Force push lookahead sent: {}", receipt.tx_hash()); diff --git a/Node/src/node/mod.rs b/Node/src/node/mod.rs index 7d1b518..7de7d30 100644 --- a/Node/src/node/mod.rs +++ b/Node/src/node/mod.rs @@ -315,10 +315,6 @@ impl Node { self.preconfirm_last_slot().await?; } OperatorStatus::Preconfer => { - if !self.is_preconfer_now.load(Ordering::Acquire) { - self.is_preconfer_now.store(true, Ordering::Release); - self.start_propose().await?; - } self.preconfirm_block(true).await?; } OperatorStatus::None => { @@ -331,6 +327,9 @@ impl Node { .slot_clock .get_l2_slot_number_within_l1_slot()? ); + + // TODO: add flag for turning it on + self.operator.check_empty_lookahead().await?; } } @@ -440,12 +439,16 @@ impl Node { .get_l2_slot_number_within_l1_slot()? ); + if !self.is_preconfer_now.load(Ordering::Acquire) { + self.is_preconfer_now.store(true, Ordering::Release); + self.start_propose().await?; + } + let lookahead_params = self.get_lookahead_params().await?; let pending_tx_lists = self.taiko.get_pending_l2_tx_lists().await?; let pending_tx_lists_bytes = if pending_tx_lists.tx_list_bytes.is_empty() { if let Some(lookahead_params) = lookahead_params { debug!("No pending transactions to preconfirm, force pushing lookahead"); - self.preconfirmation_helper.increment_nonce(); if let Err(err) = self .ethereum_l1 .execution_layer @@ -457,6 +460,8 @@ impl Node { } else { error!("Failed to force push lookahead: {}", err); } + } else { + self.preconfirmation_helper.increment_nonce(); } } // No transactions skip preconfirmation step @@ -469,7 +474,10 @@ impl Node { pending_tx_lists.tx_list_bytes[0].clone() // TODO: handle multiple tx lists }; - let new_block_height = pending_tx_lists.parent_block_id + 1; + let new_block_height = self + .preconfirmation_helper + .get_new_block_id(pending_tx_lists.parent_block_id); + debug!("Preconfirming block with the height: {}", new_block_height); let (commit_hash, signature) = self.generate_commit_hash_and_signature(&pending_tx_lists, new_block_height)?; diff --git a/Node/src/node/operator.rs b/Node/src/node/operator.rs index 051da22..c43c408 100644 --- a/Node/src/node/operator.rs +++ b/Node/src/node/operator.rs @@ -4,7 +4,7 @@ use crate::{ }; use anyhow::Error; use std::sync::Arc; -use tracing::debug; +use tracing::{debug, error}; pub struct Operator { ethereum_l1: Arc, @@ -162,6 +162,40 @@ impl Operator { Ok(lookahead_pointer) } + + pub async fn check_empty_lookahead(&mut self) -> Result<(), Error> { + debug!("Checking empty lookahead"); + + let is_required = self + .ethereum_l1 + .execution_layer + .is_lookahead_required() + .await?; + + if is_required { + self.update_preconfer_lookahead_for_epoch().await?; + if self + .lookahead_preconfer_addresses + .iter() + .all(|addr| *addr == PRECONFER_ADDRESS_ZERO) + { + debug!("Lookahead is empty, force pushing"); + match self.ethereum_l1.force_push_lookahead().await { + Ok(_) => { + debug!("Force pushed lookahead"); + } + Err(err) => { + if err.to_string().contains("AlreadyKnown") { + debug!("Force push lookahead already known"); + } else { + error!("Failed to force push lookahead: {}", err); + } + } + } + } + } + Ok(()) + } } #[cfg(test)] diff --git a/Node/src/node/preconfirmation_helper.rs b/Node/src/node/preconfirmation_helper.rs index ad0abff..177da3e 100644 --- a/Node/src/node/preconfirmation_helper.rs +++ b/Node/src/node/preconfirmation_helper.rs @@ -1,10 +1,14 @@ pub struct PreconfirmationHelper { nonce: u64, + last_block_id: u64, } impl PreconfirmationHelper { pub fn new() -> Self { - Self { nonce: 0 } + Self { + nonce: 0, + last_block_id: 0, + } } pub fn init(&mut self, nonce: u64) { @@ -20,4 +24,31 @@ impl PreconfirmationHelper { pub fn increment_nonce(&mut self) { self.nonce += 1; } + + pub fn get_new_block_id(&mut self, parent_block_id: u64) -> u64 { + let mut new_block_id = parent_block_id + 1; + if self.last_block_id >= new_block_id { + new_block_id = self.last_block_id + 1; + } + self.last_block_id = new_block_id; + new_block_id + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_get_new_block_id() { + let mut helper = PreconfirmationHelper::new(); + assert_eq!(helper.get_new_block_id(0), 1); + assert_eq!(helper.get_new_block_id(0), 2); + assert_eq!(helper.get_new_block_id(0), 3); + assert_eq!(helper.get_new_block_id(0), 4); + assert_eq!(helper.get_new_block_id(4), 5); + assert_eq!(helper.get_new_block_id(4), 6); + assert_eq!(helper.get_new_block_id(4), 7); + assert_eq!(helper.get_new_block_id(4), 8); + } }