Skip to content

Commit

Permalink
Add CLI command for force pushing lookahead
Browse files Browse the repository at this point in the history
  • Loading branch information
mikhailUshakoff committed Sep 20, 2024
1 parent 1f78e24 commit 762ae85
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 25 deletions.
24 changes: 23 additions & 1 deletion Node/src/ethereum_l1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub mod slot_clock;
mod ws_provider;

use crate::{bls::BLSService, utils::config::ContractAddresses};
use anyhow::Error;
use consensus_layer::ConsensusLayer;
#[cfg(not(test))]
use execution_layer::ExecutionLayer;
Expand Down Expand Up @@ -37,7 +38,7 @@ impl EthereumL1 {
preconf_registry_expiry_sec: u64,
bls_service: Arc<BLSService>,
l1_chain_id: u64,
) -> Result<Self, anyhow::Error> {
) -> Result<Self, Error> {
let consensus_layer = ConsensusLayer::new(consensus_rpc_url)?;
let genesis_details = consensus_layer.get_genesis_details().await?;
let slot_clock = Arc::new(SlotClock::new(
Expand All @@ -64,4 +65,25 @@ impl EthereumL1 {
execution_layer,
})
}

pub async fn force_push_lookahead(&self) -> Result<(), Error> {
// Get next epoch
let next_epoch = self.slot_clock.get_current_epoch()? + 1;
// Get CL lookahead for the next epoch
let cl_lookahead = self.consensus_layer.get_lookahead(next_epoch).await?;
// Get lookahead params for contract call
let lookahead_params = self
.execution_layer
.get_lookahead_params_for_epoch_using_cl_lookahead(
self.slot_clock.get_epoch_begin_timestamp(next_epoch)?,
&cl_lookahead,
)
.await?;
// Force push lookahead to the contract
self.execution_layer
.force_push_lookahead(lookahead_params)
.await?;

Ok(())
}
}
7 changes: 7 additions & 0 deletions Node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct Cli {
register: bool,
#[clap(long, help = "Add validator to preconfer")]
add_validator: bool,
#[clap(long, help = "Force Push lookahead to the PreconfTaskManager contract")]
force_push_lookahead: bool,
}

#[tokio::main]
Expand Down Expand Up @@ -59,6 +61,11 @@ async fn main() -> Result<(), Error> {
return Ok(());
}

if args.force_push_lookahead {
ethereum_l1.force_push_lookahead().await?;
return Ok(());
}

let (node_to_p2p_tx, node_to_p2p_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
let (p2p_to_node_tx, p2p_to_node_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
let (block_proposed_tx, block_proposed_rx) = mpsc::channel(MESSAGE_QUEUE_SIZE);
Expand Down
25 changes: 1 addition & 24 deletions Node/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,30 +309,7 @@ impl Node {
.is_lookahead_tail_zero()
.await?;
if is_zero {
// Get next epoch
let next_epoch = self.ethereum_l1.slot_clock.get_current_epoch()? + 1;
// Get CL lookahead for the next epoch
self.cl_lookahead = self
.ethereum_l1
.consensus_layer
.get_lookahead(next_epoch)
.await?;
// Get lookahead params for contract call
let lookahead_params = self
.ethereum_l1
.execution_layer
.get_lookahead_params_for_epoch_using_cl_lookahead(
self.ethereum_l1
.slot_clock
.get_epoch_begin_timestamp(next_epoch)?,
&self.cl_lookahead,
)
.await?;
// Force push lookahead to the contract
self.ethereum_l1
.execution_layer
.force_push_lookahead(lookahead_params)
.await?;
self.ethereum_l1.force_push_lookahead().await?;
}
Ok(())
}
Expand Down

0 comments on commit 762ae85

Please sign in to comment.