From e6538c7a1c521cc9a860c7e0a0a31ea4b9ede169 Mon Sep 17 00:00:00 2001 From: refcell Date: Thu, 17 Oct 2024 20:52:21 -0400 Subject: [PATCH] chore: Split Alloy (#103) ### Description Breaks up alloy --- Cargo.lock | 85 ++++--------------- Cargo.toml | 40 +++++---- crates/net/Cargo.toml | 9 +- crates/net/README.md | 2 +- crates/net/src/builder.rs | 4 +- crates/net/src/driver.rs | 3 +- crates/net/src/gossip/behaviour.rs | 2 +- crates/net/src/gossip/handler.rs | 3 +- crates/net/src/lib.rs | 5 +- crates/net/src/types/enr.rs | 6 +- crates/providers-local/Cargo.toml | 28 ++++-- crates/providers-local/src/blob_provider.rs | 3 +- crates/providers-local/src/chain_provider.rs | 28 +++--- crates/rollup/Cargo.toml | 21 ++++- crates/rollup/src/driver/context/exex.rs | 2 +- crates/rollup/src/driver/context/mod.rs | 15 ++-- .../rollup/src/driver/context/standalone.rs | 21 +++-- crates/rollup/src/driver/mod.rs | 2 +- crates/rollup/src/validator.rs | 11 ++- crates/rpc/Cargo.toml | 6 +- crates/rpc/src/sequencer.rs | 2 +- 21 files changed, 133 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b4beeb4..e069e31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -95,30 +95,6 @@ version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" -[[package]] -name = "alloy" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "056f2c01b2aed86e15b43c47d109bfc8b82553dc34e66452875e51247ec31ab2" -dependencies = [ - "alloy-consensus", - "alloy-contract", - "alloy-core", - "alloy-eips", - "alloy-genesis", - "alloy-network", - "alloy-provider", - "alloy-pubsub", - "alloy-rpc-client", - "alloy-rpc-types", - "alloy-serde", - "alloy-signer", - "alloy-transport", - "alloy-transport-http", - "alloy-transport-ipc", - "alloy-transport-ws", -] - [[package]] name = "alloy-chains" version = "0.1.39" @@ -150,40 +126,6 @@ dependencies = [ "serde_with", ] -[[package]] -name = "alloy-contract" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "917f7d12cf3971dc8c11c9972f732b35ccb9aaaf5f28f2f87e9e6523bee3a8ad" -dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-network", - "alloy-network-primitives", - "alloy-primitives", - "alloy-provider", - "alloy-pubsub", - "alloy-rpc-types-eth", - "alloy-sol-types", - "alloy-transport", - "futures", - "futures-util", - "thiserror 1.0.64 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "alloy-core" -version = "0.8.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a54c7158ea4a394bef220d82d8fdd412fb9b1ca2d6024db539070b7bc01b6401" -dependencies = [ - "alloy-dyn-abi", - "alloy-json-abi", - "alloy-primitives", - "alloy-rlp", - "alloy-sol-types", -] - [[package]] name = "alloy-dyn-abi" version = "0.8.8" @@ -194,12 +136,9 @@ dependencies = [ "alloy-primitives", "alloy-sol-type-parser", "alloy-sol-types", - "arbitrary", "const-hex", - "derive_arbitrary", "derive_more", "itoa", - "proptest", "serde", "serde_json", "winnow", @@ -372,7 +311,6 @@ dependencies = [ "alloy-primitives", "alloy-pubsub", "alloy-rpc-client", - "alloy-rpc-types-engine", "alloy-rpc-types-eth", "alloy-transport", "alloy-transport-http", @@ -558,7 +496,6 @@ dependencies = [ "alloy-rlp", "alloy-serde", "alloy-sol-types", - "arbitrary", "derive_more", "itertools 0.13.0", "jsonrpsee-types", @@ -667,7 +604,6 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ed5047c9a241df94327879c2b0729155b58b941eae7805a7ada2e19436e6b39" dependencies = [ - "alloy-json-abi", "alloy-sol-macro-input", "const-hex", "heck", @@ -686,13 +622,11 @@ version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5dee02a81f529c415082235129f0df8b8e60aa1601b9c9298ffe54d75f57210b" dependencies = [ - "alloy-json-abi", "const-hex", "dunce", "heck", "proc-macro2", "quote", - "serde_json", "syn 2.0.79", "syn-solidity", ] @@ -4402,8 +4336,11 @@ dependencies = [ name = "kona-providers-local" version = "0.0.0" dependencies = [ - "alloy", + "alloy-consensus", + "alloy-eips", + "alloy-primitives", "alloy-rlp", + "alloy-signer", "async-trait", "eyre", "hashbrown 0.15.0", @@ -5748,8 +5685,9 @@ dependencies = [ name = "op-net" version = "0.0.0" dependencies = [ - "alloy", + "alloy-primitives", "alloy-rlp", + "alloy-rpc-types-engine", "arbitrary", "arbtest", "discv5 0.8.0", @@ -5770,8 +5708,8 @@ dependencies = [ name = "op-rpc" version = "0.0.0" dependencies = [ - "alloy", "alloy-eips", + "alloy-primitives", "async-trait", "jsonrpsee", "op-alloy-rpc-jsonrpsee", @@ -9200,7 +9138,14 @@ dependencies = [ name = "rollup" version = "0.0.0" dependencies = [ - "alloy", + "alloy-consensus", + "alloy-eips", + "alloy-network", + "alloy-primitives", + "alloy-provider", + "alloy-rpc-types", + "alloy-rpc-types-engine", + "alloy-transport", "async-trait", "clap", "eyre", diff --git a/Cargo.toml b/Cargo.toml index 9eb4527..d2671c9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,37 +38,35 @@ rollup = { path = "crates/rollup" } ser = { path = "crates/ser" } kona-providers-local = { path = "crates/providers-local" } -# Optimism -superchain = { git = "https://github.com/anton-rs/superchain", branch = "main", default-features = false } +# Kona +kona-derive = { git = "https://github.com/anton-rs/kona", branch = "main", default-features = true } kona-providers = { git = "https://github.com/anton-rs/kona", branch = "main", default-features = true } -kona-providers-alloy = { git = "https://github.com/anton-rs/kona", branch = "main", default-features = true } kona-primitives = { git = "https://github.com/anton-rs/kona", branch = "main", default-features = true } -kona-derive = { git = "https://github.com/anton-rs/kona", branch = "main", default-features = true } +kona-providers-alloy = { git = "https://github.com/anton-rs/kona", branch = "main", default-features = true } + +# Superchain +superchain = { git = "https://github.com/anton-rs/superchain", branch = "main", default-features = false } # Alloy -alloy = { version = "0.4.2", features = [ - "contract", - "providers", - "provider-http", - "provider-ws", - "provider-ipc", - "signers", - "consensus", - "rpc-types", - "rpc-types-engine", - "network", - "ssz" -] } -alloy-rlp = "0.3" +alloy-rlp = { version = "0.3.8", default-features = false } alloy-eips = { version = "0.4", default-features = false } +alloy-signer = { version = "0.4.2", default-features = false } +alloy-network = { version = "0.4.2", default-features = false } +alloy-provider = { version = "0.4.2", default-features = false } +alloy-contract = { 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-consensus = { version = "0.4.2", default-features = false } +alloy-primitives = { version = "0.8.8", default-features = false } +alloy-rpc-types-engine = { 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-protocol = { version = "0.4.0", default-features = false } +op-alloy-consensus = { version = "0.4.0", default-features = false } op-alloy-rpc-types = { version = "0.4.0", default-features = false } -op-alloy-rpc-types-engine = { version = "0.4.0", default-features = false } op-alloy-rpc-jsonrpsee = { version = "0.4.0", default-features = false } +op-alloy-rpc-types-engine = { version = "0.4.0", default-features = false } # Reth reth = { git = "https://github.com/paradigmxyz/reth", rev = "a846cbd" } diff --git a/crates/net/Cargo.toml b/crates/net/Cargo.toml index f42e345..2c236e1 100644 --- a/crates/net/Cargo.toml +++ b/crates/net/Cargo.toml @@ -12,8 +12,11 @@ rust-version.workspace = true [dependencies] # Alloy -alloy.workspace = true alloy-rlp.workspace = true +alloy-primitives = { workspace = true, features = ["k256"] } +alloy-rpc-types-engine = { workspace = true, features = ["std"] } + +# Op Alloy op-alloy-rpc-types-engine = { workspace = true, features = ["std"] } # Networking @@ -37,8 +40,8 @@ arbitrary = { workspace = true, features = ["derive"], optional = true } [dev-dependencies] arbtest.workspace = true arbitrary = { workspace = true, features = ["derive"] } -alloy = { workspace = true, features = ["arbitrary"] } +alloy-primitives = { workspace = true, features = ["arbitrary"] } [features] default = [] -arbitrary = ["dep:arbitrary", "alloy/arbitrary"] +arbitrary = ["dep:arbitrary", "alloy-primitives/arbitrary"] diff --git a/crates/net/README.md b/crates/net/README.md index b26cd81..06087da 100644 --- a/crates/net/README.md +++ b/crates/net/README.md @@ -6,7 +6,7 @@ Contains a gossipsub driver to run discv5 peer discovery and block gossip. ```rust,no_run use std::net::{IpAddr, Ipv4Addr, SocketAddr}; -use alloy::primitives::address; +use alloy_primitives::address; use op_net::driver::NetworkDriver; // Build the network driver. diff --git a/crates/net/src/builder.rs b/crates/net/src/builder.rs index f36d9e2..b8d6eaf 100644 --- a/crates/net/src/builder.rs +++ b/crates/net/src/builder.rs @@ -1,6 +1,6 @@ //! Network Builder Module. -use alloy::primitives::Address; +use alloy_primitives::Address; use discv5::{Config, ListenConfig}; use eyre::Result; use std::{ @@ -151,7 +151,7 @@ impl NetworkDriverBuilder { /// ## Example /// /// ```rust - /// use alloy::primitives::{address, Address}; + /// use alloy_primitives::{address, Address}; /// use discv5::{ConfigBuilder, ListenConfig}; /// use op_net::builder::NetworkDriverBuilder; /// use std::net::{IpAddr, Ipv4Addr, SocketAddr}; diff --git a/crates/net/src/driver.rs b/crates/net/src/driver.rs index 74d82f9..a10d81e 100644 --- a/crates/net/src/driver.rs +++ b/crates/net/src/driver.rs @@ -2,7 +2,8 @@ use std::sync::mpsc::Receiver; -use alloy::{primitives::Address, rpc::types::engine::ExecutionPayload}; +use alloy_primitives::Address; +use alloy_rpc_types_engine::ExecutionPayload; use eyre::Result; use tokio::{select, sync::watch}; diff --git a/crates/net/src/gossip/behaviour.rs b/crates/net/src/gossip/behaviour.rs index fa2cdf2..8ee1fdc 100644 --- a/crates/net/src/gossip/behaviour.rs +++ b/crates/net/src/gossip/behaviour.rs @@ -49,7 +49,7 @@ impl Behaviour { mod tests { use super::*; use crate::gossip::{config, handler::BlockHandler}; - use alloy::primitives::Address; + use alloy_primitives::Address; use libp2p::gossipsub::{IdentTopic, TopicHash}; fn zero_topics() -> Vec { diff --git a/crates/net/src/gossip/handler.rs b/crates/net/src/gossip/handler.rs index 3ac9e9f..a204e17 100644 --- a/crates/net/src/gossip/handler.rs +++ b/crates/net/src/gossip/handler.rs @@ -5,7 +5,8 @@ use std::{ time::SystemTime, }; -use alloy::{primitives::Address, rpc::types::engine::ExecutionPayload}; +use alloy_primitives::Address; +use alloy_rpc_types_engine::ExecutionPayload; use libp2p::gossipsub::{IdentTopic, Message, MessageAcceptance, TopicHash}; use op_alloy_rpc_types_engine::OpNetworkPayloadEnvelope; use tokio::sync::watch; diff --git a/crates/net/src/lib.rs b/crates/net/src/lib.rs index 8ef1f92..94ef225 100644 --- a/crates/net/src/lib.rs +++ b/crates/net/src/lib.rs @@ -3,9 +3,8 @@ #![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))] #![cfg_attr(not(test), warn(unused_crate_dependencies))] +pub mod builder; pub mod discovery; +pub mod driver; pub mod gossip; pub mod types; - -pub mod builder; -pub mod driver; diff --git a/crates/net/src/types/enr.rs b/crates/net/src/types/enr.rs index 9f535fb..b819b05 100644 --- a/crates/net/src/types/enr.rs +++ b/crates/net/src/types/enr.rs @@ -44,13 +44,13 @@ impl Encodable for OpStackEnr { let version_slice = encode::u128(self.version as u128, &mut version_buf); let opstack = [chain_id_slice, version_slice].concat(); - alloy::primitives::Bytes::from(opstack).encode(out); + alloy_primitives::Bytes::from(opstack).encode(out); } } impl Decodable for OpStackEnr { fn decode(buf: &mut &[u8]) -> alloy_rlp::Result { - let bytes = alloy::primitives::Bytes::decode(buf)?; + let bytes = alloy_primitives::Bytes::decode(buf)?; let (chain_id, rest) = decode::u64(&bytes) .map_err(|_| alloy_rlp::Error::Custom("could not decode chain id"))?; let (version, _) = @@ -62,7 +62,7 @@ impl Decodable for OpStackEnr { #[cfg(test)] mod tests { use super::*; - use alloy::primitives::{bytes, Bytes}; + use alloy_primitives::{bytes, Bytes}; #[test] fn roundtrip_op_stack_enr() { diff --git a/crates/providers-local/Cargo.toml b/crates/providers-local/Cargo.toml index 5df8170..d2a1ae9 100644 --- a/crates/providers-local/Cargo.toml +++ b/crates/providers-local/Cargo.toml @@ -11,17 +11,29 @@ categories.workspace = true rust-version.workspace = true [dependencies] -reth.workspace = true -alloy.workspace = true +# Alloy alloy-rlp.workspace = true -hashbrown.workspace = true -async-trait.workspace = true -parking_lot.workspace = true +alloy-eips.workspace = true +alloy-signer.workspace = true +alloy-consensus.workspace = true +alloy-primitives.workspace = true + +# Op Alloy +op-alloy-protocol.workspace = true + +# Kona kona-derive.workspace = true kona-providers.workspace = true kona-providers-alloy.workspace = true kona-primitives.workspace = true -tracing.workspace = true -eyre.workspace = true + +# Reth +reth.workspace = true + +# Misc url.workspace = true -op-alloy-protocol.workspace = true +eyre.workspace = true +tracing.workspace = true +hashbrown.workspace = true +async-trait.workspace = true +parking_lot.workspace = true diff --git a/crates/providers-local/src/blob_provider.rs b/crates/providers-local/src/blob_provider.rs index 3a8431a..dad8eb5 100644 --- a/crates/providers-local/src/blob_provider.rs +++ b/crates/providers-local/src/blob_provider.rs @@ -3,7 +3,8 @@ use alloc::{boxed::Box, collections::VecDeque, string::ToString, sync::Arc, vec::Vec}; use hashbrown::HashMap; -use alloy::{eips::eip4844::Blob, primitives::B256}; +use alloy_eips::eip4844::Blob; +use alloy_primitives::B256; use async_trait::async_trait; use eyre::{eyre, Result}; use kona_derive::{errors::BlobProviderError, traits::BlobProvider}; diff --git a/crates/providers-local/src/chain_provider.rs b/crates/providers-local/src/chain_provider.rs index 700e058..e819862 100644 --- a/crates/providers-local/src/chain_provider.rs +++ b/crates/providers-local/src/chain_provider.rs @@ -3,16 +3,14 @@ use alloc::{boxed::Box, collections::vec_deque::VecDeque, sync::Arc, vec::Vec}; use hashbrown::HashMap; -use alloy::{ - consensus::{ - Header, Receipt, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, - TxLegacy, - }, - eips::BlockNumHash, - primitives::B256, - signers::Signature, +use alloy_consensus::{ + Header, Receipt, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip4844Variant, TxEnvelope, + TxLegacy, }; +use alloy_eips::BlockNumHash; +use alloy_primitives::B256; use alloy_rlp::{Decodable, Encodable}; +use alloy_signer::Signature; use async_trait::async_trait; use eyre::eyre; use kona_providers::ChainProvider; @@ -151,7 +149,7 @@ impl InMemoryChainProviderInner { r.as_ref().map(|r| Receipt { cumulative_gas_used: r.cumulative_gas_used as u128, logs: r.logs.clone(), - status: alloy::consensus::Eip658Value::Eip658(r.success), + status: alloy_consensus::Eip658Value::Eip658(r.success), }) }) .collect(), @@ -277,12 +275,12 @@ pub fn reth_to_alloy_tx(tx: &reth::primitives::TransactionSigned) -> Option Option Option> for Blocks { fn from(value: Arc) -> Self { let mut blocks = BTreeMap::new(); for (block_number, sealed_block) in value.blocks() { - // from reth::primitives::SealedBlock to alloy::rpc::types::Block + // from reth::primitives::SealedBlock to alloy_rpc_types::Block let block = Block { header: parse_reth_rpc_header(sealed_block), uncles: sealed_block.body.ommers.iter().map(|x| x.hash_slow()).collect(), @@ -140,7 +139,7 @@ impl From for ChainNotification { } } -// from reth::primitives::SealedBlock to alloy::rpc::types::Header +// from reth::primitives::SealedBlock to alloy_rpc_types::Header fn parse_reth_rpc_header(block: &reth::primitives::SealedBlock) -> Header { Header { hash: block.header.hash(), diff --git a/crates/rollup/src/driver/context/standalone.rs b/crates/rollup/src/driver/context/standalone.rs index 2917ca8..0e505ac 100644 --- a/crates/rollup/src/driver/context/standalone.rs +++ b/crates/rollup/src/driver/context/standalone.rs @@ -1,15 +1,14 @@ use hashbrown::HashMap; use std::{collections::BTreeMap, time::Duration}; -use alloy::{ - consensus::TxEnvelope, - eips::{eip1898::BlockNumHash, BlockId}, - network::Ethereum, - primitives::{BlockNumber, B256}, - providers::{IpcConnect, Provider, ProviderBuilder, ReqwestProvider, WsConnect}, - rpc::types::Block, - transports::{TransportErrorKind, TransportResult}, -}; +use alloy_consensus::TxEnvelope; +use alloy_eips::{eip1898::BlockNumHash, BlockId}; +use alloy_network::Ethereum; +use alloy_primitives::{BlockNumber, B256}; +use alloy_provider::{IpcConnect, Provider, ProviderBuilder, ReqwestProvider, WsConnect}; +use alloy_rpc_types::Block; +use alloy_transport::{TransportErrorKind, TransportResult}; + use async_trait::async_trait; use futures::StreamExt; use reth::rpc::types::BlockTransactions; @@ -235,7 +234,7 @@ impl DriverContext for StandaloneHeraContext { } } -// from reth::rpc::types::Block to alloy::rpc::types::Block +// from reth::rpc::types::Block to alloy_rpc_types::Block fn parse_reth_rpc_block(block: Block) -> Block { let txs = block .transactions @@ -258,7 +257,7 @@ fn parse_reth_rpc_block(block: Block) -> Block { #[cfg(test)] mod tests { use super::*; - use alloy::rpc::types::Header; + use alloy_rpc_types::Header; #[tokio::test] async fn test_http_poller() -> eyre::Result<()> { diff --git a/crates/rollup/src/driver/mod.rs b/crates/rollup/src/driver/mod.rs index 877a8f4..cd44d8d 100644 --- a/crates/rollup/src/driver/mod.rs +++ b/crates/rollup/src/driver/mod.rs @@ -1,6 +1,6 @@ //! Rollup Node Driver -use alloy::eips::eip1898::BlockNumHash; +use alloy_eips::eip1898::BlockNumHash; use std::{fmt::Debug, sync::Arc}; use eyre::{bail, eyre, Result}; diff --git a/crates/rollup/src/validator.rs b/crates/rollup/src/validator.rs index 01cf0b1..fa73520 100644 --- a/crates/rollup/src/validator.rs +++ b/crates/rollup/src/validator.rs @@ -2,12 +2,11 @@ use std::fmt::Debug; -use alloy::{ - eips::BlockNumberOrTag, - primitives::Bytes, - providers::{network::primitives::BlockTransactionsKind, Provider, ReqwestProvider}, - rpc::types::engine::PayloadAttributes, -}; +use alloy_eips::BlockNumberOrTag; +use alloy_primitives::Bytes; +use alloy_provider::{network::primitives::BlockTransactionsKind, Provider, ReqwestProvider}; +use alloy_rpc_types_engine::PayloadAttributes; + use async_trait::async_trait; use eyre::{bail, eyre, Result}; use op_alloy_rpc_types_engine::{OpAttributesWithParent, OpPayloadAttributes}; diff --git a/crates/rpc/Cargo.toml b/crates/rpc/Cargo.toml index a813832..8c4a38d 100644 --- a/crates/rpc/Cargo.toml +++ b/crates/rpc/Cargo.toml @@ -23,8 +23,8 @@ tracing.workspace = true async-trait.workspace = true jsonrpsee = { workspace = true, features = ["jsonrpsee-core", "client-core", "server-core", "macros"] } -# `reth` feature flag dependencies -alloy = { workspace = true, optional = true } +# `reth` +alloy-primitives = { workspace = true, optional = true } reqwest = { workspace = true, features = ["rustls-tls-native-roots"], optional = true } thiserror = { workspace = true, optional = true } serde_json = { workspace = true, optional = true } @@ -32,7 +32,7 @@ serde_json = { workspace = true, optional = true } [features] default = ["reth"] reth = [ - "dep:alloy", + "dep:alloy-primitives", "dep:reqwest", "dep:serde_json", "dep:thiserror", diff --git a/crates/rpc/src/sequencer.rs b/crates/rpc/src/sequencer.rs index 2eeaff8..9300f49 100644 --- a/crates/rpc/src/sequencer.rs +++ b/crates/rpc/src/sequencer.rs @@ -5,7 +5,7 @@ use std::sync::{ Arc, }; -use alloy::primitives::hex; +use alloy_primitives::hex; use reqwest::Client; use serde_json::json; use tracing::warn;