Skip to content

Commit

Permalink
feat(rpc/trace): apply pre-filter
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <delweng@gmail.com>
  • Loading branch information
jsvisa committed Jul 31, 2024
1 parent 17c17a1 commit 2c1e491
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions crates/rpc/rpc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,15 @@ where
// trace all blocks
let mut block_traces = Vec::with_capacity(blocks.len());
for block in &blocks {
let matcher = matcher.clone();
let traces = self.inner.eth_api.trace_block_until(
block.number.into(),
None,
TracingInspectorConfig::default_parity(),
move |tx_info, inspector, res, _, _| {
let traces =
move |tx_info, inspector, _, _, _| {
let mut traces =
inspector.into_parity_builder().into_localized_transaction_traces(tx_info);
traces.retain(|trace| matcher.matches(&trace.trace));
Ok(Some(traces))
},
);
Expand All @@ -303,24 +305,17 @@ where
// add reward traces for all blocks
for block in &blocks {
if let Some(base_block_reward) = self.calculate_base_block_reward(&block.header)? {
all_traces.extend(self.extract_reward_traces(
&block.header,
&block.ommers,
base_block_reward,
));
let mut traces =
self.extract_reward_traces(&block.header, &block.ommers, base_block_reward);
traces.retain(|trace| matcher.matches(&trace.trace));
all_traces.extend(traces);
} else {
// no block reward, means we're past the Paris hardfork and don't expect any rewards
// because the blocks in ascending order
break
}
}

// filter out traces that don't match the filter
all_traces = all_traces
.into_iter()
.filter(|trace| matcher.matches(&trace.trace))
.collect::<Vec<_>>();

// apply after and count to traces if specified, this allows for a pagination style.
// only consider traces after
if let Some(after) = after.map(|a| a as usize).filter(|a| *a < all_traces.len()) {
Expand Down

0 comments on commit 2c1e491

Please sign in to comment.