mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: unify ReceiptWithBloom from Alloy (#13088)
Co-authored-by: Arsenii Kulikov <klkvrr@gmail.com>
This commit is contained in:
committed by
GitHub
parent
55f931d0b9
commit
cd13bd91cd
@ -348,7 +348,6 @@ impl<F: BlindedProviderFactory> SparseStateTrie<F> {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl<F> SparseStateTrie<F>
|
||||
where
|
||||
F: BlindedProviderFactory,
|
||||
|
||||
@ -23,6 +23,7 @@ reth-trie-common.workspace = true
|
||||
revm.workspace = true
|
||||
|
||||
# alloy
|
||||
alloy-eips.workspace = true
|
||||
alloy-rlp.workspace = true
|
||||
alloy-primitives.workspace = true
|
||||
alloy-consensus.workspace = true
|
||||
@ -63,6 +64,7 @@ serde = [
|
||||
"alloy-primitives/serde",
|
||||
"alloy-consensus/serde",
|
||||
"alloy-trie/serde",
|
||||
"alloy-eips/serde",
|
||||
"revm/serde",
|
||||
"reth-trie-common/serde"
|
||||
]
|
||||
|
||||
@ -3,7 +3,7 @@ use alloy_primitives::B256;
|
||||
use criterion::{black_box, criterion_group, criterion_main, Criterion};
|
||||
use proptest::{prelude::*, strategy::ValueTree, test_runner::TestRunner};
|
||||
use proptest_arbitrary_interop::arb;
|
||||
use reth_primitives::ReceiptWithBloom;
|
||||
use reth_primitives::{Receipt, ReceiptWithBloom};
|
||||
use reth_trie::triehash::KeccakHasher;
|
||||
|
||||
/// Benchmarks different implementations of the root calculation.
|
||||
@ -27,8 +27,8 @@ pub fn trie_root_benchmark(c: &mut Criterion) {
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_test_data(size: usize) -> Vec<ReceiptWithBloom> {
|
||||
prop::collection::vec(arb::<ReceiptWithBloom>(), size)
|
||||
fn generate_test_data(size: usize) -> Vec<ReceiptWithBloom<Receipt>> {
|
||||
prop::collection::vec(arb::<ReceiptWithBloom<Receipt>>(), size)
|
||||
.new_tree(&mut TestRunner::new(ProptestConfig::default()))
|
||||
.unwrap()
|
||||
.current()
|
||||
@ -43,19 +43,19 @@ criterion_main!(benches);
|
||||
|
||||
mod implementations {
|
||||
use super::*;
|
||||
use alloy_eips::eip2718::Encodable2718;
|
||||
use alloy_rlp::Encodable;
|
||||
use alloy_trie::root::adjust_index_for_rlp;
|
||||
use reth_primitives::Receipt;
|
||||
use reth_trie_common::{HashBuilder, Nibbles};
|
||||
|
||||
pub fn trie_hash_ordered_trie_root(receipts: &[ReceiptWithBloom]) -> B256 {
|
||||
triehash::ordered_trie_root::<KeccakHasher, _>(receipts.iter().map(|receipt| {
|
||||
let mut receipt_rlp = Vec::new();
|
||||
receipt.encode_inner(&mut receipt_rlp, false);
|
||||
receipt_rlp
|
||||
}))
|
||||
pub fn trie_hash_ordered_trie_root(receipts: &[ReceiptWithBloom<Receipt>]) -> B256 {
|
||||
triehash::ordered_trie_root::<KeccakHasher, _>(
|
||||
receipts.iter().map(|receipt_with_bloom| receipt_with_bloom.encoded_2718()),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn hash_builder_root(receipts: &[ReceiptWithBloom]) -> B256 {
|
||||
pub fn hash_builder_root(receipts: &[ReceiptWithBloom<Receipt>]) -> B256 {
|
||||
let mut index_buffer = Vec::new();
|
||||
let mut value_buffer = Vec::new();
|
||||
|
||||
@ -68,7 +68,7 @@ mod implementations {
|
||||
index.encode(&mut index_buffer);
|
||||
|
||||
value_buffer.clear();
|
||||
receipts[index].encode_inner(&mut value_buffer, false);
|
||||
receipts[index].encode_2718(&mut value_buffer);
|
||||
|
||||
hb.add_leaf(Nibbles::unpack(&index_buffer), &value_buffer);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user