Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/derive/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
64 changes: 63 additions & 1 deletion crates/derive/src/traits/reset.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
//! Traits for resetting stages.

use alloc::boxed::Box;
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]
Expand All @@ -13,3 +14,64 @@ 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 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,
}

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<Mutex<TipState>>);

impl WrappedTipState {
/// Creates a new [WrappedTipState].
pub fn new(ts: Arc<Mutex<TipState>>) -> 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()
}
}