mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-02-19 03:04:27 -05:00
chore: reuse alloy-primitives logs bloom (#12031)
This commit is contained in:
4
Cargo.lock
generated
4
Cargo.lock
generated
@@ -286,9 +286,9 @@ dependencies = [
|
||||
|
||||
[[package]]
|
||||
name = "alloy-primitives"
|
||||
version = "0.8.8"
|
||||
version = "0.8.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "38f35429a652765189c1c5092870d8360ee7b7769b09b06d89ebaefd34676446"
|
||||
checksum = "c71738eb20c42c5fb149571e76536a0f309d142f3957c28791662b96baf77a3d"
|
||||
dependencies = [
|
||||
"alloy-rlp",
|
||||
"arbitrary",
|
||||
|
||||
@@ -427,7 +427,7 @@ revm-primitives = { version = "13.0.0", features = [
|
||||
# eth
|
||||
alloy-chains = "0.1.32"
|
||||
alloy-dyn-abi = "0.8.0"
|
||||
alloy-primitives = { version = "0.8.7", default-features = false }
|
||||
alloy-primitives = { version = "0.8.9", default-features = false }
|
||||
alloy-rlp = "0.3.4"
|
||||
alloy-sol-types = "0.8.0"
|
||||
alloy-trie = { version = "0.7", default-features = false }
|
||||
|
||||
@@ -39,7 +39,7 @@ mod error;
|
||||
pub use error::{GotExpected, GotExpectedBoxed};
|
||||
|
||||
mod log;
|
||||
pub use log::{logs_bloom, Log, LogData};
|
||||
pub use alloy_primitives::{logs_bloom, Log, LogData};
|
||||
|
||||
mod storage;
|
||||
pub use storage::StorageEntry;
|
||||
|
||||
@@ -1,18 +1,3 @@
|
||||
use alloy_primitives::Bloom;
|
||||
pub use alloy_primitives::{Log, LogData};
|
||||
|
||||
/// Calculate receipt logs bloom.
|
||||
pub fn logs_bloom<'a>(logs: impl IntoIterator<Item = &'a Log>) -> Bloom {
|
||||
let mut bloom = Bloom::ZERO;
|
||||
for log in logs {
|
||||
bloom.m3_2048(log.address.as_slice());
|
||||
for topic in log.topics() {
|
||||
bloom.m3_2048(topic.as_slice());
|
||||
}
|
||||
}
|
||||
bloom
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use alloy_primitives::{Address, Bytes, Log as AlloyLog, B256};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#[cfg(feature = "reth-codec")]
|
||||
use crate::compression::{RECEIPT_COMPRESSOR, RECEIPT_DECOMPRESSOR};
|
||||
use crate::{logs_bloom, TxType};
|
||||
use crate::TxType;
|
||||
use alloc::{vec, vec::Vec};
|
||||
use alloy_consensus::constants::{
|
||||
EIP1559_TX_TYPE_ID, EIP2930_TX_TYPE_ID, EIP4844_TX_TYPE_ID, EIP7702_TX_TYPE_ID,
|
||||
@@ -49,7 +49,7 @@ impl Receipt {
|
||||
/// Calculates [`Log`]'s bloom filter. this is slow operation and [`ReceiptWithBloom`] can
|
||||
/// be used to cache this value.
|
||||
pub fn bloom_slow(&self) -> Bloom {
|
||||
logs_bloom(self.logs.iter())
|
||||
alloy_primitives::logs_bloom(self.logs.iter())
|
||||
}
|
||||
|
||||
/// Calculates the bloom filter for the receipt and returns the [`ReceiptWithBloom`] container
|
||||
|
||||
@@ -9,7 +9,6 @@ use alloy_rpc_types::{
|
||||
use alloy_rpc_types_eth::transaction::TransactionRequest;
|
||||
use jsonrpsee_types::ErrorObject;
|
||||
use reth_primitives::{
|
||||
logs_bloom,
|
||||
proofs::{calculate_receipt_root, calculate_transaction_root},
|
||||
BlockBody, BlockWithSenders, Receipt, Signature, Transaction, TransactionSigned,
|
||||
TransactionSignedNoHash,
|
||||
@@ -290,7 +289,9 @@ pub fn build_block<T: TransactionCompat>(
|
||||
receipts_root: calculate_receipt_root(&receipts),
|
||||
transactions_root: calculate_transaction_root(&transactions),
|
||||
state_root,
|
||||
logs_bloom: logs_bloom(receipts.iter().flat_map(|r| r.receipt.logs.iter())),
|
||||
logs_bloom: alloy_primitives::logs_bloom(
|
||||
receipts.iter().flat_map(|r| r.receipt.logs.iter()),
|
||||
),
|
||||
mix_hash: block_env.prevrandao.unwrap_or_default(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
@@ -1257,19 +1257,24 @@ mod tests {
|
||||
// to test the sparse trie updates.
|
||||
const KEY_NIBBLES_LEN: usize = 3;
|
||||
|
||||
fn test(updates: Vec<HashMap<Nibbles, Vec<u8>>>) {
|
||||
fn test<I, T>(updates: I)
|
||||
where
|
||||
I: IntoIterator<Item = T>,
|
||||
T: IntoIterator<Item = (Nibbles, Vec<u8>)> + Clone,
|
||||
{
|
||||
let mut rng = generators::rng();
|
||||
|
||||
let mut state = BTreeMap::default();
|
||||
let mut sparse = RevealedSparseTrie::default();
|
||||
|
||||
for update in updates {
|
||||
let keys_to_delete_len = update.len() / 2;
|
||||
|
||||
let mut count = 0;
|
||||
// Insert state updates into the sparse trie and calculate the root
|
||||
for (key, value) in update.clone() {
|
||||
sparse.update_leaf(key, value).unwrap();
|
||||
count += 1;
|
||||
}
|
||||
let keys_to_delete_len = count / 2;
|
||||
let sparse_root = sparse.root();
|
||||
|
||||
// Insert state updates into the hash builder and calculate the root
|
||||
@@ -1329,7 +1334,8 @@ mod tests {
|
||||
),
|
||||
1..100,
|
||||
)
|
||||
)| { test(updates.into_iter().collect()) });
|
||||
)| {
|
||||
test(updates) });
|
||||
}
|
||||
|
||||
/// We have three leaves that share the same prefix: 0x00, 0x01 and 0x02. Hash builder trie has
|
||||
|
||||
Reference in New Issue
Block a user