trace result is a structure;
This commit is contained in:
parent
5685fde606
commit
09beeaba8e
@ -258,7 +258,7 @@ impl<'a> Executive<'a> {
|
||||
}
|
||||
} else {
|
||||
// if destination is a contract, do normal message call
|
||||
|
||||
|
||||
// don't trace if it's DELEGATECALL or CALLCODE.
|
||||
let should_trace = if let ActionValue::Transfer(_) = params.value {
|
||||
params.code_address == params.address && substate.subtraces.is_some()
|
||||
@ -281,7 +281,10 @@ 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 {
|
||||
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, trace_output.expect("trace_info is Some: so should_trace: qed")));
|
||||
c.result = res.as_ref().ok().map(|gas_left| TraceCallResult {
|
||||
gas_used: c.gas - *gas_left,
|
||||
output: trace_output.expect("trace_info is Some: qed")
|
||||
});
|
||||
}
|
||||
|
||||
trace!(target: "executive", "substate={:?}; unconfirmed_substate={:?}\n", substate, unconfirmed_substate);
|
||||
@ -294,7 +297,7 @@ impl<'a> Executive<'a> {
|
||||
trace!(target: "executive", "Basic message (send funds) should_trace={}", should_trace);
|
||||
self.state.clear_snapshot();
|
||||
if let Some((TraceAction::Call(ref mut c), _)) = trace_info {
|
||||
c.result = Some((x!(0), vec![]));
|
||||
c.result = Some(TraceCallResult::default());// Some((x!(0), vec![]));
|
||||
}
|
||||
substate.accrue_trace(if should_trace {Some(vec![])} else {None}, trace_info);
|
||||
Ok(params.gas)
|
||||
@ -330,7 +333,11 @@ impl<'a> Executive<'a> {
|
||||
};
|
||||
|
||||
if let Some((TraceAction::Create(ref mut c), _)) = trace_info {
|
||||
c.result = res.as_ref().ok().map(|gas_left| (c.gas - *gas_left, created, trace_output.expect("trace_info is Some: qed")));
|
||||
c.result = res.as_ref().ok().map(|gas_left| TraceCreateResult {
|
||||
gas_used: c.gas - *gas_left,
|
||||
address: created,
|
||||
code: trace_output.expect("trace_info is Some: qed")
|
||||
});
|
||||
}
|
||||
|
||||
trace!(target: "executive", "trace_info={:?}", trace_info);
|
||||
@ -583,7 +590,10 @@ mod tests {
|
||||
value: x!(100),
|
||||
gas: x!(100000),
|
||||
input: vec![],
|
||||
result: Some((x!(55248), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(55_248),
|
||||
output: vec![],
|
||||
})
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 1,
|
||||
@ -592,7 +602,11 @@ mod tests {
|
||||
value: x!(23),
|
||||
gas: x!(67979),
|
||||
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
|
||||
result: Some((x!(3224), x!("c6d80f262ae5e0f164e5fde365044d7ada2bfa34"), vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53])),
|
||||
result: Some(TraceCreateResult {
|
||||
gas_used: U256::from(3224),
|
||||
address: Address::from_str("c6d80f262ae5e0f164e5fde365044d7ada2bfa34").unwrap(),
|
||||
code: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
}]
|
||||
@ -646,7 +660,11 @@ mod tests {
|
||||
value: x!(100),
|
||||
gas: params.gas,
|
||||
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
|
||||
result: Some((x!(3224), params.address, vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53])),
|
||||
result: Some(TraceCreateResult {
|
||||
gas_used: U256::from(3224),
|
||||
address: params.address,
|
||||
code: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
} ]);
|
||||
|
@ -398,7 +398,11 @@ fn should_apply_create_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(77412),
|
||||
init: vec![96, 16, 128, 96, 12, 96, 0, 57, 96, 0, 243, 0, 96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53, 85],
|
||||
result: Some((x!(3224), x!("8988167e088c87cd314df6d3c2b83da5acb93ace"), vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53]))
|
||||
result: Some(TraceCreateResult {
|
||||
gas_used: U256::from(3224),
|
||||
address: Address::from_str("8988167e088c87cd314df6d3c2b83da5acb93ace").unwrap(),
|
||||
code: vec![96, 0, 53, 84, 21, 96, 9, 87, 0, 91, 96, 32, 53, 96, 0, 53]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -493,7 +497,10 @@ fn should_trace_call_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(3), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(3),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -531,7 +538,10 @@ fn should_trace_basic_call_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(0), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(0),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -595,7 +605,10 @@ fn should_not_trace_subcall_transaction_to_builtin() {
|
||||
value: x!(0),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(28061), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(28_061),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -634,7 +647,10 @@ fn should_not_trace_callcode() {
|
||||
value: x!(0),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(64), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(64),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -676,7 +692,10 @@ fn should_not_trace_delegatecall() {
|
||||
value: x!(0),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(61), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(61),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -756,7 +775,10 @@ fn should_trace_call_with_subcall_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(69), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(69),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 1,
|
||||
@ -766,7 +788,10 @@ fn should_trace_call_with_subcall_transaction() {
|
||||
value: x!(0),
|
||||
gas: x!(78934),
|
||||
input: vec![],
|
||||
result: Some((x!(3), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(3),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
}]
|
||||
@ -806,7 +831,10 @@ fn should_trace_call_with_basic_subcall_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(31761), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(31761),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 1,
|
||||
@ -816,7 +844,7 @@ fn should_trace_call_with_basic_subcall_transaction() {
|
||||
value: x!(69),
|
||||
gas: x!(2300),
|
||||
input: vec![],
|
||||
result: Some((x!(0), vec![]))
|
||||
result: Some(TraceCallResult::default())
|
||||
}),
|
||||
subs: vec![]
|
||||
}]
|
||||
@ -856,7 +884,10 @@ fn should_not_trace_call_with_invalid_basic_subcall_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(31761), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(31761),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
});
|
||||
@ -896,7 +927,12 @@ fn should_trace_failed_subcall_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(79000), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(79_000),
|
||||
output: vec![]
|
||||
})
|
||||
|
||||
// Some((x!(79000), vec![]))
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 1,
|
||||
@ -948,7 +984,10 @@ fn should_trace_call_with_subcall_with_subcall_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(135), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(135),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 1,
|
||||
@ -958,7 +997,10 @@ fn should_trace_call_with_subcall_with_subcall_transaction() {
|
||||
value: x!(0),
|
||||
gas: x!(78934),
|
||||
input: vec![],
|
||||
result: Some((x!(69), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(69),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 2,
|
||||
@ -968,7 +1010,10 @@ fn should_trace_call_with_subcall_with_subcall_transaction() {
|
||||
value: x!(0),
|
||||
gas: x!(78868),
|
||||
input: vec![],
|
||||
result: Some((x!(3), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(3),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
}]
|
||||
@ -1011,7 +1056,10 @@ fn should_trace_failed_subcall_with_subcall_transaction() {
|
||||
value: x!(100),
|
||||
gas: x!(79000),
|
||||
input: vec![],
|
||||
result: Some((x!(79000), vec![]))
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(79_000),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![Trace {
|
||||
depth: 1,
|
||||
@ -1031,7 +1079,10 @@ fn should_trace_failed_subcall_with_subcall_transaction() {
|
||||
value: x!(0),
|
||||
gas: x!(78868),
|
||||
input: vec![],
|
||||
result: Some((x!(3), vec![])),
|
||||
result: Some(TraceCallResult {
|
||||
gas_used: U256::from(3),
|
||||
output: vec![]
|
||||
})
|
||||
}),
|
||||
subs: vec![]
|
||||
}]
|
||||
|
21
ethcore/src/trace/mod.rs
Normal file
21
ethcore/src/trace/mod.rs
Normal file
@ -0,0 +1,21 @@
|
||||
// Copyright 2015, 2016 Ethcore (UK) Ltd.
|
||||
// This file is part of Parity.
|
||||
|
||||
// Parity is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// Parity is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! Tracing
|
||||
|
||||
mod trace;
|
||||
|
||||
pub use self::trace::*;
|
@ -17,6 +17,26 @@
|
||||
//! Tracing datatypes.
|
||||
use common::*;
|
||||
|
||||
/// TraceCall result.
|
||||
#[derive(Debug, Clone, PartialEq, Default)]
|
||||
pub struct TraceCallResult {
|
||||
/// Gas used by call.
|
||||
pub gas_used: U256,
|
||||
/// Call Output.
|
||||
pub output: Bytes,
|
||||
}
|
||||
|
||||
/// TraceCreate result.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TraceCreateResult {
|
||||
/// Gas used by create.
|
||||
pub gas_used: U256,
|
||||
/// Code of the newly created contract.
|
||||
pub code: Bytes,
|
||||
/// Address of the newly created contract.
|
||||
pub address: Address,
|
||||
}
|
||||
|
||||
/// Description of a _call_ action, either a `CALL` operation or a message transction.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub struct TraceCall {
|
||||
@ -31,7 +51,7 @@ pub struct TraceCall {
|
||||
/// The input data provided to the call.
|
||||
pub input: Bytes,
|
||||
/// The result of the operation; the gas used and the output data of the call.
|
||||
pub result: Option<(U256, Bytes)>,
|
||||
pub result: Option<TraceCallResult>,
|
||||
}
|
||||
|
||||
/// Description of a _create_ action, either a `CREATE` operation or a create transction.
|
||||
@ -47,15 +67,12 @@ pub struct TraceCreate {
|
||||
pub init: Bytes,
|
||||
/// The result of the operation; tuple of the gas used, the address of the newly created account and its code.
|
||||
/// NOTE: Presently failed operations are not reported so this will always be `Some`.
|
||||
pub result: Option<(U256, Address, Bytes)>,
|
||||
// pub output: Bytes,
|
||||
pub result: Option<TraceCreateResult>,
|
||||
}
|
||||
|
||||
/// Description of an action that we trace; will be either a call or a create.
|
||||
#[derive(Debug, Clone, PartialEq)]
|
||||
pub enum TraceAction {
|
||||
/// Action isn't yet known.
|
||||
Unknown,
|
||||
/// It's a call action.
|
||||
Call(TraceCall),
|
||||
/// It's a create action.
|
||||
@ -74,16 +91,6 @@ pub struct Trace {
|
||||
pub subs: Vec<Trace>,
|
||||
}
|
||||
|
||||
impl Default for Trace {
|
||||
fn default() -> Trace {
|
||||
Trace {
|
||||
depth: 0,
|
||||
action: TraceAction::Unknown,
|
||||
subs: vec![],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl TraceAction {
|
||||
/// Compose a `TraceAction` from an `ActionParams`, knowing that the action is a call.
|
||||
pub fn from_call(p: &ActionParams) -> TraceAction {
|
Loading…
Reference in New Issue
Block a user