Skip to content

Commit

Permalink
refactor: remove alloy-trie, add reth-primitives back
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrohba1 committed Feb 14, 2025
1 parent 41d8900 commit 36bb831
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/decoder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ alloy-eip2930.workspace = true
bincode.workspace = true
firehose-protos.workspace = true
prost.workspace = true
reth-primitives.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
thiserror.workspace = true
Expand Down
4 changes: 3 additions & 1 deletion crates/firehose-protos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ alloy-consensus.workspace = true
alloy-eip2930.workspace = true
alloy-primitives.workspace = true
alloy-rlp.workspace = true
alloy-trie.workspace = true
# TODO: use alloy-trie when it is certain
# that it wont break other functionalities
#alloy-trie.workspace = true
ethportal-api.workspace = true
firehose-rs.workspace = true
prost.workspace = true
Expand Down
23 changes: 11 additions & 12 deletions crates/firehose-protos/src/ethereum_v2/eth_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
// SPDX-License-Identifier: Apache-2.0

use super::{Block, BlockHeader, TransactionReceipt, TransactionTrace};
use alloy_consensus::{proofs::calculate_transaction_root, Receipt, ReceiptWithBloom};
use alloy_primitives::{hex, Address, Bloom, FixedBytes, Log, Uint, B256};
use alloy_rlp::{Encodable, Header as RlpHeader};
use alloy_trie::root::ordered_trie_root_with_encoder;
use alloy_consensus::Receipt;
use alloy_eips::Typed2718;
use alloy_primitives::{hex, Address, Bloom, FixedBytes, Uint, B256};
use alloy_rlp::{BufMut, Encodable, Header as RlpHeader};
use ethportal_api::types::execution::header::Header;
use firehose_rs::{FromResponse, HasNumberOrSlot, Response, SingleBlockResponse};
use prost::Message;
use prost_wkt_types::Any;
use reth_primitives::TransactionSigned;
use reth_primitives::{
proofs::{calculate_transaction_root, ordered_trie_root_with_encoder},
Log, ReceiptWithBloom, TransactionSigned,
};
use tracing::error;

use crate::error::ProtosError;
Expand Down Expand Up @@ -152,8 +156,7 @@ impl Block {
///
pub fn calculate_receipt_root(&self) -> Result<B256, ProtosError> {
let receipts = self.full_receipts()?;
let encoder = self.full_receipt_encoder();
Ok(ordered_trie_root_with_encoder(&receipts, encoder))
return Ok(calculate_receipt_root(&receipts));
}

fn calculate_transaction_root(&self) -> Result<FixedBytes<32>, ProtosError> {
Expand Down Expand Up @@ -192,12 +195,8 @@ impl Block {
///
/// A function that encodes a [`FullReceipt`] into an RLP format, writing the result to a mutable `Vec<u8>`.
///
fn full_receipt_encoder(&self) -> fn(&FullReceipt, &mut Vec<u8>) {
if self.is_pre_byzantium() {
|r: &FullReceipt, out: &mut Vec<u8>| r.encode_pre_byzantium_receipt(out)
} else {
|r: &FullReceipt, out: &mut Vec<u8>| r.encode_byzantium_and_later_receipt(out)
}
fn full_receipt_encoder(&self) -> impl Fn(&FullReceipt, &mut dyn BufMut) {
|r: &FullReceipt, out: &mut dyn BufMut| r.receipt.encode(out)
}

/// Returns a reference to the block header.
Expand Down

0 comments on commit 36bb831

Please sign in to comment.