From 745cb334c5563a77e4231b71040828e7b9e616e2 Mon Sep 17 00:00:00 2001 From: refcell Date: Tue, 4 Jun 2024 11:00:34 -0600 Subject: [PATCH 1/3] feat: default reset provider impl --- crates/derive/src/traits/mod.rs | 2 +- crates/derive/src/traits/reset.rs | 68 ++++++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 2 deletions(-) diff --git a/crates/derive/src/traits/mod.rs b/crates/derive/src/traits/mod.rs index 0b2463ec15..954d55b4f6 100644 --- a/crates/derive/src/traits/mod.rs +++ b/crates/derive/src/traits/mod.rs @@ -11,7 +11,7 @@ mod data_sources; pub use data_sources::{AsyncIterator, BlobProvider, DataAvailabilityProvider}; mod reset; -pub use reset::ResetProvider; +pub use reset::{ResetProvider, TipState, WrappedTipState}; mod providers; pub use providers::{ChainProvider, L2ChainProvider}; diff --git a/crates/derive/src/traits/reset.rs b/crates/derive/src/traits/reset.rs index f86d7d4fe3..14ea33a5a0 100644 --- a/crates/derive/src/traits/reset.rs +++ b/crates/derive/src/traits/reset.rs @@ -1,8 +1,12 @@ //! Traits for resetting stages. -use alloc::boxed::Box; +#![allow(unreachable_pub)] +#![allow(unused)] + +use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use kona_primitives::{BlockInfo, SystemConfig}; +use spin::Mutex; /// Provides the [BlockInfo] and [SystemConfig] for the stack to reset the stages. #[async_trait] @@ -13,3 +17,65 @@ pub trait ResetProvider { /// Returns the current [SystemConfig] for the pipeline to reset. async fn system_config(&self) -> SystemConfig; } + +/// TipState stores the tip information for the derivation pipeline. +#[derive(Debug, Clone, PartialEq)] +pub struct TipState { + /// The origin [BlockInfo]. + /// This is used downstream by [kona_derive] to reset the origin + /// of the [kona_derive::stages::BatchQueue] and l1 block list. + origin: BlockInfo, + /// The [SystemConfig] is used in two places. + system_config: SystemConfig, +} + +impl TipState { + /// Creates a new [TipState]. + pub fn new(origin: BlockInfo, system_config: SystemConfig) -> Self { + Self { origin, system_config } + } + + /// Retrieves a copy of the [BlockInfo]. + pub fn origin(&self) -> BlockInfo { + self.origin + } + + /// Retrieves a copy of the [SystemConfig]. + pub fn system_config(&self) -> SystemConfig { + self.system_config + } + + /// Sets the block info. + pub fn set_origin(&mut self, new_bi: BlockInfo) { + self.origin = new_bi; + } + + /// Sets the system config. + pub fn set_system_config(&mut self, new_config: SystemConfig) { + self.system_config = new_config; + } +} + +/// Wraps the [TipState] to implement the [ResetProvider] trait. +#[derive(Debug, Clone)] +pub struct WrappedTipState(Arc>); + +impl WrappedTipState { + /// Creates a new [ExExResetProvider]. + pub fn new(ts: Arc>) -> Self { + Self(ts) + } +} + +#[async_trait] +impl ResetProvider for WrappedTipState { + /// Returns the current [BlockInfo] for the pipeline to reset. + async fn block_info(&self) -> BlockInfo { + self.0.lock().origin() + } + + /// Returns the current [SystemConfig] for the pipeline to reset. + async fn system_config(&self) -> SystemConfig { + self.0.lock().system_config() + } +} From 5ffffd8cc75f16631f8eb198526321f53ffc7c1c Mon Sep 17 00:00:00 2001 From: refcell Date: Tue, 4 Jun 2024 11:10:27 -0600 Subject: [PATCH 2/3] fix: doc comments --- crates/derive/src/traits/reset.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/crates/derive/src/traits/reset.rs b/crates/derive/src/traits/reset.rs index 14ea33a5a0..9bf282b3c8 100644 --- a/crates/derive/src/traits/reset.rs +++ b/crates/derive/src/traits/reset.rs @@ -21,9 +21,8 @@ pub trait ResetProvider { /// TipState stores the tip information for the derivation pipeline. #[derive(Debug, Clone, PartialEq)] pub struct TipState { - /// The origin [BlockInfo]. - /// This is used downstream by [kona_derive] to reset the origin - /// of the [kona_derive::stages::BatchQueue] and l1 block list. + /// The origin [BlockInfo]. This is used by the [crate::stages::BatchQueue] + /// to reset it's origin and l1 block list. origin: BlockInfo, /// The [SystemConfig] is used in two places. system_config: SystemConfig, @@ -61,7 +60,7 @@ impl TipState { pub struct WrappedTipState(Arc>); impl WrappedTipState { - /// Creates a new [ExExResetProvider]. + /// Creates a new [WrappedTipState]. pub fn new(ts: Arc>) -> Self { Self(ts) } From 15782625745697545e683d177640689e29ac2e3f Mon Sep 17 00:00:00 2001 From: refcell Date: Thu, 6 Jun 2024 09:44:36 -0600 Subject: [PATCH 3/3] remove attributes --- crates/derive/src/traits/reset.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/derive/src/traits/reset.rs b/crates/derive/src/traits/reset.rs index 9bf282b3c8..e80540fde6 100644 --- a/crates/derive/src/traits/reset.rs +++ b/crates/derive/src/traits/reset.rs @@ -1,8 +1,5 @@ //! Traits for resetting stages. -#![allow(unreachable_pub)] -#![allow(unused)] - use alloc::{boxed::Box, sync::Arc}; use async_trait::async_trait; use kona_primitives::{BlockInfo, SystemConfig};