diff --git a/ethcore/src/executive.rs b/ethcore/src/executive.rs index 9a48f9d4a..9d5a8acf7 100644 --- a/ethcore/src/executive.rs +++ b/ethcore/src/executive.rs @@ -99,11 +99,11 @@ impl<'a> Executive<'a> { let check = options.check_nonce; match options.tracing { true => match options.vm_tracing { - true => self.transact_with_tracer(t, check, ExecutiveTracer::default(), ExecutiveVMTracer::default()), + true => self.transact_with_tracer(t, check, ExecutiveTracer::default(), ExecutiveVMTracer::toplevel()), false => self.transact_with_tracer(t, check, ExecutiveTracer::default(), NoopVMTracer), }, false => match options.vm_tracing { - true => self.transact_with_tracer(t, check, NoopTracer, ExecutiveVMTracer::default()), + true => self.transact_with_tracer(t, check, NoopTracer, ExecutiveVMTracer::toplevel()), false => self.transact_with_tracer(t, check, NoopTracer, NoopVMTracer), }, } diff --git a/ethcore/src/trace/executive_tracer.rs b/ethcore/src/trace/executive_tracer.rs index a64664095..5c2e158e9 100644 --- a/ethcore/src/trace/executive_tracer.rs +++ b/ethcore/src/trace/executive_tracer.rs @@ -160,11 +160,24 @@ impl Tracer for ExecutiveTracer { } /// Simple VM tracer. Traces all operations. -#[derive(Default)] pub struct ExecutiveVMTracer { data: VMTrace, } +impl ExecutiveVMTracer { + /// Create a new top-level instance. + pub fn toplevel() -> Self { + ExecutiveVMTracer { + data: VMTrace { + parent_step: 0, + code: vec![], + operations: vec![Default::default()], // prefill with a single entry so that prepare_subtrace can get the parent_step + subs: vec![], + } + } + } +} + impl VMTracer for ExecutiveVMTracer { fn trace_prepare_execute(&mut self, pc: usize, instruction: u8, gas_cost: &U256) -> bool { self.data.operations.push(VMOperation { @@ -188,7 +201,7 @@ impl VMTracer for ExecutiveVMTracer { fn prepare_subtrace(&self, code: &[u8]) -> Self { ExecutiveVMTracer { data: VMTrace { - parent_step: self.data.operations.len(), + parent_step: self.data.operations.len() - 1, // won't overflow since we must already have pushed an operation in trace_prepare_execute. code: code.to_vec(), operations: vec![], subs: vec![], diff --git a/ethcore/src/types/trace_types/trace.rs b/ethcore/src/types/trace_types/trace.rs index 346b99c06..8d251032c 100644 --- a/ethcore/src/types/trace_types/trace.rs +++ b/ethcore/src/types/trace_types/trace.rs @@ -473,7 +473,7 @@ impl Decodable for VMExecutedOperation { } } -#[derive(Debug, Clone, PartialEq, Binary)] +#[derive(Debug, Clone, PartialEq, Binary, Default)] /// A record of the execution of a single VM operation. pub struct VMOperation { /// The program counter.