Create VMTracer trait.

This commit is contained in:
Gav Wood 2016-05-28 17:50:20 +02:00
parent c1ed520de0
commit d4a06b27ed
4 changed files with 27 additions and 19 deletions

View File

@ -40,8 +40,7 @@ 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>, delegate_call: bool) {
fn trace_call(&mut self, call: Option<Call>, gas_used: U256, output: Option<Bytes>, depth: usize, subs: Vec<Trace>, delegate_call: bool) {
// don't trace if it's DELEGATECALL or CALLCODE.
if delegate_call {
return;

View File

@ -81,13 +81,25 @@ pub trait Tracer: Send {
/// Stores failed create trace.
fn trace_failed_create(&mut self, create: Option<Create>, depth: usize, subs: Vec<Trace>);
/// Spawn subracer which will be used to trace deeper levels of execution.
/// 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>;
}
/// Used by executive to build VM traces.
pub trait VMTracer: Send {
/// Trace the preparation to execute a single instruction.
fn trace_prepare_execute(pc: usize, instruction: u8, gas_cost: &U256, stack: &Vec<U256>);
/// Spawn subtracer which will be used to trace deeper levels of execution.
fn subtracer(&self) -> Self where Self: Sized;
/// Consumes self and returns all VM traces.
fn traces(self) -> Vec<VMTrace>;
}
/// `DbExtras` provides an interface to query extra data which is not stored in tracesdb,
/// but necessary to work correctly.
pub trait DatabaseExtras {

View File

@ -349,6 +349,17 @@ impl Trace {
}
}
/*pub struct VMExecutedOperation {
/// The total gas used.
pub gas_used: U256,
/// Altered storage value.
pub storage_diff: Option<(U256, U256)>,
/// If altered, the new memory image.
pub new_memory: Option<Bytes>,
}*/
/// Information concerning the execution of the operation.
// pub executed: Option<VMExecutedOperation>,
#[derive(Debug, Clone, PartialEq, Binary)]
/// A record of the execution of a single VM operation.
pub struct VMOperation {
@ -358,26 +369,17 @@ pub struct VMOperation {
pub instruction: u8,
/// The gas cost for this instruction.
pub gas_cost: U256,
/// The total gas used.
pub gas_used: U256,
/// The stack.
pub stack: Vec<U256>,
/// Altered storage value. TODO: should be option.
// pub storage_diff: Option<(U256, U256)>,
/// If altered, the new memory image.
pub new_memory: Bytes,
}
impl Encodable for VMOperation {
fn rlp_append(&self, s: &mut RlpStream) {
s.begin_list(6);
s.begin_list(4);
s.append(&self.pc);
s.append(&self.instruction);
s.append(&self.gas_cost);
s.append(&self.gas_used);
s.append(&self.stack);
// s.append(&self.storage_diff);
s.append(&self.new_memory);
}
}
@ -388,10 +390,7 @@ impl Decodable for VMOperation {
pc: try!(d.val_at(0)),
instruction: try!(d.val_at(1)),
gas_cost: try!(d.val_at(2)),
gas_used: try!(d.val_at(3)),
stack: try!(d.val_at(4)),
// storage_diff: try!(d.val_at(5)),
new_memory: try!(d.val_at(6)),
stack: try!(d.val_at(3)),
};
Ok(res)

View File

@ -157,8 +157,6 @@ impl<C, M> Ethcore for EthcoreClient<C, M> where C: BlockChainClient + 'static,
to_value(&Bytes::new(version))
}
//pub type VMTraceFunctionBox = Box<FnMut(usize, u8, U256, U256) + Send>;
fn vm_trace_call(&self, params: Params) -> Result<Value, Error> {
trace!(target: "jsonrpc", "vm_trace_call: {:?}", params);
from_params(params)