Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(plasma): Implements Plasma Support for kona derive #152

Merged
merged 6 commits into from
Apr 27, 2024
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
38 changes: 38 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ alloy-rlp = { workspace = true, features = ["derive"] }

# Local
kona-primitives = { path = "../primitives", version = "0.0.1" }
kona-plasma = { path = "../plasma", version = "0.0.1" }
kona-providers = { path = "../providers", version = "0.0.1" }

# External
alloy-sol-types = { version = "0.7.1", default-features = false }
Expand All @@ -42,6 +44,7 @@ alloy-transport-http = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f
reqwest = { version = "0.12", default-features = false, optional = true }

[dev-dependencies]
kona-plasma = { path = "../plasma", version = "0.0.1", features = ["default", "test-utils"] }
tokio = { version = "1.37", features = ["full"] }
proptest = "1.4.0"
tracing-subscriber = "0.3.18"
Expand All @@ -51,7 +54,7 @@ serde_json = { version = "1.0.116", default-features = false }

[features]
default = ["serde", "k256"]
serde = ["dep:serde", "alloy-primitives/serde", "alloy-consensus/serde", "op-alloy-consensus/serde"]
serde = ["dep:serde", "kona-plasma/serde", "kona-providers/serde", "kona-primitives/serde", "alloy-primitives/serde", "alloy-consensus/serde", "op-alloy-consensus/serde"]
k256 = ["alloy-primitives/k256", "alloy-consensus/k256", "op-alloy-consensus/k256"]
online = [
"dep:revm-primitives",
Expand All @@ -66,3 +69,4 @@ online = [
"revm-primitives/serde",
"revm-primitives/c-kzg",
]
test-utils = [ "kona-providers/test-utils", "kona-plasma/test-utils" ]
5 changes: 2 additions & 3 deletions crates/derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ extern crate alloc;
mod params;
pub use params::{
ChannelID, CHANNEL_ID_LENGTH, CONFIG_UPDATE_EVENT_VERSION_0, CONFIG_UPDATE_TOPIC,
DEPOSIT_EVENT_ABI, DEPOSIT_EVENT_ABI_HASH, DEPOSIT_EVENT_VERSION_0, DERIVATION_VERSION_0,
FRAME_OVERHEAD, MAX_CHANNEL_BANK_SIZE, MAX_FRAME_LEN, MAX_RLP_BYTES_PER_CHANNEL,
MAX_SPAN_BATCH_BYTES, SEQUENCER_FEE_VAULT_ADDRESS,
DERIVATION_VERSION_0, FRAME_OVERHEAD, MAX_CHANNEL_BANK_SIZE, MAX_FRAME_LEN,
MAX_RLP_BYTES_PER_CHANNEL, MAX_SPAN_BATCH_BYTES, SEQUENCER_FEE_VAULT_ADDRESS,
};

pub mod builder;
Expand Down
9 changes: 3 additions & 6 deletions crates/derive/src/online/alloy_providers.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
//! This module contains concrete implementations of the data provider traits, using an alloy
//! provider on the backend.

use crate::{
traits::{ChainProvider, L2ChainProvider},
types::{
Block, BlockInfo, L2BlockInfo, L2ExecutionPayloadEnvelope, OpBlock, RollupConfig,
SystemConfig,
},
use crate::types::{
Block, BlockInfo, L2BlockInfo, L2ExecutionPayloadEnvelope, OpBlock, RollupConfig, SystemConfig,
};
use alloc::{boxed::Box, sync::Arc, vec::Vec};
use alloy_consensus::{Header, Receipt, ReceiptWithBloom, TxEnvelope, TxType};
Expand All @@ -17,6 +13,7 @@ use alloy_transport_http::Http;
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use core::num::NonZeroUsize;
use kona_providers::{ChainProvider, L2ChainProvider};
use lru::LruCache;

const CACHE_SIZE: usize = 16;
Expand Down
23 changes: 5 additions & 18 deletions crates/derive/src/params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,27 +30,14 @@ pub const CHANNEL_ID_LENGTH: usize = 16;
/// [ChannelID] is an opaque identifier for a channel.
pub type ChannelID = [u8; CHANNEL_ID_LENGTH];

/// `keccak256("ConfigUpdate(uint256,uint8,bytes)")`
pub const CONFIG_UPDATE_TOPIC: B256 =
b256!("1d2b0bda21d56b8bd12d4f94ebacffdfb35f5e226f84b461103bb8beab6353be");

/// The initial version of the system config event log.
pub const CONFIG_UPDATE_EVENT_VERSION_0: B256 = B256::ZERO;

/// Frames cannot be larger than 1MB.
/// Data transactions that carry frames are generally not larger than 128 KB due to L1 network
/// conditions, but we leave space to grow larger anyway (gas limit allows for more data).
pub const MAX_FRAME_LEN: usize = 1000;

/// Deposit log event abi signature.
pub const DEPOSIT_EVENT_ABI: &str = "TransactionDeposited(address,address,uint256,bytes)";

/// Deposit event abi hash.
///
/// This is the keccak256 hash of the deposit event ABI signature.
/// `keccak256("TransactionDeposited(address,address,uint256,bytes)")`
pub const DEPOSIT_EVENT_ABI_HASH: B256 =
b256!("b3813568d9991fc951961fcb4c784893574240a28925604d09fc577c55bb7c32");
/// `keccak256("ConfigUpdate(uint256,uint8,bytes)")`
pub const CONFIG_UPDATE_TOPIC: B256 =
b256!("1d2b0bda21d56b8bd12d4f94ebacffdfb35f5e226f84b461103bb8beab6353be");

/// The initial version of the deposit event log.
pub const DEPOSIT_EVENT_VERSION_0: B256 = B256::ZERO;
/// The initial version of the system config event log.
pub const CONFIG_UPDATE_EVENT_VERSION_0: B256 = B256::ZERO;
3 changes: 2 additions & 1 deletion crates/derive/src/sources/blobs.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
//! Blob Data Source

use crate::{
traits::{AsyncIterator, BlobProvider, ChainProvider, SignedRecoverable},
traits::{AsyncIterator, BlobProvider, SignedRecoverable},
types::{BlobData, BlockInfo, IndexedBlobHash, StageError, StageResult},
};
use alloc::{boxed::Box, vec::Vec};
use alloy_consensus::{Transaction, TxEip4844Variant, TxEnvelope, TxType};
use alloy_primitives::{Address, Bytes, TxKind};
use anyhow::Result;
use async_trait::async_trait;
use kona_providers::ChainProvider;
use tracing::warn;

/// A data iterator that reads from a blob.
Expand Down
3 changes: 2 additions & 1 deletion crates/derive/src/sources/calldata.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
//! CallData Source

use crate::{
traits::{AsyncIterator, ChainProvider, SignedRecoverable},
traits::{AsyncIterator, SignedRecoverable},
types::{BlockInfo, StageError, StageResult},
};
use alloc::{boxed::Box, collections::VecDeque};
use alloy_consensus::{Transaction, TxEnvelope};
use alloy_primitives::{Address, Bytes, TxKind};
use async_trait::async_trait;
use kona_providers::ChainProvider;

/// A data iterator that reads from calldata.
#[derive(Debug, Clone)]
Expand Down
40 changes: 30 additions & 10 deletions crates/derive/src/sources/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,33 @@

use crate::{
sources::{BlobSource, CalldataSource, DataSource, PlasmaSource},
traits::{BlobProvider, ChainProvider, DataAvailabilityProvider},
types::{BlockInfo, RollupConfig},
traits::{BlobProvider, DataAvailabilityProvider},
types::{BlockID, BlockInfo, RollupConfig},
};
use alloc::{boxed::Box, fmt::Debug};
use alloy_primitives::{Address, Bytes};
use anyhow::{anyhow, Result};
use async_trait::async_trait;
use kona_plasma::traits::PlasmaInputFetcher;
use kona_providers::ChainProvider;

/// A factory for creating a calldata and blob provider.
#[derive(Debug, Clone, Copy)]
pub struct DataSourceFactory<C, B>
pub struct DataSourceFactory<C, B, PIF, I>
where
C: ChainProvider + Clone,
C: ChainProvider + Send + Clone,
B: BlobProvider + Clone,
PIF: PlasmaInputFetcher<C> + Clone,
I: Iterator<Item = Bytes> + Send + Clone,
{
/// The chain provider to use for the factory.
pub chain_provider: C,
/// The plasma iterator.
pub plasma_source: I,
/// The blob provider
pub blob_provider: B,
/// The plasma input fetcher.
pub plasma_input_fetcher: PIF,
/// The ecotone timestamp.
pub ecotone_timestamp: Option<u64>,
/// Whether or not plasma is enabled.
Expand All @@ -29,16 +37,20 @@ where
pub signer: Address,
}

impl<C, B> DataSourceFactory<C, B>
impl<C, B, PIF, I> DataSourceFactory<C, B, PIF, I>
where
C: ChainProvider + Clone + Debug,
C: ChainProvider + Send + Clone + Debug,
B: BlobProvider + Clone + Debug,
PIF: PlasmaInputFetcher<C> + Clone + Debug,
I: Iterator<Item = Bytes> + Send + Clone,
{
/// Creates a new factory.
pub fn new(provider: C, blobs: B, cfg: &RollupConfig) -> Self {
pub fn new(provider: C, blobs: B, pif: PIF, s: I, cfg: &RollupConfig) -> Self {
Self {
chain_provider: provider,
plasma_source: s,
blob_provider: blobs,
plasma_input_fetcher: pif,
ecotone_timestamp: cfg.ecotone_time,
plasma_enabled: cfg.is_plasma_enabled(),
signer: cfg.genesis.system_config.batcher_addr,
Expand All @@ -47,13 +59,15 @@ where
}

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

async fn open_data(
&self,
Expand Down Expand Up @@ -81,7 +95,13 @@ where
});
Ok(source)
} else if self.plasma_enabled {
Ok(DataSource::Plasma(PlasmaSource::new(self.chain_provider.clone())))
let id = BlockID { hash: block_ref.hash, number: block_ref.number };
Ok(DataSource::Plasma(PlasmaSource::new(
self.chain_provider.clone(),
self.plasma_input_fetcher.clone(),
self.plasma_source.clone(),
id,
)))
} else {
Err(anyhow!("No data source available"))
}
Expand Down
Loading
Loading