Skip to content

Commit

Permalink
chore(workspace): Removes Primitives (#638)
Browse files Browse the repository at this point in the history
* feat(workspace): remove primitives

* fix: indexed blob hash
  • Loading branch information
refcell authored Oct 18, 2024
1 parent 7d22a13 commit 2bd0928
Show file tree
Hide file tree
Showing 30 changed files with 611 additions and 896 deletions.
171 changes: 95 additions & 76 deletions Cargo.lock

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,37 @@ lto = "fat"

[workspace.dependencies]
# Workspace
kona-client = { path = "bin/client", version = "0.1.0" }
kona-mpt = { path = "crates/mpt", version = "0.0.3" }
kona-common = { path = "crates/common", version = "0.0.3" }
kona-preimage = { path = "crates/preimage", version = "0.0.3" }
kona-executor = { path = "crates/executor", version = "0.0.2" }
kona-common-proc = { path = "crates/common-proc", version = "0.0.3" }
kona-mpt = { path = "crates/mpt", version = "0.0.3", default-features = false }
kona-client = { path = "bin/client", version = "0.1.0", default-features = false }
kona-common = { path = "crates/common", version = "0.0.3", default-features = false }
kona-derive = { path = "crates/derive", version = "0.0.3", default-features = false }
kona-primitives = { path = "crates/primitives", version = "0.0.2", default-features = false }
kona-providers = { path = "crates/providers", version = "0.0.1" }
kona-preimage = { path = "crates/preimage", version = "0.0.3", default-features = false }
kona-executor = { path = "crates/executor", version = "0.0.2", default-features = false }
kona-providers = { path = "crates/providers", version = "0.0.1", default-features = false }
kona-common-proc = { path = "crates/common-proc", version = "0.0.3", default-features = false }
kona-providers-alloy = { path = "crates/providers-alloy", version = "0.0.1", default-features = false }

# OP Alloy
op-alloy-genesis = { version = "0.5.0", default-features = false }
op-alloy-protocol = { version = "0.5.0", default-features = false }
op-alloy-consensus = { version = "0.5.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.5.0", default-features = false }

# Alloy
alloy-rlp = { version = "0.3.8", default-features = false }
alloy-trie = { version = "0.7.2", default-features = false }
alloy-eips = { version = "0.5.0", default-features = false }
alloy-serde = { version = "0.5.0", default-features = false }
alloy-provider = { version = "0.5.0", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }
alloy-consensus = { version = "0.5.0", default-features = false }
alloy-transport = { version = "0.5.0", default-features = false }
alloy-rpc-types = { version = "0.5.0", default-features = false }
alloy-rpc-client = { version = "0.5.0", default-features = false }
alloy-node-bindings = { version = "0.5.0", default-features = false }
alloy-transport-http = { version = "0.5.0", default-features = false }
alloy-rpc-types-engine = { version = "0.5.0", default-features = false }

# General
anyhow = { version = "1.0.89", default-features = false }
thiserror = { git = "https://github.com/quartiq/thiserror", branch = "no-std", default-features = false }
Expand Down Expand Up @@ -111,30 +131,10 @@ serde_json = { version = "1.0.128", default-features = false }

# Ethereum
unsigned-varint = "0.8.0"
revm = { version = "14.0.3", default-features = false }
revm = { version = "16.0.0", default-features = false }

# Optimism
superchain = { version = "0.7", default-features = false }

# K/V database
rocksdb = { version = "0.22", default-features = false, features = ["snappy"] }

# Alloy
alloy-rlp = { version = "0.3.8", default-features = false }
alloy-trie = { version = "0.7.2", default-features = false }
alloy-eips = { version = "0.4.2", default-features = false }
alloy-provider = { version = "0.4.2", default-features = false }
alloy-primitives = { version = "0.8", default-features = false }
alloy-consensus = { version = "0.4.2", default-features = false }
alloy-transport = { version = "0.4.2", default-features = false }
alloy-rpc-types = { version = "0.4.2", default-features = false }
alloy-rpc-client = { version = "0.4.2", default-features = false }
alloy-rpc-types-engine = { version = "0.4.2", default-features = false }
alloy-node-bindings = { version = "0.4.2", default-features = false }
alloy-transport-http = { version = "0.4.2", default-features = false }

# OP Alloy
op-alloy-consensus = { version = "0.4.0", default-features = false }
op-alloy-protocol = { version = "0.4.0", default-features = false }
op-alloy-genesis = { version = "0.4.0", default-features = false }
op-alloy-rpc-types-engine = { version = "0.4.0", default-features = false }
1 change: 0 additions & 1 deletion bin/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ kona-mpt.workspace = true
kona-derive.workspace = true
kona-executor.workspace = true
kona-providers.workspace = true
kona-primitives = { workspace = true, features = ["serde"] }
op-alloy-genesis = { workspace = true, features = ["serde"] }
op-alloy-protocol.workspace = true
op-alloy-rpc-types-engine.workspace = true
Expand Down
9 changes: 4 additions & 5 deletions bin/client/src/l1/blob_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ use alloy_eips::eip4844::FIELD_ELEMENTS_PER_BLOB;
use alloy_primitives::keccak256;
use anyhow::Result;
use async_trait::async_trait;
use kona_derive::traits::BlobProvider;
use kona_derive::{sources::IndexedBlobHash, traits::BlobProvider};
use kona_preimage::{CommsClient, PreimageKey, PreimageKeyType};
use kona_primitives::IndexedBlobHash;
use op_alloy_protocol::BlockInfo;

/// An oracle-backed blob provider.
Expand All @@ -36,7 +35,7 @@ impl<T: CommsClient> OracleBlobProvider<T> {
async fn get_blob(&self, block_ref: &BlockInfo, blob_hash: &IndexedBlobHash) -> Result<Blob> {
let mut blob_req_meta = [0u8; 48];
blob_req_meta[0..32].copy_from_slice(blob_hash.hash.as_ref());
blob_req_meta[32..40].copy_from_slice((blob_hash.index as u64).to_be_bytes().as_ref());
blob_req_meta[32..40].copy_from_slice((blob_hash.index).to_be_bytes().as_ref());
blob_req_meta[40..48].copy_from_slice(block_ref.timestamp.to_be_bytes().as_ref());

// Send a hint for the blob commitment and field elements.
Expand Down Expand Up @@ -79,10 +78,10 @@ impl<T: CommsClient + Sync + Send> BlobProvider for OracleBlobProvider<T> {
&mut self,
block_ref: &BlockInfo,
blob_hashes: &[IndexedBlobHash],
) -> Result<Vec<Blob>, Self::Error> {
) -> Result<Vec<Box<Blob>>, Self::Error> {
let mut blobs = Vec::with_capacity(blob_hashes.len());
for hash in blob_hashes {
blobs.push(self.get_blob(block_ref, hash).await?);
blobs.push(Box::new(self.get_blob(block_ref, hash).await?));
}
Ok(blobs)
}
Expand Down
2 changes: 1 addition & 1 deletion bin/host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ workspace = true
# Workspace
kona-mpt.workspace = true
kona-client.workspace = true
kona-derive.workspace = true
kona-common.workspace = true
kona-preimage.workspace = true
kona-providers-alloy.workspace = true
kona-primitives = { workspace = true, features = ["online"] }

# Alloy & Revm
alloy-eips.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion bin/host/src/fetcher/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ use alloy_rpc_types::{
};
use anyhow::{anyhow, Result};
use kona_client::HintType;
use kona_derive::sources::IndexedBlobHash;
use kona_preimage::{PreimageKey, PreimageKeyType};
use kona_primitives::IndexedBlobHash;
use kona_providers_alloy::{OnlineBeaconClient, OnlineBlobProvider};
use op_alloy_protocol::BlockInfo;
use std::sync::Arc;
Expand Down
2 changes: 1 addition & 1 deletion book/src/sdk/fpvm-backend.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Kona is effectively split into two parts:

- OP Stack state transition logic & types (`kona-derive`, `kona-executor`, `kona-mpt`, `kona-primitives`)
- OP Stack state transition logic (`kona-derive`, `kona-executor`, `kona-mpt`)
- {{#template ../../templates/glossary-link.md root=./ ref=fault-proof-vm text=Fault Proof VM}} IO and utilities
(`kona-common`, `kona-common-proc`, `kona-preimage`)

Expand Down
2 changes: 0 additions & 2 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ async-trait.workspace = true

# Workspace
kona-providers.workspace = true
kona-primitives.workspace = true

# `serde` feature dependencies
serde = { workspace = true, optional = true }
Expand Down Expand Up @@ -72,7 +71,6 @@ metrics = [
]
serde = [
"dep:serde",
"kona-primitives/serde",
"alloy-primitives/serde",
"alloy-consensus/serde",
"op-alloy-consensus/serde",
Expand Down
8 changes: 4 additions & 4 deletions crates/derive/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ mod tests {
prev_randao,
suggested_fee_recipient: SEQUENCER_FEE_VAULT_ADDRESS,
parent_beacon_block_root,
withdrawals: None,
withdrawals: Some(vec![]),
},
transactions: payload.transactions.clone(),
no_tx_pool: Some(true),
Expand Down Expand Up @@ -693,8 +693,8 @@ mod tests {
timestamp: next_l2_time,
prev_randao,
suggested_fee_recipient: SEQUENCER_FEE_VAULT_ADDRESS,
parent_beacon_block_root: None,
withdrawals: None,
parent_beacon_block_root: Some(B256::ZERO),
withdrawals: Some(vec![]),
},
transactions: payload.transactions.clone(),
no_tx_pool: Some(true),
Expand All @@ -703,7 +703,7 @@ mod tests {
)),
eip_1559_params: None,
};
assert_eq!(payload.transactions.as_ref().unwrap().len(), 10);
assert_eq!(payload, expected);
assert_eq!(payload.transactions.unwrap().len(), 4);
}
}
8 changes: 4 additions & 4 deletions crates/derive/src/batch/span_batch/transactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use super::{
use alloc::vec::Vec;
use alloy_consensus::{Transaction, TxEnvelope, TxType};
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{Address, Bytes, TxKind, U256};
use alloy_primitives::{Address, Bytes, U256};
use alloy_rlp::{Buf, Decodable, Encodable};

/// This struct contains the decoded information for transactions in a span batch.
Expand Down Expand Up @@ -348,11 +348,11 @@ impl SpanBatchTransactions {
let signature_v = signature.v().to_u64();
let y_parity_bit = convert_v_to_y_parity(signature_v, tx_type)?;
let contract_creation_bit = match to {
TxKind::Call(address) => {
Some(address) => {
self.tx_tos.push(address);
0
}
TxKind::Create => 1,
None => 1,
};
let mut tx_data_buf = Vec::new();
span_batch_tx.encode(&mut tx_data_buf);
Expand All @@ -374,7 +374,7 @@ impl SpanBatchTransactions {
mod tests {
use super::*;
use alloy_consensus::{Signed, TxEip1559, TxEip2930, TxLegacy};
use alloy_primitives::{address, Signature};
use alloy_primitives::{address, Signature, TxKind};

#[test]
fn test_span_batch_transactions_add_empty_txs() {
Expand Down
18 changes: 17 additions & 1 deletion crates/derive/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,27 @@ use crate::{
use alloc::string::String;
use alloy_eips::BlockNumHash;
use alloy_primitives::B256;
use kona_primitives::BlobDecodingError;
use op_alloy_genesis::system::SystemConfigUpdateError;
use op_alloy_protocol::DepositError;
use thiserror::Error;

/// Blob Decuding Error
#[derive(Error, Debug, PartialEq, Eq)]
pub enum BlobDecodingError {
/// Invalid field element
#[error("Invalid field element")]
InvalidFieldElement,
/// Invalid encoding version
#[error("Invalid encoding version")]
InvalidEncodingVersion,
/// Invalid length
#[error("Invalid length")]
InvalidLength,
/// Missing Data
#[error("Missing data")]
MissingData,
}

/// A result type for the derivation pipeline stages.
pub type PipelineResult<T> = Result<T, PipelineErrorKind>;

Expand Down
Loading

0 comments on commit 2bd0928

Please sign in to comment.