diff --git a/Cargo.lock b/Cargo.lock index 78ff0d78c..f33999256 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -121,9 +121,9 @@ dependencies = [ [[package]] name = "alloy-consensus" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf9f8fb3895d5a526b6b8cae7e1bba96ba350545852f0b0ab51041136785ac95" +checksum = "e88e1edea70787c33e11197d3f32ae380f3db19e6e061e539a5bcf8184a6b326" dependencies = [ "alloy-eips", "alloy-primitives", @@ -155,9 +155,9 @@ dependencies = [ [[package]] name = "alloy-contract" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a1240738b2c2d5a45153722fc50f28cd6e3129283b5f3e039031577c71eb70d" +checksum = "1b668c78c4b1f12f474ede5a85e8ce550d0aa1ef7d49fd1d22855a43b960e725" dependencies = [ "alloy-dyn-abi", "alloy-json-abi", @@ -222,9 +222,9 @@ dependencies = [ [[package]] name = "alloy-eips" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5061487522a347cc84b282ce507dfca70a34d0ef173c1af643b47f77897e38c9" +checksum = "5f9fadfe089e9ccc0650473f2d4ef0a28bc015bbca5631d9f0f09e49b557fdb3" dependencies = [ "alloy-eip2930", "alloy-eip7702", @@ -243,9 +243,9 @@ dependencies = [ [[package]] name = "alloy-genesis" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62acff796b1cfc301f09eba904b8299b2e243069ddf33584941843e3a1c5a6a5" +checksum = "2b2a4cf7b70f3495788e74ce1c765260ffe38820a2a774ff4aacb62e31ea73f9" dependencies = [ "alloy-primitives", "alloy-serde", @@ -267,9 +267,9 @@ dependencies = [ [[package]] name = "alloy-json-rpc" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73c81f9b96b5ed5c32508ca494d74cdc693e534535b0cf9bf2a5b94a2d3d3a27" +checksum = "e29040b9d5fe2fb70415531882685b64f8efd08dfbd6cc907120650504821105" dependencies = [ "alloy-primitives", "alloy-sol-types", @@ -281,9 +281,9 @@ dependencies = [ [[package]] name = "alloy-network" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01e53bad8c26999c2577e395e5cea1cee39966247218206ecc694544f0853993" +checksum = "510cc00b318db0dfccfdd2d032411cfae64fc144aef9679409e014145d3dacc4" dependencies = [ "alloy-consensus", "alloy-consensus-any", @@ -319,9 +319,9 @@ dependencies = [ [[package]] name = "alloy-node-bindings" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b19414ac7f0cc153fc000a540babd450fe7cbd3ccb4b5ddb62b4fa5a72126fb" +checksum = "aef9849fb8bbb28f69f2cbdb4b0dac2f0e35c04f6078a00dfb8486469aed02de" dependencies = [ "alloy-genesis", "alloy-primitives", @@ -368,9 +368,9 @@ dependencies = [ [[package]] name = "alloy-provider" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9cda73601658d30295f1a4e93614166da9ad925f26196157f48e0e225ef70a" +checksum = "dc2dfaddd9a30aa870a78a4e1316e3e115ec1e12e552cbc881310456b85c1f24" dependencies = [ "alloy-chains", "alloy-consensus", @@ -409,9 +409,9 @@ dependencies = [ [[package]] name = "alloy-pubsub" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2a83226edba216f2464b1bd48a06dd8e8d836427883568ec63ecda65d770f830" +checksum = "695809e743628d54510c294ad17a4645bd9f465aeb0d20ee9ce9877c9712dc9c" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -450,9 +450,9 @@ dependencies = [ [[package]] name = "alloy-rpc-client" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "318806a3a1f5e8c2f110de2bdf5aa14faf9f2f19a4f24603a8cb968b35319a6c" +checksum = "531137b283547d5b9a5cafc96b006c64ef76810c681d606f28be9781955293b6" dependencies = [ "alloy-json-rpc", "alloy-primitives", @@ -475,9 +475,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a97b37bdea65460684bcfdbd6c3bac43dec7316fa634da2d96f16df9b970482f" +checksum = "3410a472ce26c457e9780f708ee6bd540b30f88f1f31fdab7a11d00bd6aa1aee" dependencies = [ "alloy-primitives", "alloy-rpc-types-engine", @@ -488,9 +488,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-admin" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "972a7682802bb02ce42a5b32a5b5d6952717159c0007c20834c3e40aebc94349" +checksum = "5e4da9f5c14c38d84ce83a7c76541d39b7fd15ccd2265690151284544836e8c8" dependencies = [ "alloy-genesis", "alloy-primitives", @@ -500,9 +500,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-anvil" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa29f70eb194f0e61df4ac7d6c5226ed5588c386f0ebdcf7c43d7623e05d755a" +checksum = "9ed06bd8a5fc57b352a6cbac24eec52a4760f08ae2c1eb56ac49c8ed4b02c351" dependencies = [ "alloy-primitives", "alloy-rpc-types-eth", @@ -523,9 +523,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-beacon" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c9d4cdff2aef8bc2a2b6b172a87bd205ed293ad23aa21d86a2eb82dbfc88231" +checksum = "c966cacae719252501d2c5f6b67beac2fd6c03ec3c5bb64d664e769737ea5651" dependencies = [ "alloy-eips", "alloy-primitives", @@ -539,9 +539,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-debug" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "893786e4bd2acb2884fc5a708a64e9a64f1e233c40cc2f8583219f6f5ff67f6c" +checksum = "e1dec1c1b65614ebd5834a7dfddf525a186962082023718e10f4f64ed2d02514" dependencies = [ "alloy-primitives", "serde", @@ -549,9 +549,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-engine" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90ebd3bd158875c60bef2167e858ef004455f17ee19f19670149b4fc6567fb7f" +checksum = "03bd16fa4959255ebf4a7702df08f325e5631df5cdca07c8a8e58bdc10fe02e3" dependencies = [ "alloy-consensus", "alloy-eips", @@ -570,9 +570,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-eth" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43495c55aeaac24faa4f8b315ea8b7ee6e49985bd1edfcb1e156177de59b55a6" +checksum = "8737d7a6e37ca7bba9c23e9495c6534caec6760eb24abc9d5ffbaaba147818e1" dependencies = [ "alloy-consensus", "alloy-consensus-any", @@ -592,9 +592,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-mev" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3cd734a907a7d6c26a2f054a13ee194212143b50ffc34d4d3505d38b05fce88" +checksum = "d81da8a9b3094af917a109d55617844096d22c8dbf70cde1c5a93a2bbef7c29a" dependencies = [ "alloy-eips", "alloy-primitives", @@ -606,9 +606,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-trace" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d1dcc3dae728f6b576ca96b055f3ee91e1e9f88a2d36bc8d578fafef803c356" +checksum = "db14a83665cd28ffd01939f04c2adf0e0fd9bb648b73ca651dcaa0869dae027f" dependencies = [ "alloy-primitives", "alloy-rpc-types-eth", @@ -620,9 +620,9 @@ dependencies = [ [[package]] name = "alloy-rpc-types-txpool" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da98336d7b576d85df704c678043bf21d65f8e15512f217838584257c7354a21" +checksum = "0a574e97dff62097d22d6cd360f898f3d069239ca0ca7bfc2e5e7b22815ec572" dependencies = [ "alloy-primitives", "alloy-rpc-types-eth", @@ -632,9 +632,9 @@ dependencies = [ [[package]] name = "alloy-serde" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "514e925398442f5ac13d33ba98e26bd99925131edd4928a9a15658ec67f2bf92" +checksum = "5851bf8d5ad33014bd0c45153c603303e730acc8a209450a7ae6b4a12c2789e2" dependencies = [ "alloy-primitives", "arbitrary", @@ -644,9 +644,9 @@ dependencies = [ [[package]] name = "alloy-signer" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39d611775721dfe9f993d94308ac6c84ea5b1880e4c91e8b38c86d3e610ae41c" +checksum = "7e10ca565da6500cca015ba35ee424d59798f2e1b85bc0dd8f81dafd401f029a" dependencies = [ "alloy-primitives", "async-trait", @@ -658,9 +658,9 @@ dependencies = [ [[package]] name = "alloy-signer-local" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bccfe7997ffd0a721995c61cda28b842d0fb5231ddc51b8a4c1ee1c9a9bbb6ed" +checksum = "47fababf5a745133490cde927d48e50267f97d3d1209b9fc9f1d1d666964d172" dependencies = [ "alloy-consensus", "alloy-network", @@ -746,9 +746,9 @@ dependencies = [ [[package]] name = "alloy-transport" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3df16f5842a8484d8523297a5c1d574ec0f43500b1baa0566ff1ea4190883c5c" +checksum = "538a04a37221469cac0ce231b737fd174de2fdfcdd843bdd068cb39ed3e066ad" dependencies = [ "alloy-json-rpc", "base64 0.22.1", @@ -766,9 +766,9 @@ dependencies = [ [[package]] name = "alloy-transport-http" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c4c662b3f9d5d4470ea7f0d60ad00c9332315001d0acbe91f6b0ca0df535f4" +checksum = "2ed40eb1e1265b2911512f6aa1dcece9702d078f5a646730c45e39e2be00ac1c" dependencies = [ "alloy-json-rpc", "alloy-transport", @@ -781,9 +781,9 @@ dependencies = [ [[package]] name = "alloy-transport-ipc" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60c8d8a4c922358c27da4cc639cb8bba527376e1e268beac230751aec80231b9" +checksum = "a7a172a59d24706b26a79a837f86d51745cb26ca6f8524712acd0208a14cff95" dependencies = [ "alloy-json-rpc", "alloy-pubsub", @@ -800,9 +800,9 @@ dependencies = [ [[package]] name = "alloy-transport-ws" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dff9302c8430fe84e88c445f243f99d7f189e4c8a78ab8a56312bfa5ad0801f" +checksum = "fba0e39d181d13c266dbb8ca54ed584a2c66d6e9279afca89c7a6b1825e98abb" dependencies = [ "alloy-pubsub", "alloy-transport", diff --git a/Cargo.toml b/Cargo.toml index e23c3724f..7853c0da8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -441,40 +441,40 @@ alloy-rlp = { version = "0.3.10", default-features = false } alloy-sol-types = "0.8.15" alloy-trie = { version = "0.7", default-features = false } -alloy-consensus = { version = "0.8.2", default-features = false } -alloy-contract = { version = "0.8.2", default-features = false } -alloy-eips = { version = "0.8.2", default-features = false } -alloy-genesis = { version = "0.8.2", default-features = false } -alloy-json-rpc = { version = "0.8.2", default-features = false } -alloy-network = { version = "0.8.2", default-features = false } -alloy-network-primitives = { version = "0.8.2", default-features = false } -alloy-node-bindings = { version = "0.8.2", default-features = false } -alloy-provider = { version = "0.8.2", features = [ +alloy-consensus = { version = "0.8.3", default-features = false } +alloy-contract = { version = "0.8.3", default-features = false } +alloy-eips = { version = "0.8.3", default-features = false } +alloy-genesis = { version = "0.8.3", default-features = false } +alloy-json-rpc = { version = "0.8.3", default-features = false } +alloy-network = { version = "0.8.3", default-features = false } +alloy-network-primitives = { version = "0.8.3", default-features = false } +alloy-node-bindings = { version = "0.8.3", default-features = false } +alloy-provider = { version = "0.8.3", features = [ "reqwest", ], default-features = false } -alloy-pubsub = { version = "0.8.2", default-features = false } -alloy-rpc-client = { version = "0.8.2", default-features = false } -alloy-rpc-types = { version = "0.8.2", features = [ +alloy-pubsub = { version = "0.8.3", default-features = false } +alloy-rpc-client = { version = "0.8.3", default-features = false } +alloy-rpc-types = { version = "0.8.3", features = [ "eth", ], default-features = false } -alloy-rpc-types-admin = { version = "0.8.2", default-features = false } -alloy-rpc-types-anvil = { version = "0.8.2", default-features = false } -alloy-rpc-types-beacon = { version = "0.8.2", default-features = false } -alloy-rpc-types-debug = { version = "0.8.2", default-features = false } -alloy-rpc-types-engine = { version = "0.8.2", default-features = false } -alloy-rpc-types-eth = { version = "0.8.2", default-features = false } -alloy-rpc-types-mev = { version = "0.8.2", default-features = false } -alloy-rpc-types-trace = { version = "0.8.2", default-features = false } -alloy-rpc-types-txpool = { version = "0.8.2", default-features = false } -alloy-serde = { version = "0.8.2", default-features = false } -alloy-signer = { version = "0.8.2", default-features = false } -alloy-signer-local = { version = "0.8.2", default-features = false } -alloy-transport = { version = "0.8.2" } -alloy-transport-http = { version = "0.8.2", features = [ +alloy-rpc-types-admin = { version = "0.8.3", default-features = false } +alloy-rpc-types-anvil = { version = "0.8.3", default-features = false } +alloy-rpc-types-beacon = { version = "0.8.3", default-features = false } +alloy-rpc-types-debug = { version = "0.8.3", default-features = false } +alloy-rpc-types-engine = { version = "0.8.3", default-features = false } +alloy-rpc-types-eth = { version = "0.8.3", default-features = false } +alloy-rpc-types-mev = { version = "0.8.3", default-features = false } +alloy-rpc-types-trace = { version = "0.8.3", default-features = false } +alloy-rpc-types-txpool = { version = "0.8.3", default-features = false } +alloy-serde = { version = "0.8.3", default-features = false } +alloy-signer = { version = "0.8.3", default-features = false } +alloy-signer-local = { version = "0.8.3", default-features = false } +alloy-transport = { version = "0.8.3" } +alloy-transport-http = { version = "0.8.3", features = [ "reqwest-rustls-tls", ], default-features = false } -alloy-transport-ipc = { version = "0.8.2", default-features = false } -alloy-transport-ws = { version = "0.8.2", default-features = false } +alloy-transport-ipc = { version = "0.8.3", default-features = false } +alloy-transport-ws = { version = "0.8.3", default-features = false } # op op-alloy-rpc-types = "0.8.4" diff --git a/crates/primitives-traits/src/block/body.rs b/crates/primitives-traits/src/block/body.rs index 8c8804b59..37342733b 100644 --- a/crates/primitives-traits/src/block/body.rs +++ b/crates/primitives-traits/src/block/body.rs @@ -4,7 +4,7 @@ use crate::{ BlockHeader, FullSignedTx, InMemorySize, MaybeSerde, MaybeSerdeBincodeCompat, SignedTransaction, }; use alloc::{fmt, vec::Vec}; -use alloy_consensus::Transaction; +use alloy_consensus::{Header, Transaction}; use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals}; use alloy_primitives::{Bytes, B256}; @@ -99,6 +99,30 @@ pub trait BlockBody: } } +impl BlockBody for alloy_consensus::BlockBody +where + T: SignedTransaction, +{ + type Transaction = T; + type OmmerHeader = Header; + + fn transactions(&self) -> &[Self::Transaction] { + &self.transactions + } + + fn into_transactions(self) -> Vec { + self.transactions + } + + fn withdrawals(&self) -> Option<&Withdrawals> { + self.withdrawals.as_ref() + } + + fn ommers(&self) -> Option<&[Self::OmmerHeader]> { + Some(&self.ommers) + } +} + /// This is a helper alias to make it easy to refer to the inner `Transaction` associated type of a /// given type that implements [`BlockBody`]. pub type BodyTx = ::Transaction; diff --git a/crates/primitives-traits/src/block/mod.rs b/crates/primitives-traits/src/block/mod.rs index 7354cba91..4c98a94b3 100644 --- a/crates/primitives-traits/src/block/mod.rs +++ b/crates/primitives-traits/src/block/mod.rs @@ -4,9 +4,13 @@ pub mod body; pub mod header; use alloc::fmt; +use alloy_consensus::Header; use alloy_rlp::{Decodable, Encodable}; -use crate::{BlockBody, BlockHeader, FullBlockBody, FullBlockHeader, InMemorySize, MaybeSerde}; +use crate::{ + BlockBody, BlockHeader, FullBlockBody, FullBlockHeader, InMemorySize, MaybeSerde, + SignedTransaction, +}; /// Helper trait that unifies all behaviour required by block to support full node operations. pub trait FullBlock: @@ -60,3 +64,27 @@ pub trait Block: /// Splits the block into its header and body. fn split(self) -> (Self::Header, Self::Body); } + +impl Block for alloy_consensus::Block +where + T: SignedTransaction, +{ + type Header = Header; + type Body = alloy_consensus::BlockBody; + + fn new(header: Self::Header, body: Self::Body) -> Self { + Self { header, body } + } + + fn header(&self) -> &Self::Header { + &self.header + } + + fn body(&self) -> &Self::Body { + &self.body + } + + fn split(self) -> (Self::Header, Self::Body) { + (self.header, self.body) + } +} diff --git a/crates/primitives-traits/src/size.rs b/crates/primitives-traits/src/size.rs index 278fcf2c3..185f9f08e 100644 --- a/crates/primitives-traits/src/size.rs +++ b/crates/primitives-traits/src/size.rs @@ -2,6 +2,7 @@ use alloy_consensus::{ transaction::PooledTransaction, Header, TxEip1559, TxEip2930, TxEip4844, TxEip4844WithSidecar, TxEip7702, TxLegacy, TxType, }; +use alloy_eips::eip4895::Withdrawals; use alloy_primitives::{PrimitiveSignature as Signature, TxHash}; use revm_primitives::Log; @@ -82,6 +83,27 @@ impl InMemorySize for PooledTransaction { } } +impl InMemorySize for alloy_consensus::BlockBody { + /// Calculates a heuristic for the in-memory size of the block body + #[inline] + fn size(&self) -> usize { + self.transactions.iter().map(T::size).sum::() + + self.transactions.capacity() * core::mem::size_of::() + + self.ommers.iter().map(Header::size).sum::() + + self.ommers.capacity() * core::mem::size_of::
() + + self.withdrawals + .as_ref() + .map_or(core::mem::size_of::>(), Withdrawals::total_size) + } +} + +impl InMemorySize for alloy_consensus::Block { + #[inline] + fn size(&self) -> usize { + self.header.size() + self.body.size() + } +} + #[cfg(feature = "op")] impl InMemorySize for op_alloy_consensus::OpDepositReceipt { fn size(&self) -> usize {