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(primitives): kona-derive type refactor #135

Merged
merged 3 commits into from
Apr 24, 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
15 changes: 15 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ anyhow.workspace = true
tracing.workspace = true
alloy-primitives = { workspace = true, features = ["rlp"] }

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

# External
alloy-rlp = { version = "0.3.4", default-features = false, features = ["derive"] }
alloy-sol-types = { version = "0.7.0", default-features = false }
Expand Down
2 changes: 1 addition & 1 deletion crates/derive/src/types/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};

use super::{block::L2BlockInfo, RawTransaction, Withdrawal};
use super::{L2BlockInfo, RawTransaction, Withdrawal};
use alloc::vec::Vec;
use alloy_primitives::{Address, B256};

Expand Down
1 change: 0 additions & 1 deletion crates/derive/src/types/ecotone.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![allow(dead_code)]
//! Module containing a [Transaction] builder for the Ecotone network updgrade transactions.
//!
//! [Transaction]: alloy_consensus::Transaction
Expand Down
18 changes: 3 additions & 15 deletions crates/derive/src/types/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! This module contains all of the types used within the derivation pipeline.

#[cfg(feature = "serde")]
use serde::{Deserialize, Serialize};
/// Re-export the kona primitive prelude
pub use kona_primitives::prelude::*;

use alloc::vec::Vec;
pub use alloy_consensus::Receipt;
Expand All @@ -11,15 +11,9 @@ use alloy_rlp::{Decodable, Encodable};
mod attributes;
pub use attributes::{L2AttributesWithParent, L2PayloadAttributes};

mod system_config;
pub use system_config::{SystemAccounts, SystemConfig, SystemConfigUpdateType};

mod deposits;
pub use deposits::*;

mod rollup_config;
pub use rollup_config::RollupConfig;

pub mod batch;
pub use batch::{
Batch, BatchType, BatchValidity, BatchWithInclusionBlock, RawSpanBatch, SingleBatch, SpanBatch,
Expand All @@ -37,9 +31,6 @@ pub use payload::{
L2ExecutionPayload, L2ExecutionPayloadEnvelope, PAYLOAD_MEM_FIXED_COST, PAYLOAD_TX_MEM_OVERHEAD,
};

mod block;
pub use block::{Block, BlockID, BlockInfo, BlockKind, L2BlockInfo, OpBlock, Withdrawal};

mod l1_block_info;
pub use l1_block_info::{L1BlockInfoBedrock, L1BlockInfoEcotone, L1BlockInfoTx};

Expand All @@ -53,9 +44,6 @@ pub use sidecar::{
VersionInformation, KZG_COMMITMENT_SIZE, KZG_PROOF_SIZE,
};

mod genesis;
pub use genesis::Genesis;

mod frame;
pub use frame::Frame;

Expand All @@ -66,7 +54,7 @@ mod errors;
pub use errors::*;

/// A raw transaction
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Debug, Default, Clone, PartialEq, Eq)]
pub struct RawTransaction(pub Bytes);

Expand Down
29 changes: 29 additions & 0 deletions crates/primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "kona-primitives"
description = "Primitive types for kona crates"
version = "0.0.1"
edition.workspace = true
authors.workspace = true
license.workspace = true
repository.workspace = true
homepage.workspace = true

[dependencies]
anyhow.workspace = true

# Alloy Types
alloy-sol-types = { version = "0.7.0", default-features = false }
alloy-rlp = { version = "0.3.4", default-features = false, features = ["derive"] }
alloy-primitives = { workspace = true, features = ["rlp"] }
alloy-consensus = { git = "https://github.com/alloy-rs/alloy", rev = "e3f2f07", default-features = false }
op-alloy-consensus = { git = "https://github.com/clabby/op-alloy", branch = "refcell/consensus-port", default-features = false }

# `serde` feature dependencies
serde = { version = "1.0.197", default-features = false, features = ["derive"], optional = true }

[dev-dependencies]
serde_json = { version = "1.0.68", default-features = false }

[features]
default = ["serde"]
serde = ["dep:serde"]
5 changes: 5 additions & 0 deletions crates/primitives/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# `kona-primitives`

Primitive types for kona crates.

These types SHOULD be re-exported by downstream kona crates.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module contains the [Genesis] type.

use super::{BlockID, SystemConfig};
use crate::{block::BlockID, system_config::SystemConfig};

/// Represents the genesis state of the rollup.
#[derive(Debug, Clone, Copy, Default)]
Expand Down
23 changes: 23 additions & 0 deletions crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#![doc = include_str!("../README.md")]
#![warn(missing_debug_implementations, missing_docs, unreachable_pub, rustdoc::all)]
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
#![no_std]

extern crate alloc;

pub mod block;
pub mod genesis;
pub mod params;
pub mod rollup_config;
pub mod system_config;

/// The prelude exports common types and traits.
pub mod prelude {
pub use crate::{
block::{Block, BlockID, BlockInfo, BlockKind, L2BlockInfo, OpBlock, Withdrawal},
genesis::Genesis,
rollup_config::RollupConfig,
system_config::{SystemAccounts, SystemConfig, SystemConfigUpdateType},
};
}
10 changes: 10 additions & 0 deletions crates/primitives/src/params.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//! This module contains the parameters and identifying types for the derivation pipeline.

use alloy_primitives::{b256, B256};

/// `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;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This module contains the [RollupConfig] type.

use super::Genesis;
use crate::genesis::Genesis;
use alloy_primitives::Address;

/// The Rollup configuration.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! This module contains the [SystemConfig] type.

use super::RollupConfig;
use crate::{CONFIG_UPDATE_EVENT_VERSION_0, CONFIG_UPDATE_TOPIC};
use crate::{
params::{CONFIG_UPDATE_EVENT_VERSION_0, CONFIG_UPDATE_TOPIC},
rollup_config::RollupConfig,
};
use alloy_consensus::Receipt;
use alloy_primitives::{address, Address, Log, U256};
use alloy_sol_types::{sol, SolType};
Expand Down Expand Up @@ -229,7 +231,7 @@ impl Default for SystemAccounts {

#[cfg(test)]
mod test {
use crate::types::Genesis;
use crate::genesis::Genesis;

use super::*;
use alloc::vec;
Expand All @@ -240,8 +242,8 @@ mod test {
fn mock_rollup_config(system_config: SystemConfig) -> RollupConfig {
RollupConfig {
genesis: Genesis {
l1: crate::types::BlockID::default(),
l2: crate::types::BlockID::default(),
l1: crate::block::BlockID::default(),
l2: crate::block::BlockID::default(),
timestamp: 0,
system_config,
},
Expand Down
Loading