-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
update trace_filter, trace block only to highest matching index #4974
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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:
https://github.com/paradigmxyz/reth/blob/main/crates/rpc/rpc/src/trace.rs#L408-L408
crates/rpc/rpc/src/trace.rs
Outdated
if idx > highest_matching_index { | ||
highest_matching_index = idx; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
// trace all relevant blocks | ||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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^? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, almost there
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to move this to transactions.into_iter().take()
instead
crates/rpc/rpc/src/trace.rs
Outdated
@@ -310,6 +338,7 @@ where | |||
.into_localized_transaction_traces(tx_info); | |||
Ok(Some(traces)) | |||
}, | |||
Some(highest_idx), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
@@ -436,15 +436,10 @@ where | |||
let mut results = Vec::with_capacity(transactions.len()); | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks wrong, we should not need +1
crates/rpc/rpc/src/trace.rs
Outdated
// 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) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still need this
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like this because this is just a hack to make signatures nicer and not really needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice, lgtm
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.