mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: Alloy migration (#4737)
Co-authored-by: Alessandro Mazza <121622391+alessandromazza98@users.noreply.github.com> Co-authored-by: Supernovahs.eth <91280922+supernovahs@users.noreply.github.com> Co-authored-by: Oliver Nordbjerg <hi@notbjerg.me>
This commit is contained in:
@ -1,8 +1,7 @@
|
||||
use alloy_rlp::Decodable;
|
||||
use criterion::{criterion_group, criterion_main, Criterion};
|
||||
use hex_literal::hex;
|
||||
use pprof::criterion::{Output, PProfProfiler};
|
||||
use reth_primitives::TransactionSigned;
|
||||
use reth_rlp::Decodable;
|
||||
use reth_primitives::{hex_literal::hex, TransactionSigned};
|
||||
|
||||
/// Benchmarks the recovery of the public key from the ECDSA message using criterion.
|
||||
pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
|
||||
@ -4,7 +4,7 @@ use proptest::{
|
||||
strategy::{Strategy, ValueTree},
|
||||
test_runner::TestRunner,
|
||||
};
|
||||
use reth_primitives::{proofs::triehash::KeccakHasher, ReceiptWithBloom, H256};
|
||||
use reth_primitives::{proofs::triehash::KeccakHasher, ReceiptWithBloom, B256};
|
||||
|
||||
/// Benchmarks different implementations of the root calculation.
|
||||
pub fn trie_root_benchmark(c: &mut Criterion) {
|
||||
@ -14,34 +14,24 @@ pub fn trie_root_benchmark(c: &mut Criterion) {
|
||||
let group_name =
|
||||
|description: &str| format!("receipts root | size: {size} | {description}");
|
||||
|
||||
let (test_data, expected) = generate_test_data(size);
|
||||
use implementations::*;
|
||||
let receipts = &generate_test_data(size)[..];
|
||||
assert_eq!(trie_hash_ordered_trie_root(receipts), hash_builder_root(receipts));
|
||||
|
||||
group.bench_function(group_name("triehash::ordered_trie_root"), |b| {
|
||||
b.iter(|| {
|
||||
let receipts = test_data.clone();
|
||||
let result = black_box(trie_hash_ordered_trie_root(receipts.into_iter()));
|
||||
assert_eq!(result, expected);
|
||||
});
|
||||
b.iter(|| trie_hash_ordered_trie_root(black_box(receipts)));
|
||||
});
|
||||
|
||||
group.bench_function(group_name("HashBuilder"), |b| {
|
||||
b.iter(|| {
|
||||
let receipts = test_data.clone();
|
||||
let result = black_box(hash_builder_root(receipts));
|
||||
assert_eq!(result, expected);
|
||||
});
|
||||
b.iter(|| hash_builder_root(black_box(receipts)));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_test_data(size: usize) -> (Vec<ReceiptWithBloom>, H256) {
|
||||
let receipts = prop::collection::vec(any::<ReceiptWithBloom>(), size)
|
||||
fn generate_test_data(size: usize) -> Vec<ReceiptWithBloom> {
|
||||
prop::collection::vec(any::<ReceiptWithBloom>(), size)
|
||||
.new_tree(&mut TestRunner::new(ProptestConfig::default()))
|
||||
.unwrap()
|
||||
.current();
|
||||
let root = implementations::hash_builder_root(receipts.clone());
|
||||
(receipts, root)
|
||||
.current()
|
||||
}
|
||||
|
||||
criterion_group! {
|
||||
@ -53,23 +43,22 @@ criterion_main!(benches);
|
||||
|
||||
mod implementations {
|
||||
use super::*;
|
||||
use alloy_rlp::Encodable;
|
||||
use bytes::BytesMut;
|
||||
use reth_primitives::{
|
||||
proofs::adjust_index_for_rlp,
|
||||
trie::{HashBuilder, Nibbles},
|
||||
};
|
||||
use reth_rlp::Encodable;
|
||||
use std::vec::IntoIter;
|
||||
|
||||
pub fn trie_hash_ordered_trie_root(receipts: IntoIter<ReceiptWithBloom>) -> H256 {
|
||||
triehash::ordered_trie_root::<KeccakHasher, _>(receipts.map(|receipt| {
|
||||
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 hash_builder_root(receipts: Vec<ReceiptWithBloom>) -> H256 {
|
||||
pub fn hash_builder_root(receipts: &[ReceiptWithBloom]) -> B256 {
|
||||
let mut index_buffer = BytesMut::new();
|
||||
let mut value_buffer = BytesMut::new();
|
||||
|
||||
@ -90,3 +79,4 @@ mod implementations {
|
||||
hb.root()
|
||||
}
|
||||
}
|
||||
use implementations::*;
|
||||
|
||||
Reference in New Issue
Block a user