Skip to content

Commit

Permalink
feat(forrestrie-examples): add example on how to retreieve an executi…
Browse files Browse the repository at this point in the history
…on layer block and generate proofs for it's receipts
  • Loading branch information
pedrohba1 committed Nov 6, 2024
1 parent 4b62d16 commit ad423a8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# TODO: set at least somewhere of these can be found, as most of them are either publicly available or
# behind an account-based API
FIREHOSE_ETHEREUM_URL=<YOUR-FIREHOSE-ETHEREUM-URL>
FIREHOSE_ETHEREUM_PORT=<YOUR-FIREHOSE-ETHEREUM-PORT>
FIREHOSE_BEACON_URL=<YOUR-FIREHOSE-BEACON-URL>
Expand All @@ -6,5 +8,7 @@ FIREHOSE_ARBITRUM_URL=<YOUR-FIREHOSE-ARBITRUM-URL>
FIREHOSE_ARBITRUM_PORT=<YOUR-FIREHOSE-ARBITRUM-PORT>
# Pinax is a great provider for blockchain data, so if you need an API key, you might want to check them out.
BEACON_API_KEY=<YOUR-API-KEY>

# For example, this ETHEREUM_API_KEY is for the StreamingFast firehose endpoint being used
ETHEREUM_API_KEY=<YOUR-API-KEY>
ARBITRUM_API_KEY=<YOUR-API-KEY>
1 change: 1 addition & 0 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/firehose-protos/src/ethereum_v2/eth_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,8 @@ impl Block {
}
}

struct FullReceipt {
receipt: ReceiptWithBloom,
pub struct FullReceipt {
pub receipt: ReceiptWithBloom,
state_root: Vec<u8>,
}

Expand Down
1 change: 1 addition & 0 deletions crates/forrestrie-examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ prost.workspace = true
prost-wkt.workspace = true
prost-wkt-types.workspace = true
reqwest = { workspace = true, features = ["json"] }
reth-primitives.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
ssz_types.workspace = true
Expand Down
40 changes: 40 additions & 0 deletions crates/forrestrie-examples/examples/receipts_proof.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//! # Receipts proof given an EL block's `receipt_root``
//!
//! This example shows how to generate an inclusion proof for a set of receipts of a EL block;
//!
//!
use firehose_client::client::{Chain, FirehoseClient};
use firehose_protos::ethereum_v2::{self, eth_block::FullReceipt, Block};
use forrestrie::execution_layer::build_trie_with_proofs;
use reth_primitives::ReceiptWithBloom;

const EXECUTION_BLOCK_NUMBER: u64 = 20759937;

#[tokio::main]
async fn main() {
let mut eth1_client = FirehoseClient::new(Chain::Ethereum);
let response = eth1_client
.fetch_block(EXECUTION_BLOCK_NUMBER)
.await
.unwrap()
.unwrap();
let eth1_block: Block = ethereum_v2::Block::try_from(response.into_inner()).unwrap();

let receipts: Vec<FullReceipt> = eth1_block
.transaction_traces
.iter()
.filter_map(|trace| {
// Attempt to convert each trace into a FullReceipt
FullReceipt::try_from(trace).ok() // Collect only successful conversions
})
.collect();

let receipts_with_bloom: Vec<ReceiptWithBloom> = receipts
.iter()
.map(|full_receipt| full_receipt.receipt.clone())
.collect();

let mut hb = build_trie_with_proofs(&receipts_with_bloom, &[1, 2, 3]);

let _root = hb.root();
}

0 comments on commit ad423a8

Please sign in to comment.