Skip to content

Commit

Permalink
some touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Dec 15, 2023
1 parent 92fc57b commit 543c486
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
9 changes: 4 additions & 5 deletions crates/rpc/rpc/src/eth/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ where

// cache good receipts
if let Ok(Some(receipts)) = res {
self.receipts_cache.insert(block_hash, Arc::clone(&receipts));
self.receipts_cache.insert(block_hash, receipts);
}
}

Expand Down Expand Up @@ -434,10 +434,9 @@ where
this.action_task_spawner.spawn_blocking(Box::pin(async move {
// Acquire permit
let _permit = rate_limiter.acquire().await;
// TODO rename receipts option
let res = provider.receipts_by_block(block_hash.into()).map(
|receipts_option| {
receipts_option.map(|receipts| Arc::new(receipts))
|maybe_receipts| {
maybe_receipts.map(|receipts| Arc::new(receipts))
},
);

Expand Down Expand Up @@ -515,7 +514,7 @@ where
.receipts
.into_iter()
.flatten()
.collect::<Vec<Receipt>>(),
.collect(),
))),
);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/rpc/src/eth/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ where
&mut all_logs,
&filter,
(block_hash, block.number).into(),
block.body.into_iter().map(|tx| tx.hash()).zip(receipts.to_vec()),
block.body.into_iter().map(|tx| tx.hash()).zip(receipts.iter()),
false,
);
}
Expand Down Expand Up @@ -471,7 +471,7 @@ where
.body
.into_iter()
.map(|tx| tx.hash())
.zip(receipts.iter().map(|receipt| receipt.clone())), /* TODO: think of something better to avoid cloning */
.zip(receipts.iter()),
false,
);

Expand Down
17 changes: 8 additions & 9 deletions crates/rpc/rpc/src/eth/logs_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,40 @@ use reth_rpc_types::{FilteredParams, Log};
use reth_rpc_types_compat::log::from_primitive_log;

/// Returns all matching logs of a block's receipts grouped with the hash of their transaction.
pub(crate) fn matching_block_logs<I>(
pub(crate) fn matching_block_logs<'a, I>(
filter: &FilteredParams,
block: BlockNumHash,
tx_and_receipts: I,
removed: bool,
) -> Vec<Log>
where
I: IntoIterator<Item = (TxHash, Receipt)>,
I: IntoIterator<Item = (TxHash, &'a Receipt)>,
{
let mut all_logs = Vec::new();
append_matching_block_logs(&mut all_logs, filter, block, tx_and_receipts, removed);
all_logs
}

/// Appends all matching logs of a block's receipts grouped with the hash of their transaction
pub(crate) fn append_matching_block_logs<I>(
pub(crate) fn append_matching_block_logs<'a, I>(
all_logs: &mut Vec<Log>,
filter: &FilteredParams,
block: BlockNumHash,
tx_and_receipts: I,
removed: bool,
) where
I: IntoIterator<Item = (TxHash, Receipt)>,
I: IntoIterator<Item = (TxHash, &'a Receipt)>,
{
let block_number_u256 = U256::from(block.number);
// tracks the index of a log in the entire block
let mut log_index: u32 = 0;
for (transaction_idx, (transaction_hash, receipt)) in tx_and_receipts.into_iter().enumerate() {
let logs = receipt.logs;
for log in logs.into_iter() {
if log_matches_filter(block, &log, filter) {
for log in receipt.logs.iter() {
if log_matches_filter(block, log, filter) {
let log = Log {
address: log.address,
topics: log.topics,
data: log.data,
topics: log.topics.clone(),
data: log.data.clone(),
block_hash: Some(block.hash),
block_number: Some(block_number_u256),
transaction_hash: Some(transaction_hash),
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc/src/eth/pubsub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ where
let all_logs = logs_utils::matching_block_logs(
&filter,
block_receipts.block,
block_receipts.tx_receipts,
block_receipts.tx_receipts.iter().map(|(tx, receipt)| (*tx, receipt)),
removed,
);
futures::stream::iter(all_logs)
Expand Down

0 comments on commit 543c486

Please sign in to comment.