-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plasma): Plasma Data Source Cleanup (#164)
* fix(plasma): cleanup the plasma data source * fix(plasma): generic bound rename
- Loading branch information
Showing
1 changed file
with
18 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(), | ||
)) | ||
} | ||
} |