update trace_filter, trace block only to highest matching index#4974
update trace_filter, trace block only to highest matching index#4974mattsse merged 22 commits intoparadigmxyz:mainfrom
Conversation
mattsse
left a comment
There was a problem hiding this comment.
that's a great start.
I have some nits,
the biggest improvement would still be to only trace the block until the highest index, for that we'd need a new function that is similar to:
https://github.com/paradigmxyz/reth/blob/main/crates/rpc/rpc/src/trace.rs#L363-L369
pub only traces the block until a given transaction,
we can unify some code by moving this loop to a standalone function so it can be reused:
crates/rpc/rpc/src/trace.rs
Outdated
| if idx > highest_matching_index { | ||
| highest_matching_index = idx; | ||
| } |
There was a problem hiding this comment.
this check is redundant because all tx_idx are only increasing
crates/rpc/rpc/src/trace.rs
Outdated
| if idx > highest_idx { | ||
| return Ok(None); | ||
| } |
There was a problem hiding this comment.
this is a smol improvement, however this still traces the entire block,
https://github.com/paradigmxyz/reth/blob/main/crates/rpc/rpc/src/trace.rs#L353-L362
crates/rpc/rpc/src/trace.rs
Outdated
| let mut block_traces = Vec::with_capacity(target_blocks.len()); | ||
| for (num, indices) in target_blocks { | ||
| for (num, indices, highest_idx) in target_blocks { | ||
| let traces = self.trace_block_with( |
There was a problem hiding this comment.
there's something else we need to do here:
skipping blocks with empty indices entirely
|
i wanted to localize this code in one place, instead of defining it twice, once for each function/ so i defined it like this at the top of the file but i think that's still pretty redundant. I'm not that familiar with rust, it's why I wanna become a contributor to this project, to learn rust. is there a more idiomatic way to do that^? |
crates/rpc/rpc/src/trace.rs
Outdated
| // Check if current index exceeds the highest_index and break if it does | ||
| if let Some(highest) = highest_index { | ||
| if idx as u64 > highest { | ||
| break; | ||
| } | ||
| } |
There was a problem hiding this comment.
I'd like to move this to transactions.into_iter().take() instead
crates/rpc/rpc/src/trace.rs
Outdated
| .into_localized_transaction_traces(tx_info); | ||
| Ok(Some(traces)) | ||
| }, | ||
| Some(highest_idx), |
There was a problem hiding this comment.
this argument should be moved and should be the second argument, so that the closure is always the last argument
Codecov Report
... and 65 files with indirect coverage changes
Flags with carried forward coverage won't be shown. Click here to find out more.
|
crates/rpc/rpc/src/trace.rs
Outdated
| let mut db = CacheDB::new(StateProviderDatabase::new(state)); | ||
|
|
||
| let mut transactions = transactions.into_iter().enumerate().peekable(); | ||
| let max_transactions = highest_index.map_or(transactions.len(), |highest| highest as usize + 1); |
There was a problem hiding this comment.
this looks wrong, we should not need +1
| // need to apply the state changes of this transaction before executing the | ||
| // next transaction | ||
| if transactions.peek().is_some() { | ||
| // need to apply the state changes of this transaction before executing | ||
| // the next transaction | ||
| db.commit(state) | ||
| } |
crates/rpc/rpc/src/trace.rs
Outdated
| trait TransactionCallback<R> | ||
| where | ||
| Self: for<'a> Fn( | ||
| TransactionInfo, | ||
| TracingInspector, | ||
| ExecutionResult, | ||
| &'a State, | ||
| &'a CacheDB<StateProviderDatabase<StateProviderBox<'a>>>, | ||
| ) -> EthResult<R> | ||
| + Send | ||
| + 'static, | ||
| { | ||
| } | ||
|
|
||
| impl<F, R> TransactionCallback<R> for F where | ||
| F: for<'a> Fn( | ||
| TransactionInfo, | ||
| TracingInspector, | ||
| ExecutionResult, | ||
| &'a State, | ||
| &'a CacheDB<StateProviderDatabase<StateProviderBox<'a>>>, | ||
| ) -> EthResult<R> | ||
| + Send | ||
| + 'static | ||
| { | ||
| } |
There was a problem hiding this comment.
I don't really like this because this is just a hack to make signatures nicer and not really needed
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This PR aims to address the following TODO:
This is my first contribution to
reth, I've read through the CONTRIBUTING.md doc and executed all the specified checks. If there's anything I've overlooked or missed please let me know and I'll be happy to address it.