Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consensus: implement root_slow for Receipts #1563

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion crates/consensus/src/receipt/receipts.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::receipt::{Eip658Value, TxReceipt};
use alloc::{vec, vec::Vec};
use alloy_primitives::{Bloom, Log};
use alloy_primitives::{Bloom, Log, B256};
use alloy_rlp::{length_of_length, BufMut, Decodable, Encodable};
use core::{borrow::Borrow, fmt};
use derive_more::{DerefMut, From, IntoIterator};
Expand Down Expand Up @@ -126,6 +126,12 @@ impl<T> Receipts<T> {
pub fn push(&mut self, receipts: Vec<T>) {
self.receipt_vec.push(receipts);
}

/// Retrieves all recorded receipts from index and calculates the root using the given closure.
pub fn root_slow(&self, index: usize, f: impl FnOnce(&[&T]) -> B256) -> Option<B256> {
let receipts = self.receipt_vec.get(index)?.iter().collect::<Vec<_>>();
Some(f(receipts.as_slice()))
}
}

impl<T> From<Vec<T>> for Receipts<T> {
Expand Down