Skip to content

Commit

Permalink
fix(plasma): Plasma Data Source Cleanup (#164)
Browse files Browse the repository at this point in the history
* fix(plasma): cleanup the plasma data source

* fix(plasma): generic bound rename
  • Loading branch information
refcell authored Apr 28, 2024
1 parent 2f242f1 commit 4147919
Showing 1 changed file with 18 additions and 31 deletions.
49 changes: 18 additions & 31 deletions crates/plasma/src/plasma.rs
Original file line number Diff line number Diff line change
@@ -1,72 +1,59 @@
//! Contains the [PlasmaDataSource], which is a concrete implementation of the
//! [DataAvailabilityProvider] trait for the Plasma protocol. Used as an adapter to the
//! [DataAvailabilityProvider] trait for the Plasma source. Used as an adapter to the
//! [kona_derive] crate's derivation pipeline construction.
//!
//! [DataAvailabilityProvider]: kona_derive::traits::DataAvailabilityProvider
use crate::{source::PlasmaSource, traits::PlasmaInputFetcher};
use alloc::{boxed::Box, fmt::Debug};
use alloy_primitives::{Address, Bytes};
use anyhow::Result;
use async_trait::async_trait;
use kona_derive::{
traits::{ChainProvider, DataAvailabilityProvider},
types::{BlockInfo, RollupConfig},
};
use kona_primitives::BlockID;
use kona_derive::traits::{ChainProvider, DataAvailabilityProvider};
use kona_primitives::BlockInfo;

/// A factory for creating an Ethereum data source provider.
/// The plasma data source implements the [DataAvailabilityProvider] trait for the Plasma source.
#[derive(Debug, Clone, Copy)]
pub struct PlasmaDataSource<C, PIF, I>
pub struct PlasmaDataSource<C, F, I>
where
C: ChainProvider + Send + Clone,
PIF: PlasmaInputFetcher<C> + Clone,
F: PlasmaInputFetcher<C> + Clone,
I: Iterator<Item = Bytes> + Send + Clone,
{
/// The chain provider to use for the factory.
/// The chain provider.
pub chain_provider: C,
/// The plasma input fetcher.
pub plasma_input_fetcher: F,
/// The plasma iterator.
pub plasma_source: I,
/// The plasma input fetcher.
pub plasma_input_fetcher: PIF,
/// The L1 Signer.
pub signer: Address,
}

impl<C, PIF, I> PlasmaDataSource<C, PIF, I>
impl<C, F, I> PlasmaDataSource<C, F, I>
where
C: ChainProvider + Send + Clone + Debug,
PIF: PlasmaInputFetcher<C> + Clone,
F: PlasmaInputFetcher<C> + Clone,
I: Iterator<Item = Bytes> + Send + Clone,
{
/// Creates a new factory.
pub fn new(provider: C, pif: PIF, s: I, cfg: &RollupConfig) -> Self {
Self {
chain_provider: provider,
plasma_source: s,
plasma_input_fetcher: pif,
signer: cfg.genesis.system_config.batcher_addr,
}
/// Creates a new [PlasmaDataSource] from the given providers.
pub fn new(chain_provider: C, plasma_input_fetcher: F, plasma_source: I) -> Self {
Self { chain_provider, plasma_input_fetcher, plasma_source }
}
}

#[async_trait]
impl<C, PIF, I> DataAvailabilityProvider for PlasmaDataSource<C, PIF, I>
impl<C, F, I> DataAvailabilityProvider for PlasmaDataSource<C, F, I>
where
C: ChainProvider + Send + Clone + Debug + Sync,
PIF: PlasmaInputFetcher<C> + Clone + Debug + Send + Sync,
F: PlasmaInputFetcher<C> + Clone + Debug + Send + Sync,
I: Iterator<Item = Bytes> + Send + Clone + Debug + Sync,
{
type Item = Bytes;
type DataIter = PlasmaSource<C, PIF, I>;
type DataIter = PlasmaSource<C, F, I>;

async fn open_data(&self, block_ref: &BlockInfo, _: Address) -> Result<Self::DataIter> {
let id = BlockID { hash: block_ref.hash, number: block_ref.number };
Ok(PlasmaSource::new(
self.chain_provider.clone(),
self.plasma_input_fetcher.clone(),
self.plasma_source.clone(),
id,
block_ref.id(),
))
}
}

0 comments on commit 4147919

Please sign in to comment.