-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(driver): Introduce driver crate (#794)
- Loading branch information
Showing
19 changed files
with
845 additions
and
517 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
//! An executor constructor. | ||
use alloc::sync::Arc; | ||
use alloy_consensus::{Header, Sealed}; | ||
use alloy_primitives::B256; | ||
use kona_driver::{Executor, ExecutorConstructor}; | ||
use kona_executor::{KonaHandleRegister, StatelessL2BlockExecutor}; | ||
use kona_mpt::{TrieHinter, TrieProvider}; | ||
use op_alloy_genesis::RollupConfig; | ||
use op_alloy_rpc_types_engine::OpPayloadAttributes; | ||
|
||
/// An executor wrapper type. | ||
#[derive(Debug)] | ||
pub struct KonaExecutor<'a, P, H>(StatelessL2BlockExecutor<'a, P, H>) | ||
where | ||
P: TrieProvider + Send + Sync + Clone, | ||
H: TrieHinter + Send + Sync + Clone; | ||
|
||
impl<'a, P, H> KonaExecutor<'a, P, H> | ||
where | ||
P: TrieProvider + Send + Sync + Clone, | ||
H: TrieHinter + Send + Sync + Clone, | ||
{ | ||
/// Creates a new executor. | ||
pub fn new(executor: StatelessL2BlockExecutor<'a, P, H>) -> Self { | ||
Self(executor) | ||
} | ||
} | ||
|
||
impl<P, H> Executor for KonaExecutor<'_, P, H> | ||
where | ||
P: TrieProvider + Send + Sync + Clone, | ||
H: TrieHinter + Send + Sync + Clone, | ||
{ | ||
type Error = kona_executor::ExecutorError; | ||
|
||
/// Execute the given payload attributes. | ||
fn execute_payload(&mut self, attributes: OpPayloadAttributes) -> Result<&Header, Self::Error> { | ||
self.0.execute_payload(attributes) | ||
} | ||
|
||
/// Computes the output root. | ||
fn compute_output_root(&mut self) -> Result<B256, Self::Error> { | ||
self.0.compute_output_root() | ||
} | ||
} | ||
|
||
/// An executor constructor. | ||
#[derive(Debug)] | ||
pub struct KonaExecutorConstructor<'a, P, H> | ||
where | ||
P: TrieProvider + Send + Sync + Clone, | ||
H: TrieHinter + Send + Sync + Clone, | ||
{ | ||
/// The rollup config for the executor. | ||
rollup_config: &'a Arc<RollupConfig>, | ||
/// The trie provider for the executor. | ||
trie_provider: P, | ||
/// The trie hinter for the executor. | ||
trie_hinter: H, | ||
/// The handle register for the executor. | ||
handle_register: KonaHandleRegister<P, H>, | ||
} | ||
|
||
impl<'a, P, H> KonaExecutorConstructor<'a, P, H> | ||
where | ||
P: TrieProvider + Send + Sync + Clone, | ||
H: TrieHinter + Send + Sync + Clone, | ||
{ | ||
/// Creates a new executor constructor. | ||
pub fn new( | ||
rollup_config: &'a Arc<RollupConfig>, | ||
trie_provider: P, | ||
trie_hinter: H, | ||
handle_register: KonaHandleRegister<P, H>, | ||
) -> Self { | ||
Self { rollup_config, trie_provider, trie_hinter, handle_register } | ||
} | ||
} | ||
|
||
impl<'a, P, H> ExecutorConstructor<KonaExecutor<'a, P, H>> for KonaExecutorConstructor<'a, P, H> | ||
where | ||
P: TrieProvider + Send + Sync + Clone, | ||
H: TrieHinter + Send + Sync + Clone, | ||
{ | ||
/// Constructs the executor. | ||
fn new_executor(&self, header: Sealed<Header>) -> KonaExecutor<'a, P, H> { | ||
KonaExecutor::new( | ||
StatelessL2BlockExecutor::builder( | ||
self.rollup_config, | ||
self.trie_provider.clone(), | ||
self.trie_hinter.clone(), | ||
) | ||
.with_parent_header(header) | ||
.with_handle_register(self.handle_register) | ||
.build(), | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.