diff --git a/bin/client/src/caching_oracle.rs b/bin/client/src/caching_oracle.rs index a50782f9f..129118195 100644 --- a/bin/client/src/caching_oracle.rs +++ b/bin/client/src/caching_oracle.rs @@ -53,6 +53,23 @@ where } } +/// A trait that provides a method to flush a cache. +pub trait FlushableCache { + /// Flushes the cache, removing all entries. + fn flush(&self); +} + +impl FlushableCache for CachingOracle +where + OR: PreimageOracleClient, + HW: HintWriterClient, +{ + /// Flushes the cache, removing all entries. + fn flush(&self) { + self.cache.lock().clear(); + } +} + #[async_trait] impl PreimageOracleClient for CachingOracle where diff --git a/bin/client/src/kona.rs b/bin/client/src/kona.rs index e1d825a37..1824bfb8f 100644 --- a/bin/client/src/kona.rs +++ b/bin/client/src/kona.rs @@ -48,14 +48,9 @@ fn main() -> Result<()> { //////////////////////////////////////////////////////////////// // Create a new derivation driver with the given boot information and oracle. - let mut driver = DerivationDriver::new( - boot.as_ref(), - oracle.as_ref(), - beacon, - l1_provider, - l2_provider.clone(), - ) - .await?; + let mut driver = + DerivationDriver::new(boot.as_ref(), &oracle, beacon, l1_provider, l2_provider.clone()) + .await?; // Run the derivation pipeline until we are able to produce the output root of the claimed // L2 block. diff --git a/bin/client/src/l1/driver.rs b/bin/client/src/l1/driver.rs index 96da16245..34480ac72 100644 --- a/bin/client/src/l1/driver.rs +++ b/bin/client/src/l1/driver.rs @@ -4,7 +4,7 @@ //! [OpPayloadAttributes]: op_alloy_rpc_types_engine::OpPayloadAttributes use super::OracleL1ChainProvider; -use crate::{l2::OracleL2ChainProvider, BootInfo, HintType}; +use crate::{l2::OracleL2ChainProvider, BootInfo, FlushableCache, HintType}; use alloc::{sync::Arc, vec::Vec}; use alloy_consensus::{Header, Sealed}; use alloy_primitives::B256; @@ -82,11 +82,13 @@ where l2_safe_head_header: Sealed
, /// The inner pipeline. pipeline: OraclePipeline, + /// The caching oracle. + caching_oracle: Arc, } impl DerivationDriver where - O: CommsClient + Send + Sync + Debug, + O: CommsClient + FlushableCache + Send + Sync + Debug, B: BlobProvider + Send + Sync + Debug + Clone, { /// Returns the current L2 safe head [L2BlockInfo]. @@ -117,7 +119,7 @@ where /// - A new [DerivationDriver] instance. pub async fn new( boot_info: &BootInfo, - caching_oracle: &O, + caching_oracle: &Arc, blob_provider: B, mut chain_provider: OracleL1ChainProvider, mut l2_chain_provider: OracleL2ChainProvider, @@ -160,7 +162,12 @@ where .origin(l1_origin) .build(); - Ok(Self { l2_safe_head, l2_safe_head_header, pipeline }) + Ok(Self { + l2_safe_head, + l2_safe_head_header, + pipeline, + caching_oracle: caching_oracle.clone(), + }) } /// Produces the output root of the next L2 block. @@ -281,6 +288,9 @@ where ) .await?; } else { + if matches!(e, ResetError::ReorgDetected(_, _)) { + self.caching_oracle.as_ref().flush(); + } // Reset the pipeline to the initial L2 safe head and L1 origin, // and try again. self.pipeline diff --git a/bin/client/src/lib.rs b/bin/client/src/lib.rs index 3e5c13d31..d327a3546 100644 --- a/bin/client/src/lib.rs +++ b/bin/client/src/lib.rs @@ -17,4 +17,4 @@ pub mod boot; pub use boot::BootInfo; mod caching_oracle; -pub use caching_oracle::CachingOracle; +pub use caching_oracle::{CachingOracle, FlushableCache};