Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OLD] feat(client): providers generic over oracles #324

Closed
wants to merge 17 commits into from
140 changes: 129 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 9 additions & 2 deletions bin/client/src/comms/caching_oracle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
//!
//! [OracleReader]: kona_preimage::OracleReader

use crate::ORACLE_READER;
use crate::{HINT_WRITER, ORACLE_READER};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use anyhow::Result;
use async_trait::async_trait;
use core::num::NonZeroUsize;
use kona_preimage::{PreimageKey, PreimageOracleClient};
use kona_preimage::{HintWriterClient, PreimageKey, PreimageOracleClient};
use lru::LruCache;
use spin::Mutex;

Expand Down Expand Up @@ -63,3 +63,10 @@ impl PreimageOracleClient for CachingOracle {
}
}
}

#[async_trait]
impl HintWriterClient for CachingOracle {
async fn write(&self, hint: &str) -> Result<()> {
HINT_WRITER.write(hint).await
}
}
4 changes: 2 additions & 2 deletions bin/client/src/kona.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use alloc::sync::Arc;
use alloy_consensus::Header;
use kona_client::{
l1::{DerivationDriver, OracleBlobProvider, OracleL1ChainProvider},
l2::{OracleL2ChainProvider, TrieDBHintWriter},
l2::OracleL2ChainProvider,
BootInfo, CachingOracle,
};
use kona_common_proc::client_entry;
Expand Down Expand Up @@ -60,8 +60,8 @@ fn main() -> Result<()> {
let mut executor = StatelessL2BlockExecutor::new(
&boot.rollup_config,
driver.take_l2_safe_head_header(),
l2_provider.clone(),
l2_provider,
TrieDBHintWriter,
);
let Header { number, .. } = *executor.execute_payload(attributes)?;
let output_root = executor.compute_output_root()?;
Expand Down
16 changes: 8 additions & 8 deletions bin/client/src/l1/blob_provider.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Contains the concrete implementation of the [BlobProvider] trait for the client program.

use crate::{CachingOracle, HintType, HINT_WRITER};
use crate::HintType;
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::Blob;
use alloy_eips::eip4844::FIELD_ELEMENTS_PER_BLOB;
Expand All @@ -10,18 +10,18 @@ use kona_derive::{
traits::BlobProvider,
types::{BlobProviderError, IndexedBlobHash},
};
use kona_preimage::{HintWriterClient, PreimageKey, PreimageKeyType, PreimageOracleClient};
use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType};
use kona_primitives::BlockInfo;

/// An oracle-backed blob provider.
#[derive(Debug, Clone)]
pub struct OracleBlobProvider {
oracle: Arc<CachingOracle>,
pub struct OracleBlobProvider<T: CommsClient> {
oracle: Arc<T>,
}

impl OracleBlobProvider {
impl<T: CommsClient> OracleBlobProvider<T> {
/// Constructs a new `OracleBlobProvider`.
pub fn new(oracle: Arc<CachingOracle>) -> Self {
pub fn new(oracle: Arc<T>) -> Self {
Self { oracle }
}

Expand All @@ -45,7 +45,7 @@ impl OracleBlobProvider {
blob_req_meta[40..48].copy_from_slice(block_ref.timestamp.to_be_bytes().as_ref());

// Send a hint for the blob commitment and field elements.
HINT_WRITER.write(&HintType::L1Blob.encode_with(&[blob_req_meta.as_ref()])).await?;
self.oracle.write(&HintType::L1Blob.encode_with(&[blob_req_meta.as_ref()])).await?;

// Fetch the blob commitment.
let mut commitment = [0u8; 48];
Expand Down Expand Up @@ -77,7 +77,7 @@ impl OracleBlobProvider {
}

#[async_trait]
impl BlobProvider for OracleBlobProvider {
impl<T: CommsClient + Sync + Send> BlobProvider for OracleBlobProvider<T> {
async fn get_blobs(
&mut self,
block_ref: &BlockInfo,
Expand Down
Loading