-
Notifications
You must be signed in to change notification settings - Fork 346
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
chore: Enhance Call Tracer Performance and Code Reliability #3125
Open
crStiv
wants to merge
2
commits into
moonbeam-foundation:master
Choose a base branch
from
crStiv:call-tracer
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -37,10 +37,15 @@ impl super::ResponseFormatter for Formatter { | |||||||
type Response = Vec<BlockTransactionTrace>; | ||||||||
|
||||||||
fn format(mut listener: Listener) -> Option<Vec<BlockTransactionTrace>> { | ||||||||
// Remove empty BTreeMaps pushed to `entries`. | ||||||||
// I.e. InvalidNonce or other pallet_evm::runner exits | ||||||||
// Skip empty transactions early to avoid unnecessary processing | ||||||||
if listener.entries.is_empty() { | ||||||||
return None; | ||||||||
} | ||||||||
|
||||||||
// Remove empty BTreeMaps | ||||||||
listener.entries.retain(|x| !x.is_empty()); | ||||||||
let mut traces = Vec::new(); | ||||||||
|
||||||||
let mut traces = Vec::with_capacity(listener.entries.len()); | ||||||||
for (eth_tx_index, entry) in listener.entries.iter().enumerate() { | ||||||||
let mut result: Vec<Call> = entry | ||||||||
.into_iter() | ||||||||
|
@@ -169,28 +174,8 @@ impl super::ResponseFormatter for Formatter { | |||||||
trace_address: Some(b), | ||||||||
.. | ||||||||
}), | ||||||||
) => { | ||||||||
let a_len = a.len(); | ||||||||
let b_len = b.len(); | ||||||||
let sibling_greater_than = |a: &Vec<u32>, b: &Vec<u32>| -> bool { | ||||||||
for (i, a_value) in a.iter().enumerate() { | ||||||||
if a_value > &b[i] { | ||||||||
return true; | ||||||||
} else if a_value < &b[i] { | ||||||||
return false; | ||||||||
} else { | ||||||||
continue; | ||||||||
} | ||||||||
} | ||||||||
return false; | ||||||||
}; | ||||||||
if b_len > a_len || (a_len == b_len && sibling_greater_than(&a, &b)) { | ||||||||
Ordering::Less | ||||||||
} else { | ||||||||
Ordering::Greater | ||||||||
} | ||||||||
} | ||||||||
_ => unreachable!(), | ||||||||
) => compare_trace_address(a, b), | ||||||||
_ => unreachable!("All calls should have trace addresses"), | ||||||||
}); | ||||||||
// Stack pop-and-push. | ||||||||
while result.len() > 1 { | ||||||||
|
@@ -279,6 +264,7 @@ pub struct CallTracerCall { | |||||||
pub inner: CallTracerInner, | ||||||||
|
||||||||
#[serde(skip_serializing_if = "Vec::is_empty")] | ||||||||
#[serde(default)] | ||||||||
pub calls: Vec<Call>, | ||||||||
} | ||||||||
|
||||||||
|
@@ -296,6 +282,7 @@ pub enum CallTracerInner { | |||||||
res: CallResult, | ||||||||
|
||||||||
#[serde(skip_serializing_if = "Option::is_none")] | ||||||||
#[serde(default)] | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
value: Option<U256>, | ||||||||
|
||||||||
#[serde(skip_serializing_if = "Vec::is_empty")] | ||||||||
|
@@ -327,3 +314,20 @@ pub enum CallTracerInner { | |||||||
value: U256, | ||||||||
}, | ||||||||
} | ||||||||
|
||||||||
fn compare_trace_address(a: &[u32], b: &[u32]) -> Ordering { | ||||||||
let a_len = a.len(); | ||||||||
let b_len = b.len(); | ||||||||
|
||||||||
if b_len != a_len { | ||||||||
return a_len.cmp(&b_len); | ||||||||
} | ||||||||
|
||||||||
for (a_value, b_value) in a.iter().zip(b.iter()) { | ||||||||
match a_value.cmp(b_value) { | ||||||||
Ordering::Equal => continue, | ||||||||
other => return other, | ||||||||
} | ||||||||
} | ||||||||
Ordering::Equal | ||||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.