Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge pull request #791 from ethcore/tracing
Browse files Browse the repository at this point in the history
Comprehensive tests for tracing transactions
  • Loading branch information
arkpar committed Mar 20, 2016
2 parents dcb23de + c2933e0 commit 8a5aa35
Show file tree
Hide file tree
Showing 5 changed files with 492 additions and 31 deletions.
12 changes: 6 additions & 6 deletions ethcore/src/evm/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use evm::Evm;
/// Type of EVM to use.
pub enum VMType {
/// JIT EVM
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
Jit,
/// RUST EVM
Interpreter
Expand All @@ -52,26 +52,26 @@ impl fmt::Display for VMType {
#[cfg(feature = "json-tests")]
impl VMType {
/// Return all possible VMs (JIT, Interpreter)
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
pub fn all() -> Vec<VMType> {
vec![VMType::Jit, VMType::Interpreter]
}

/// Return all possible VMs (Interpreter)
#[cfg(not(feature="jit"))]
#[cfg(not(feature = "jit"))]
pub fn all() -> Vec<VMType> {
vec![VMType::Interpreter]
}
}

/// Evm factory. Creates appropriate Evm.
pub struct Factory {
evm : VMType
evm: VMType
}

impl Factory {
/// Create fresh instance of VM
#[cfg(feature="jit")]
#[cfg(feature = "jit")]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Jit => {
Expand All @@ -84,7 +84,7 @@ impl Factory {
}

/// Create fresh instance of VM
#[cfg(not(feature="jit"))]
#[cfg(not(feature = "jit"))]
pub fn create(&self) -> Box<Evm> {
match self.evm {
VMType::Interpreter => {
Expand Down
23 changes: 12 additions & 11 deletions ethcore/src/executive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,16 +261,14 @@ impl<'a> Executive<'a> {

// if there's tracing, make up trace_info's result with trace_output and some arithmetic.
if let Some((TraceAction::Call(ref mut c), _)) = trace_info {
if let Some(output) = trace_output {
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, output));
}
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, trace_output.expect("trace_info is Some: qed")));
}

trace!("exec: sstore-clears={}\n", unconfirmed_substate.sstore_clears_count);
trace!("exec: substate={:?}; unconfirmed_substate={:?}\n", substate, unconfirmed_substate);
trace!(target: "executive", "sstore-clears={}\n", unconfirmed_substate.sstore_clears_count);
trace!(target: "executive", "substate={:?}; unconfirmed_substate={:?}\n", substate, unconfirmed_substate);

self.enact_result(&res, substate, unconfirmed_substate, trace_info);
trace!("exec: new substate={:?}\n", substate);
trace!(target: "executive", "enacted: substate={:?}\n", substate);
res
} else {
// otherwise, nothing
Expand Down Expand Up @@ -307,11 +305,11 @@ impl<'a> Executive<'a> {
};

if let Some((TraceAction::Create(ref mut c), _)) = trace_info {
if let Some(output) = trace_output {
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created, output));
}
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created, trace_output.expect("trace_info is Some: qed")));
}

trace!(target: "executive", "trace_info={:?}", trace_info);

self.enact_result(&res, substate, unconfirmed_substate, trace_info);
res
}
Expand Down Expand Up @@ -348,6 +346,8 @@ impl<'a> Executive<'a> {
self.state.kill_account(address);
}

let trace = substate.subtraces.and_then(|mut v| v.pop());

match result {
Err(evm::Error::Internal) => Err(ExecutionError::Internal),
Err(_) => {
Expand All @@ -359,7 +359,7 @@ impl<'a> Executive<'a> {
logs: vec![],
contracts_created: vec![],
output: output,
trace: None,
trace: trace,
})
},
_ => {
Expand All @@ -371,7 +371,7 @@ impl<'a> Executive<'a> {
logs: substate.logs,
contracts_created: substate.contracts_created,
output: output,
trace: substate.subtraces.and_then(|mut v| v.pop()),
trace: trace,
})
},
}
Expand All @@ -385,6 +385,7 @@ impl<'a> Executive<'a> {
| Err(evm::Error::StackUnderflow {..})
| Err(evm::Error::OutOfStack {..}) => {
self.state.revert_snapshot();
substate.accrue_trace(un_substate.subtraces, maybe_info)
},
Ok(_) | Err(evm::Error::Internal) => {
self.state.clear_snapshot();
Expand Down
16 changes: 9 additions & 7 deletions ethcore/src/externalities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,13 +153,15 @@ impl<'a> Ext for Externalities<'a> {
}

fn call(&mut self,
gas: &U256,
sender_address: &Address,
receive_address: &Address,
value: Option<U256>,
data: &[u8],
code_address: &Address,
output: &mut [u8]) -> MessageCallResult {
gas: &U256,
sender_address: &Address,
receive_address: &Address,
value: Option<U256>,
data: &[u8],
code_address: &Address,
output: &mut [u8]
) -> MessageCallResult {
trace!(target: "externalities", "call");

let mut params = ActionParams {
sender: sender_address.clone(),
Expand Down

0 comments on commit 8a5aa35

Please sign in to comment.