Stackoverflow fix (#1742)
* executive tracer builds flat traces without intermediate struct * temporarilt commented out tests for traces * fixed new way of building trace address * fixed new way of building trace address * updating state tests with flat tracing in progress * fixed flat tracing tests * fixed compiling ethcore-rpc with new flat traces * removed warnings from ethcore module * remove unused data structures
This commit is contained in:
@@ -1,58 +0,0 @@
|
||||
// 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/>.
|
||||
|
||||
use util::rlp::*;
|
||||
use basic_types::LogBloom;
|
||||
use super::Trace;
|
||||
|
||||
/// Traces created by transactions from the same block.
|
||||
#[derive(Clone)]
|
||||
pub struct BlockTraces(Vec<Trace>);
|
||||
|
||||
impl From<Vec<Trace>> for BlockTraces {
|
||||
fn from(traces: Vec<Trace>) -> Self {
|
||||
BlockTraces(traces)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<Trace>> for BlockTraces {
|
||||
fn into(self) -> Vec<Trace> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for BlockTraces {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let traces = try!(Decodable::decode(decoder));
|
||||
let block_traces = BlockTraces(traces);
|
||||
Ok(block_traces)
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for BlockTraces {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
Encodable::rlp_append(&self.0, s)
|
||||
}
|
||||
}
|
||||
|
||||
impl BlockTraces {
|
||||
/// Returns bloom of all traces in given block.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
self.0.iter()
|
||||
.fold(LogBloom::default(), |acc, trace| acc | trace.bloom())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ impl<T> TraceDB<T> where T: DatabaseExtras {
|
||||
action: trace.action,
|
||||
result: trace.result,
|
||||
subtraces: trace.subtraces,
|
||||
trace_address: trace.trace_address,
|
||||
trace_address: trace.trace_address.into_iter().collect(),
|
||||
transaction_number: tx_number,
|
||||
transaction_hash: tx_hash.clone(),
|
||||
block_number: block_number,
|
||||
@@ -230,7 +230,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
let mut traces = self.traces.write();
|
||||
// it's important to use overwrite here,
|
||||
// cause this value might be queried by hash later
|
||||
batch.write_with_cache(traces.deref_mut(), request.block_hash, request.traces.into(), CacheUpdatePolicy::Overwrite);
|
||||
batch.write_with_cache(traces.deref_mut(), request.block_hash, request.traces, CacheUpdatePolicy::Overwrite);
|
||||
}
|
||||
|
||||
// now let's rebuild the blooms
|
||||
@@ -263,12 +263,13 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
}
|
||||
|
||||
fn trace(&self, block_number: BlockNumber, tx_position: usize, trace_position: Vec<usize>) -> Option<LocalizedTrace> {
|
||||
let trace_position_deq = trace_position.into_iter().collect();
|
||||
self.extras.block_hash(block_number)
|
||||
.and_then(|block_hash| self.transactions_traces(&block_hash)
|
||||
.and_then(|traces| traces.into_iter().nth(tx_position))
|
||||
.map(Into::<Vec<FlatTrace>>::into)
|
||||
// this may and should be optimized
|
||||
.and_then(|traces| traces.into_iter().find(|trace| trace.trace_address == trace_position))
|
||||
.and_then(|traces| traces.into_iter().find(|trace| trace.trace_address == trace_position_deq))
|
||||
.map(|trace| {
|
||||
let tx_hash = self.extras.transaction_hash(block_number, tx_position)
|
||||
.expect("Expected to find transaction hash. Database is probably corrupted");
|
||||
@@ -277,7 +278,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
action: trace.action,
|
||||
result: trace.result,
|
||||
subtraces: trace.subtraces,
|
||||
trace_address: trace.trace_address,
|
||||
trace_address: trace.trace_address.into_iter().collect(),
|
||||
transaction_number: tx_position,
|
||||
transaction_hash: tx_hash,
|
||||
block_number: block_number,
|
||||
@@ -301,7 +302,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
action: trace.action,
|
||||
result: trace.result,
|
||||
subtraces: trace.subtraces,
|
||||
trace_address: trace.trace_address,
|
||||
trace_address: trace.trace_address.into_iter().collect(),
|
||||
transaction_number: tx_position,
|
||||
transaction_hash: tx_hash.clone(),
|
||||
block_number: block_number,
|
||||
@@ -328,7 +329,7 @@ impl<T> TraceDatabase for TraceDB<T> where T: DatabaseExtras {
|
||||
action: trace.action,
|
||||
result: trace.result,
|
||||
subtraces: trace.subtraces,
|
||||
trace_address: trace.trace_address,
|
||||
trace_address: trace.trace_address.into_iter().collect(),
|
||||
transaction_number: tx_position,
|
||||
transaction_hash: tx_hash.clone(),
|
||||
block_number: block_number,
|
||||
@@ -365,8 +366,9 @@ mod tests {
|
||||
use devtools::RandomTempPath;
|
||||
use header::BlockNumber;
|
||||
use trace::{Config, Switch, TraceDB, Database, DatabaseExtras, ImportRequest};
|
||||
use trace::{BlockTraces, Trace, Filter, LocalizedTrace, AddressesFilter};
|
||||
use trace::{Filter, LocalizedTrace, AddressesFilter};
|
||||
use trace::trace::{Call, Action, Res};
|
||||
use trace::flat::{FlatTrace, FlatBlockTraces, FlatTransactionTraces};
|
||||
use types::executed::CallType;
|
||||
|
||||
struct NoopExtras;
|
||||
@@ -485,19 +487,19 @@ mod tests {
|
||||
|
||||
fn create_simple_import_request(block_number: BlockNumber, block_hash: H256) -> ImportRequest {
|
||||
ImportRequest {
|
||||
traces: BlockTraces::from(vec![Trace {
|
||||
depth: 0,
|
||||
traces: FlatBlockTraces::from(vec![FlatTransactionTraces::from(vec![FlatTrace {
|
||||
trace_address: Default::default(),
|
||||
subtraces: 0,
|
||||
action: Action::Call(Call {
|
||||
from: Address::from(1),
|
||||
to: Address::from(2),
|
||||
value: U256::from(3),
|
||||
gas: U256::from(4),
|
||||
from: 1.into(),
|
||||
to: 2.into(),
|
||||
value: 3.into(),
|
||||
gas: 4.into(),
|
||||
input: vec![],
|
||||
call_type: CallType::Call,
|
||||
}),
|
||||
result: Res::FailedCall,
|
||||
subs: vec![],
|
||||
}]),
|
||||
}])]),
|
||||
block_hash: block_hash.clone(),
|
||||
block_number: block_number,
|
||||
enacted: vec![block_hash],
|
||||
|
||||
@@ -18,13 +18,53 @@
|
||||
|
||||
use util::{Bytes, Address, U256};
|
||||
use action_params::ActionParams;
|
||||
use trace::trace::{Trace, Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide};
|
||||
use trace::{Tracer, VMTracer};
|
||||
use trace::trace::{Call, Create, Action, Res, CreateResult, CallResult, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, Suicide};
|
||||
use trace::{Tracer, VMTracer, FlatTrace};
|
||||
|
||||
/// Simple executive tracer. Traces all calls and creates. Ignores delegatecalls.
|
||||
#[derive(Default)]
|
||||
pub struct ExecutiveTracer {
|
||||
traces: Vec<Trace>,
|
||||
traces: Vec<FlatTrace>,
|
||||
}
|
||||
|
||||
fn top_level_subtraces(traces: &[FlatTrace]) -> usize {
|
||||
traces.iter().filter(|t| t.trace_address.is_empty()).count()
|
||||
}
|
||||
|
||||
fn update_trace_address(traces: Vec<FlatTrace>) -> Vec<FlatTrace> {
|
||||
// input traces are expected to be ordered like
|
||||
// []
|
||||
// [0]
|
||||
// [0, 0]
|
||||
// [0, 1]
|
||||
// []
|
||||
// [0]
|
||||
//
|
||||
// so they can be transformed to
|
||||
//
|
||||
// [0]
|
||||
// [0, 0]
|
||||
// [0, 0, 0]
|
||||
// [0, 0, 1]
|
||||
// [1]
|
||||
// [1, 0]
|
||||
let mut top_subtrace_index = 0;
|
||||
let mut subtrace_subtraces_left = 0;
|
||||
traces.into_iter().map(|mut trace| {
|
||||
let is_top_subtrace = trace.trace_address.is_empty();
|
||||
trace.trace_address.push_front(top_subtrace_index);
|
||||
|
||||
if is_top_subtrace {
|
||||
subtrace_subtraces_left = trace.subtraces;
|
||||
} else {
|
||||
subtrace_subtraces_left -= 1;
|
||||
}
|
||||
|
||||
if subtrace_subtraces_left == 0 {
|
||||
top_subtrace_index += 1;
|
||||
}
|
||||
trace
|
||||
}).collect()
|
||||
}
|
||||
|
||||
impl Tracer for ExecutiveTracer {
|
||||
@@ -40,67 +80,71 @@ impl Tracer for ExecutiveTracer {
|
||||
Some(vec![])
|
||||
}
|
||||
|
||||
fn trace_call(&mut self, call: Option<Call>, gas_used: U256, output: Option<Bytes>, depth: usize, subs: Vec<Trace>) {
|
||||
let trace = Trace {
|
||||
depth: depth,
|
||||
subs: subs,
|
||||
fn trace_call(&mut self, call: Option<Call>, gas_used: U256, output: Option<Bytes>, subs: Vec<FlatTrace>) {
|
||||
let trace = FlatTrace {
|
||||
trace_address: Default::default(),
|
||||
subtraces: top_level_subtraces(&subs),
|
||||
action: Action::Call(call.expect("self.prepare_trace_call().is_some(): so we must be tracing: qed")),
|
||||
result: Res::Call(CallResult {
|
||||
gas_used: gas_used,
|
||||
output: output.expect("self.prepare_trace_output().is_some(): so we must be tracing: qed")
|
||||
})
|
||||
}),
|
||||
};
|
||||
debug!(target: "trace", "Traced call {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
self.traces.extend(update_trace_address(subs));
|
||||
}
|
||||
|
||||
fn trace_create(&mut self, create: Option<Create>, gas_used: U256, code: Option<Bytes>, address: Address, depth: usize, subs: Vec<Trace>) {
|
||||
let trace = Trace {
|
||||
depth: depth,
|
||||
subs: subs,
|
||||
fn trace_create(&mut self, create: Option<Create>, gas_used: U256, code: Option<Bytes>, address: Address, subs: Vec<FlatTrace>) {
|
||||
let trace = FlatTrace {
|
||||
subtraces: top_level_subtraces(&subs),
|
||||
action: Action::Create(create.expect("self.prepare_trace_create().is_some(): so we must be tracing: qed")),
|
||||
result: Res::Create(CreateResult {
|
||||
gas_used: gas_used,
|
||||
code: code.expect("self.prepare_trace_output.is_some(): so we must be tracing: qed"),
|
||||
address: address
|
||||
})
|
||||
}),
|
||||
trace_address: Default::default(),
|
||||
};
|
||||
debug!(target: "trace", "Traced create {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
self.traces.extend(update_trace_address(subs));
|
||||
}
|
||||
|
||||
fn trace_failed_call(&mut self, call: Option<Call>, depth: usize, subs: Vec<Trace>) {
|
||||
let trace = Trace {
|
||||
depth: depth,
|
||||
subs: subs,
|
||||
fn trace_failed_call(&mut self, call: Option<Call>, subs: Vec<FlatTrace>) {
|
||||
let trace = FlatTrace {
|
||||
trace_address: Default::default(),
|
||||
subtraces: top_level_subtraces(&subs),
|
||||
action: Action::Call(call.expect("self.prepare_trace_call().is_some(): so we must be tracing: qed")),
|
||||
result: Res::FailedCall,
|
||||
};
|
||||
debug!(target: "trace", "Traced failed call {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
self.traces.extend(update_trace_address(subs));
|
||||
}
|
||||
|
||||
fn trace_failed_create(&mut self, create: Option<Create>, depth: usize, subs: Vec<Trace>) {
|
||||
let trace = Trace {
|
||||
depth: depth,
|
||||
subs: subs,
|
||||
fn trace_failed_create(&mut self, create: Option<Create>, subs: Vec<FlatTrace>) {
|
||||
let trace = FlatTrace {
|
||||
subtraces: top_level_subtraces(&subs),
|
||||
action: Action::Create(create.expect("self.prepare_trace_create().is_some(): so we must be tracing: qed")),
|
||||
result: Res::FailedCreate,
|
||||
trace_address: Default::default(),
|
||||
};
|
||||
debug!(target: "trace", "Traced failed create {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
self.traces.extend(update_trace_address(subs));
|
||||
}
|
||||
|
||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address, depth: usize) {
|
||||
let trace = Trace {
|
||||
depth: depth,
|
||||
subs: vec![],
|
||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address) {
|
||||
let trace = FlatTrace {
|
||||
subtraces: 0,
|
||||
action: Action::Suicide(Suicide {
|
||||
address: address,
|
||||
refund_address: refund_address,
|
||||
balance: balance,
|
||||
}),
|
||||
result: Res::None,
|
||||
trace_address: Default::default(),
|
||||
};
|
||||
debug!(target: "trace", "Traced failed suicide {:?}", trace);
|
||||
self.traces.push(trace);
|
||||
@@ -110,7 +154,7 @@ impl Tracer for ExecutiveTracer {
|
||||
ExecutiveTracer::default()
|
||||
}
|
||||
|
||||
fn traces(self) -> Vec<Trace> {
|
||||
fn traces(self) -> Vec<FlatTrace> {
|
||||
self.traces
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,287 +0,0 @@
|
||||
// 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/>.
|
||||
|
||||
//! Flat trace module
|
||||
|
||||
use util::rlp::*;
|
||||
use trace::BlockTraces;
|
||||
use basic_types::LogBloom;
|
||||
use super::trace::{Trace, Action, Res};
|
||||
|
||||
/// Trace localized in vector of traces produced by a single transaction.
|
||||
///
|
||||
/// Parent and children indexes refer to positions in this vector.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct FlatTrace {
|
||||
/// Type of action performed by a transaction.
|
||||
pub action: Action,
|
||||
/// Result of this action.
|
||||
pub result: Res,
|
||||
/// Number of subtraces.
|
||||
pub subtraces: usize,
|
||||
/// Exact location of trace.
|
||||
///
|
||||
/// [index in root, index in first CALL, index in second CALL, ...]
|
||||
pub trace_address: Vec<usize>,
|
||||
}
|
||||
|
||||
impl FlatTrace {
|
||||
/// Returns bloom of the trace.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
self.action.bloom() | self.result.bloom()
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for FlatTrace {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.begin_list(4);
|
||||
s.append(&self.action);
|
||||
s.append(&self.result);
|
||||
s.append(&self.subtraces);
|
||||
s.append(&self.trace_address);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for FlatTrace {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
let d = decoder.as_rlp();
|
||||
let res = FlatTrace {
|
||||
action: try!(d.val_at(0)),
|
||||
result: try!(d.val_at(1)),
|
||||
subtraces: try!(d.val_at(2)),
|
||||
trace_address: try!(d.val_at(3)),
|
||||
};
|
||||
|
||||
Ok(res)
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents all traces produced by a single transaction.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct FlatTransactionTraces(Vec<FlatTrace>);
|
||||
|
||||
impl FlatTransactionTraces {
|
||||
/// Returns bloom of all traces in the collection.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
self.0.iter().fold(Default::default(), | bloom, trace | bloom | trace.bloom())
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for FlatTransactionTraces {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.append(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for FlatTransactionTraces {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
Ok(FlatTransactionTraces(try!(Decodable::decode(decoder))))
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<FlatTrace>> for FlatTransactionTraces {
|
||||
fn into(self) -> Vec<FlatTrace> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
/// Represents all traces produced by transactions in a single block.
|
||||
#[derive(Debug, PartialEq, Clone)]
|
||||
pub struct FlatBlockTraces(Vec<FlatTransactionTraces>);
|
||||
|
||||
impl FlatBlockTraces {
|
||||
/// Returns bloom of all traces in the block.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
self.0.iter().fold(Default::default(), | bloom, tx_traces | bloom | tx_traces.bloom())
|
||||
}
|
||||
}
|
||||
|
||||
impl Encodable for FlatBlockTraces {
|
||||
fn rlp_append(&self, s: &mut RlpStream) {
|
||||
s.append(&self.0);
|
||||
}
|
||||
}
|
||||
|
||||
impl Decodable for FlatBlockTraces {
|
||||
fn decode<D>(decoder: &D) -> Result<Self, DecoderError> where D: Decoder {
|
||||
Ok(FlatBlockTraces(try!(Decodable::decode(decoder))))
|
||||
}
|
||||
}
|
||||
|
||||
impl From<BlockTraces> for FlatBlockTraces {
|
||||
fn from(block_traces: BlockTraces) -> Self {
|
||||
let traces: Vec<Trace> = block_traces.into();
|
||||
let ordered = traces.into_iter()
|
||||
.map(|trace| FlatBlockTraces::flatten(vec![], trace))
|
||||
.map(FlatTransactionTraces)
|
||||
.collect();
|
||||
FlatBlockTraces(ordered)
|
||||
}
|
||||
}
|
||||
|
||||
impl Into<Vec<FlatTransactionTraces>> for FlatBlockTraces {
|
||||
fn into(self) -> Vec<FlatTransactionTraces> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl FlatBlockTraces {
|
||||
/// Helper function flattening nested tree structure to vector of ordered traces.
|
||||
fn flatten(address: Vec<usize>, trace: Trace) -> Vec<FlatTrace> {
|
||||
let subtraces = trace.subs.len();
|
||||
let all_subs = trace.subs
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.flat_map(|(index, subtrace)| {
|
||||
let mut subtrace_address = address.clone();
|
||||
subtrace_address.push(index);
|
||||
FlatBlockTraces::flatten(subtrace_address, subtrace)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let ordered = FlatTrace {
|
||||
action: trace.action,
|
||||
result: trace.result,
|
||||
subtraces: subtraces,
|
||||
trace_address: address,
|
||||
};
|
||||
|
||||
let mut result = vec![ordered];
|
||||
result.extend(all_subs);
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{FlatBlockTraces, FlatTransactionTraces, FlatTrace};
|
||||
use util::{U256, Address};
|
||||
use trace::trace::{Action, Res, CallResult, Call, Create, Trace};
|
||||
use trace::BlockTraces;
|
||||
use types::executed::CallType;
|
||||
|
||||
#[test]
|
||||
fn test_block_from() {
|
||||
let trace = Trace {
|
||||
depth: 2,
|
||||
action: Action::Call(Call {
|
||||
from: Address::from(1),
|
||||
to: Address::from(2),
|
||||
value: U256::from(3),
|
||||
gas: U256::from(4),
|
||||
input: vec![0x5],
|
||||
call_type: CallType::Call,
|
||||
}),
|
||||
subs: vec![
|
||||
Trace {
|
||||
depth: 3,
|
||||
action: Action::Create(Create {
|
||||
from: Address::from(6),
|
||||
value: U256::from(7),
|
||||
gas: U256::from(8),
|
||||
init: vec![0x9]
|
||||
}),
|
||||
subs: vec![
|
||||
Trace {
|
||||
depth: 3,
|
||||
action: Action::Create(Create {
|
||||
from: Address::from(6),
|
||||
value: U256::from(7),
|
||||
gas: U256::from(8),
|
||||
init: vec![0x9]
|
||||
}),
|
||||
subs: vec![
|
||||
],
|
||||
result: Res::FailedCreate
|
||||
},
|
||||
Trace {
|
||||
depth: 3,
|
||||
action: Action::Create(Create {
|
||||
from: Address::from(6),
|
||||
value: U256::from(7),
|
||||
gas: U256::from(8),
|
||||
init: vec![0x9]
|
||||
}),
|
||||
subs: vec![
|
||||
],
|
||||
result: Res::FailedCreate
|
||||
}
|
||||
],
|
||||
result: Res::FailedCreate
|
||||
},
|
||||
Trace {
|
||||
depth: 3,
|
||||
action: Action::Create(Create {
|
||||
from: Address::from(6),
|
||||
value: U256::from(7),
|
||||
gas: U256::from(8),
|
||||
init: vec![0x9]
|
||||
}),
|
||||
subs: vec![],
|
||||
result: Res::FailedCreate,
|
||||
}
|
||||
],
|
||||
result: Res::Call(CallResult {
|
||||
gas_used: U256::from(10),
|
||||
output: vec![0x11, 0x12]
|
||||
})
|
||||
};
|
||||
|
||||
let block_traces = FlatBlockTraces::from(BlockTraces::from(vec![trace]));
|
||||
let transaction_traces: Vec<FlatTransactionTraces> = block_traces.into();
|
||||
assert_eq!(transaction_traces.len(), 1);
|
||||
let ordered_traces: Vec<FlatTrace> = transaction_traces.into_iter().nth(0).unwrap().into();
|
||||
assert_eq!(ordered_traces.len(), 5);
|
||||
assert_eq!(ordered_traces[0].trace_address, vec![]);
|
||||
assert_eq!(ordered_traces[0].subtraces, 2);
|
||||
assert_eq!(ordered_traces[1].trace_address, vec![0]);
|
||||
assert_eq!(ordered_traces[1].subtraces, 2);
|
||||
assert_eq!(ordered_traces[2].trace_address, vec![0, 0]);
|
||||
assert_eq!(ordered_traces[2].subtraces, 0);
|
||||
assert_eq!(ordered_traces[3].trace_address, vec![0, 1]);
|
||||
assert_eq!(ordered_traces[3].subtraces, 0);
|
||||
assert_eq!(ordered_traces[4].trace_address, vec![1]);
|
||||
assert_eq!(ordered_traces[4].subtraces, 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trace_serialization() {
|
||||
use util::rlp;
|
||||
|
||||
let flat_trace = FlatTrace {
|
||||
action: Action::Call(Call {
|
||||
from: 1.into(),
|
||||
to: 2.into(),
|
||||
value: 3.into(),
|
||||
gas: 4.into(),
|
||||
input: vec![0x5],
|
||||
call_type: CallType::Call,
|
||||
}),
|
||||
result: Res::Call(CallResult {
|
||||
gas_used: 10.into(),
|
||||
output: vec![0x11, 0x12]
|
||||
}),
|
||||
trace_address: Vec::new(),
|
||||
subtraces: 0,
|
||||
};
|
||||
|
||||
let block_traces = FlatBlockTraces(vec![FlatTransactionTraces(vec![flat_trace])]);
|
||||
|
||||
let encoded = rlp::encode(&block_traces);
|
||||
let decoded = rlp::decode(&encoded);
|
||||
assert_eq!(block_traces, decoded);
|
||||
}
|
||||
}
|
||||
@@ -17,12 +17,12 @@
|
||||
//! Traces import request.
|
||||
use util::H256;
|
||||
use header::BlockNumber;
|
||||
use trace::BlockTraces;
|
||||
use trace::FlatBlockTraces;
|
||||
|
||||
/// Traces import request.
|
||||
pub struct ImportRequest {
|
||||
/// Traces to import.
|
||||
pub traces: BlockTraces,
|
||||
pub traces: FlatBlockTraces,
|
||||
/// Hash of traces block.
|
||||
pub block_hash: H256,
|
||||
/// Number of traces block.
|
||||
|
||||
@@ -16,22 +16,20 @@
|
||||
|
||||
//! Tracing
|
||||
|
||||
mod block;
|
||||
mod bloom;
|
||||
mod config;
|
||||
mod db;
|
||||
mod error;
|
||||
mod executive_tracer;
|
||||
pub mod flat;
|
||||
mod import;
|
||||
mod noop_tracer;
|
||||
|
||||
pub use types::trace_types::*;
|
||||
pub use self::block::BlockTraces;
|
||||
pub use self::config::{Config, Switch};
|
||||
pub use self::db::TraceDB;
|
||||
pub use self::error::Error;
|
||||
pub use types::trace_types::trace::{Trace, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff};
|
||||
pub use types::trace_types::trace::{VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff};
|
||||
pub use types::trace_types::flat::{FlatTrace, FlatTransactionTraces, FlatBlockTraces};
|
||||
pub use self::noop_tracer::{NoopTracer, NoopVMTracer};
|
||||
pub use self::executive_tracer::{ExecutiveTracer, ExecutiveVMTracer};
|
||||
pub use types::trace_types::filter::{Filter, AddressesFilter};
|
||||
@@ -59,8 +57,7 @@ pub trait Tracer: Send {
|
||||
call: Option<Call>,
|
||||
gas_used: U256,
|
||||
output: Option<Bytes>,
|
||||
depth: usize,
|
||||
subs: Vec<Trace>
|
||||
subs: Vec<FlatTrace>,
|
||||
);
|
||||
|
||||
/// Stores trace create info.
|
||||
@@ -70,24 +67,23 @@ pub trait Tracer: Send {
|
||||
gas_used: U256,
|
||||
code: Option<Bytes>,
|
||||
address: Address,
|
||||
depth: usize,
|
||||
subs: Vec<Trace>
|
||||
subs: Vec<FlatTrace>
|
||||
);
|
||||
|
||||
/// Stores failed call trace.
|
||||
fn trace_failed_call(&mut self, call: Option<Call>, depth: usize, subs: Vec<Trace>);
|
||||
fn trace_failed_call(&mut self, call: Option<Call>, subs: Vec<FlatTrace>);
|
||||
|
||||
/// Stores failed create trace.
|
||||
fn trace_failed_create(&mut self, create: Option<Create>, depth: usize, subs: Vec<Trace>);
|
||||
fn trace_failed_create(&mut self, create: Option<Create>, subs: Vec<FlatTrace>);
|
||||
|
||||
/// Stores suicide info.
|
||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address, depth: usize);
|
||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address);
|
||||
|
||||
/// Spawn subtracer which will be used to trace deeper levels of execution.
|
||||
fn subtracer(&self) -> Self where Self: Sized;
|
||||
|
||||
/// Consumes self and returns all traces.
|
||||
fn traces(self) -> Vec<Trace>;
|
||||
fn traces(self) -> Vec<FlatTrace>;
|
||||
}
|
||||
|
||||
/// Used by executive to build VM traces.
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
|
||||
use util::{Bytes, Address, U256};
|
||||
use action_params::ActionParams;
|
||||
use trace::{Tracer, VMTracer};
|
||||
use trace::trace::{Trace, Call, Create, VMTrace};
|
||||
use trace::{Tracer, VMTracer, FlatTrace};
|
||||
use trace::trace::{Call, Create, VMTrace};
|
||||
|
||||
/// Nonoperative tracer. Does not trace anything.
|
||||
pub struct NoopTracer;
|
||||
@@ -37,32 +37,32 @@ impl Tracer for NoopTracer {
|
||||
None
|
||||
}
|
||||
|
||||
fn trace_call(&mut self, call: Option<Call>, _: U256, output: Option<Bytes>, _: usize, _: Vec<Trace>) {
|
||||
fn trace_call(&mut self, call: Option<Call>, _: U256, output: Option<Bytes>, _: Vec<FlatTrace>) {
|
||||
assert!(call.is_none(), "self.prepare_trace_call().is_none(): so we can't be tracing: qed");
|
||||
assert!(output.is_none(), "self.prepare_trace_output().is_none(): so we can't be tracing: qed");
|
||||
}
|
||||
|
||||
fn trace_create(&mut self, create: Option<Create>, _: U256, code: Option<Bytes>, _: Address, _: usize, _: Vec<Trace>) {
|
||||
fn trace_create(&mut self, create: Option<Create>, _: U256, code: Option<Bytes>, _: Address, _: Vec<FlatTrace>) {
|
||||
assert!(create.is_none(), "self.prepare_trace_create().is_none(): so we can't be tracing: qed");
|
||||
assert!(code.is_none(), "self.prepare_trace_output().is_none(): so we can't be tracing: qed");
|
||||
}
|
||||
|
||||
fn trace_failed_call(&mut self, call: Option<Call>, _: usize, _: Vec<Trace>) {
|
||||
fn trace_failed_call(&mut self, call: Option<Call>, _: Vec<FlatTrace>) {
|
||||
assert!(call.is_none(), "self.prepare_trace_call().is_none(): so we can't be tracing: qed");
|
||||
}
|
||||
|
||||
fn trace_failed_create(&mut self, create: Option<Create>, _: usize, _: Vec<Trace>) {
|
||||
fn trace_failed_create(&mut self, create: Option<Create>, _: Vec<FlatTrace>) {
|
||||
assert!(create.is_none(), "self.prepare_trace_create().is_none(): so we can't be tracing: qed");
|
||||
}
|
||||
|
||||
fn trace_suicide(&mut self, _address: Address, _balance: U256, _refund_address: Address, _depth: usize) {
|
||||
fn trace_suicide(&mut self, _address: Address, _balance: U256, _refund_address: Address) {
|
||||
}
|
||||
|
||||
fn subtracer(&self) -> Self {
|
||||
NoopTracer
|
||||
}
|
||||
|
||||
fn traces(self) -> Vec<Trace> {
|
||||
fn traces(self) -> Vec<FlatTrace> {
|
||||
vec![]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user