From 0cfad7125c8b6f75fdd0dfd33dcb9970a27c6677 Mon Sep 17 00:00:00 2001 From: Elias Tazartes <66871571+Eikix@users.noreply.github.com> Date: Thu, 11 Jan 2024 15:05:12 +0100 Subject: [PATCH] Feat/bloom filter (#710) * feat: add bloom filter in transaction receipt * feat: add todo for bloom in block --- src/models/block.rs | 6 ++++-- src/models/transaction_receipt.rs | 27 ++++++++++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/models/block.rs b/src/models/block.rs index f2a37b5a7..36259a20b 100644 --- a/src/models/block.rs +++ b/src/models/block.rs @@ -165,7 +165,7 @@ impl BlockWithTxHashes { // TODO: Fetch real data let gas_used = *GAS_USED; - // TODO: Fetch real data + // Difficulty should be 0 in a non-POW chain let difficulty = *DIFFICULTY; // TODO: Fetch real data @@ -174,7 +174,9 @@ impl BlockWithTxHashes { // TODO: Fetch real data let size: Option = *SIZE; - // Bloom is a byte array of length 256 + // TODO: + // Aggregate all the logs from the transactions + // Create a bloom filter from the logs and add it to the block let logs_bloom = Bloom::default(); let extra_data = Bytes::default(); diff --git a/src/models/transaction_receipt.rs b/src/models/transaction_receipt.rs index 89aefd8c6..8b49f7d94 100644 --- a/src/models/transaction_receipt.rs +++ b/src/models/transaction_receipt.rs @@ -1,6 +1,7 @@ +use reth_primitives::bloom::logs_bloom; use reth_primitives::contract::create_address; -use reth_primitives::{Bloom, H256, U128, U256, U64, U8}; -use reth_rpc_types::TransactionReceipt as EthTransactionReceipt; +use reth_primitives::{H256, U128, U256, U64, U8}; +use reth_rpc_types::{Log, TransactionReceipt as EthTransactionReceipt}; use starknet::core::types::{ ExecutionResult, InvokeTransactionReceipt, MaybePendingTransactionReceipt, TransactionReceipt, }; @@ -78,7 +79,7 @@ impl StarknetTransactionReceipt { ExecutionResult::Reverted { .. } => Some(U64::from(0)), }; - let logs = events + let logs: Vec = events .into_iter() .map(StarknetEvent::new) .filter_map(|event| { @@ -86,10 +87,22 @@ impl StarknetTransactionReceipt { }) .collect(); + // Reth note: + // This bloom operation is slow and should be cached if possible. + let bloom = { + let logs: Vec = logs + .iter() + .map(|log| reth_primitives::Log { + data: log.data.clone(), + topics: log.topics.clone(), + address: log.address, + }) + .collect(); + logs_bloom(logs.iter()) + }; + EthTransactionReceipt { transaction_hash, - // TODO: transition this hardcoded default out of nearing-demo-day hack and seeing how to - // properly source/translate this value transaction_index: U64::from(0), // TODO: Fetch real data block_hash, block_number, @@ -99,8 +112,8 @@ impl StarknetTransactionReceipt { gas_used: Some(U256::from(500_000)), contract_address, logs, - state_root: None, // TODO: Fetch real data - logs_bloom: Bloom::default(), // TODO: Fetch real data + state_root: None, + logs_bloom: bloom, status_code, effective_gas_price: U128::from(1_000_000), // TODO: Fetch real data transaction_type: U8::from(0), // TODO: Fetch real data