diff --git a/bin/client/src/kona.rs b/bin/client/src/kona.rs index cb8e09d61..28ac7dd30 100644 --- a/bin/client/src/kona.rs +++ b/bin/client/src/kona.rs @@ -8,15 +8,12 @@ extern crate alloc; use alloc::sync::Arc; -use alloy_consensus::Header; use kona_client::{ l1::{DerivationDriver, OracleBlobProvider, OracleL1ChainProvider}, l2::OracleL2ChainProvider, BootInfo, CachingOracle, }; use kona_common_proc::client_entry; -use kona_executor::StatelessL2BlockExecutor; -use op_alloy_rpc_types_engine::OptimismAttributesWithParent; pub(crate) mod fault; use fault::{fpvm_handle_register, HINT_WRITER, ORACLE_READER}; @@ -50,6 +47,7 @@ fn main() -> Result<()> { // DERIVATION & EXECUTION // //////////////////////////////////////////////////////////////// + // Create a new derivation driver with the given boot information and oracle. let mut driver = DerivationDriver::new( boot.as_ref(), oracle.as_ref(), @@ -58,19 +56,12 @@ fn main() -> Result<()> { l2_provider.clone(), ) .await?; - let OptimismAttributesWithParent { attributes, .. } = - driver.produce_disputed_payload().await?; - let mut executor = StatelessL2BlockExecutor::builder( - &boot.rollup_config, - l2_provider.clone(), - l2_provider, - ) - .with_parent_header(driver.take_l2_safe_head_header()) - .with_handle_register(fpvm_handle_register) - .build(); - let Header { number, .. } = *executor.execute_payload(attributes)?; - let output_root = executor.compute_output_root()?; + // Run the derivation pipeline until we are able to produce the output root of the claimed + // L2 block. + let (number, output_root) = driver + .produce_output(&boot.rollup_config, &l2_provider, &l2_provider, fpvm_handle_register) + .await?; //////////////////////////////////////////////////////////////// // EPILOGUE // diff --git a/bin/client/src/l1/driver.rs b/bin/client/src/l1/driver.rs index 01e493a7c..d79661b26 100644 --- a/bin/client/src/l1/driver.rs +++ b/bin/client/src/l1/driver.rs @@ -7,6 +7,7 @@ use super::OracleL1ChainProvider; use crate::{l2::OracleL2ChainProvider, BootInfo, HintType}; use alloc::sync::Arc; use alloy_consensus::{Header, Sealed}; +use alloy_primitives::B256; use anyhow::{anyhow, Result}; use core::fmt::Debug; use kona_derive::{ @@ -19,8 +20,10 @@ use kona_derive::{ }, traits::{BlobProvider, ChainProvider, L2ChainProvider, OriginProvider}, }; -use kona_mpt::TrieProvider; +use kona_executor::{KonaHandleRegister, StatelessL2BlockExecutor}; +use kona_mpt::{TrieHinter, TrieProvider}; use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType}; +use op_alloy_genesis::RollupConfig; use op_alloy_protocol::{BlockInfo, L2BlockInfo}; use op_alloy_rpc_types_engine::OptimismAttributesWithParent; use tracing::{info, warn}; @@ -150,14 +153,58 @@ where Ok(Self { l2_safe_head, l2_safe_head_header, pipeline }) } + /// Produces the output root of the next L2 block. + /// + /// ## Takes + /// - `cfg`: The rollup configuration. + /// - `provider`: The trie provider. + /// - `hinter`: The trie hinter. + /// - `handle_register`: The handle register for the EVM. + /// + /// ## Returns + /// - `Ok((number, output_root))` - A tuple containing the number of the produced block and the + /// output root. + /// - `Err(e)` - An error if the block could not be produced. + pub async fn produce_output
( + &mut self, + cfg: &RollupConfig, + provider: &P, + hinter: &H, + handle_register: KonaHandleRegister
,
+ ) -> Result<(u64, B256)>
+ where
+ P: TrieProvider + Send + Sync + Clone,
+ H: TrieHinter + Send + Sync + Clone,
+ {
+ loop {
+ let OptimismAttributesWithParent { attributes, .. } = self.produce_payload().await?;
+
+ let mut executor =
+ StatelessL2BlockExecutor::builder(cfg, provider.clone(), hinter.clone())
+ .with_parent_header(self.l2_safe_head_header().clone())
+ .with_handle_register(handle_register)
+ .build();
+
+ let number = match executor.execute_payload(attributes) {
+ Ok(Header { number, .. }) => *number,
+ Err(e) => {
+ tracing::error!(target: "client", "Failed to execute L2 block: {}", e);
+ continue;
+ }
+ };
+ let output_root = executor.compute_output_root()?;
+
+ return Ok((number, output_root));
+ }
+ }
+
/// Produces the disputed [OptimismAttributesWithParent] payload, directly after the starting L2
/// output root passed through the [BootInfo].
- pub async fn produce_disputed_payload(&mut self) -> Result