fix(rpc): fix parity tracing config (#3549)

This commit is contained in:
Matthias Seitz
2023-07-03 15:21:17 +02:00
committed by GitHub
parent 228f6479b0
commit d848668fb2
2 changed files with 42 additions and 3 deletions

View File

@ -103,6 +103,16 @@ impl TracingInspectorConfig {
self
}
/// Configure whether the tracer should record steps and state diffs.
///
/// This is a convenience method for setting both [TracingInspectorConfig::set_steps] and
/// [TracingInspectorConfig::set_state_diffs] since tracking state diffs requires steps tracing.
pub fn set_steps_and_state_diffs(mut self, steps_and_diffs: bool) -> Self {
self.record_steps = steps_and_diffs;
self.record_state_diff = steps_and_diffs;
self
}
/// Configure whether the tracer should record logs
pub fn set_record_logs(mut self, record_logs: bool) -> Self {
self.record_logs = record_logs;

View File

@ -615,10 +615,12 @@ struct TraceApiInner<Provider, Eth> {
}
/// Returns the [TracingInspectorConfig] depending on the enabled [TraceType]s
#[inline]
fn tracing_config(trace_types: &HashSet<TraceType>) -> TracingInspectorConfig {
TracingInspectorConfig::default_parity()
.set_state_diffs(trace_types.contains(&TraceType::StateDiff))
.set_steps(trace_types.contains(&TraceType::VmTrace))
let needs_diff = trace_types.contains(&TraceType::StateDiff);
let needs_vm_trace = trace_types.contains(&TraceType::VmTrace);
let needs_steps = needs_vm_trace || needs_diff;
TracingInspectorConfig::default_parity().set_steps(needs_steps).set_state_diffs(needs_diff)
}
/// Helper to construct a [`LocalizedTransactionTrace`] that describes a reward to the block
@ -637,3 +639,30 @@ fn reward_trace(header: &SealedHeader, reward: RewardAction) -> LocalizedTransac
},
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_parity_config() {
let mut s = HashSet::new();
s.insert(TraceType::StateDiff);
let config = tracing_config(&s);
assert!(config.record_steps);
assert!(config.record_state_diff);
let mut s = HashSet::new();
s.insert(TraceType::VmTrace);
let config = tracing_config(&s);
assert!(config.record_steps);
assert!(!config.record_state_diff);
let mut s = HashSet::new();
s.insert(TraceType::VmTrace);
s.insert(TraceType::StateDiff);
let config = tracing_config(&s);
assert!(config.record_steps);
assert!(config.record_state_diff);
}
}