2019-01-07 11:33:07 +01:00
|
|
|
// Copyright 2015-2019 Parity Technologies (UK) Ltd.
|
|
|
|
// This file is part of Parity Ethereum.
|
2016-04-06 21:23:52 +02:00
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is free software: you can redistribute it and/or modify
|
2016-04-06 21:23:52 +02:00
|
|
|
// 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.
|
|
|
|
|
2019-01-07 11:33:07 +01:00
|
|
|
// Parity Ethereum is distributed in the hope that it will be useful,
|
2016-04-06 21:23:52 +02:00
|
|
|
// 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
|
2019-01-07 11:33:07 +01:00
|
|
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
2016-04-06 21:23:52 +02:00
|
|
|
|
|
|
|
//! Tracing
|
|
|
|
|
2019-07-08 18:17:48 +02:00
|
|
|
use ethereum_types::{U256, Address};
|
|
|
|
use kvdb::DBTransaction;
|
|
|
|
use vm::{Error as VmError, ActionParams};
|
|
|
|
// The MallocSizeOf derive looks for this in the root
|
|
|
|
use parity_util_mem as malloc_size_of;
|
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
mod config;
|
|
|
|
mod db;
|
|
|
|
mod executive_tracer;
|
|
|
|
mod import;
|
|
|
|
mod noop_tracer;
|
2017-07-12 13:09:17 +02:00
|
|
|
mod types;
|
2016-04-30 17:41:24 +02:00
|
|
|
|
2019-07-08 18:17:48 +02:00
|
|
|
pub use crate::{
|
|
|
|
config::Config,
|
2019-07-14 18:35:43 +02:00
|
|
|
db::{TraceDB, DatabaseExtras},
|
2019-07-08 18:17:48 +02:00
|
|
|
localized::LocalizedTrace,
|
|
|
|
executive_tracer::{ExecutiveTracer, ExecutiveVMTracer},
|
|
|
|
import::ImportRequest,
|
|
|
|
noop_tracer::{NoopTracer, NoopVMTracer},
|
|
|
|
types::{
|
|
|
|
Tracing,
|
|
|
|
error::Error as TraceError,
|
|
|
|
localized,
|
|
|
|
trace::{self, VMTrace, VMOperation, VMExecutedOperation, MemoryDiff, StorageDiff, RewardType},
|
|
|
|
flat::{self, FlatTrace, FlatTransactionTraces, FlatBlockTraces},
|
|
|
|
filter::{self, Filter, AddressesFilter},
|
|
|
|
}
|
|
|
|
};
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2019-07-14 18:35:43 +02:00
|
|
|
/// Type for block number.
|
|
|
|
pub(crate) type BlockNumber = u64;
|
|
|
|
|
2016-04-08 01:50:55 +02:00
|
|
|
/// This trait is used by executive to build traces.
|
|
|
|
pub trait Tracer: Send {
|
2017-10-20 15:40:25 +02:00
|
|
|
/// Data returned when draining the Tracer.
|
|
|
|
type Output;
|
|
|
|
|
2018-10-02 16:33:19 +02:00
|
|
|
/// Prepares call trace for given params. Would panic if prepare/done_trace are not balanced.
|
|
|
|
fn prepare_trace_call(&mut self, params: &ActionParams, depth: usize, is_builtin: bool);
|
|
|
|
|
|
|
|
/// Prepares create trace for given params. Would panic if prepare/done_trace are not balanced.
|
|
|
|
fn prepare_trace_create(&mut self, params: &ActionParams);
|
|
|
|
|
|
|
|
/// Finishes a successful call trace. Would panic if prepare/done_trace are not balanced.
|
|
|
|
fn done_trace_call(&mut self, gas_used: U256, output: &[u8]);
|
|
|
|
|
|
|
|
/// Finishes a successful create trace. Would panic if prepare/done_trace are not balanced.
|
|
|
|
fn done_trace_create(&mut self, gas_used: U256, code: &[u8], address: Address);
|
|
|
|
|
|
|
|
/// Finishes a failed trace. Would panic if prepare/done_trace are not balanced.
|
|
|
|
fn done_trace_failed(&mut self, error: &VmError);
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2016-07-22 14:47:23 +02:00
|
|
|
/// Stores suicide info.
|
2016-07-28 20:31:29 +02:00
|
|
|
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address);
|
2016-07-22 14:47:23 +02:00
|
|
|
|
2017-07-18 12:14:06 +02:00
|
|
|
/// Stores reward info.
|
2017-07-31 12:06:38 +02:00
|
|
|
fn trace_reward(&mut self, author: Address, value: U256, reward_type: RewardType);
|
2017-07-18 12:14:06 +02:00
|
|
|
|
2016-04-08 01:50:55 +02:00
|
|
|
/// Consumes self and returns all traces.
|
2017-10-20 15:40:25 +02:00
|
|
|
fn drain(self) -> Vec<Self::Output>;
|
2016-04-08 01:50:55 +02:00
|
|
|
}
|
|
|
|
|
2016-06-02 12:40:31 +02:00
|
|
|
/// Used by executive to build VM traces.
|
|
|
|
pub trait VMTracer: Send {
|
|
|
|
|
2017-10-20 15:40:25 +02:00
|
|
|
/// Data returned when draining the VMTracer.
|
|
|
|
type Output;
|
|
|
|
|
2017-07-10 13:23:40 +02:00
|
|
|
/// Trace the progression of interpreter to next instruction.
|
|
|
|
/// If tracer returns `false` it won't be called again.
|
|
|
|
/// @returns true if `trace_prepare_execute` and `trace_executed` should be called.
|
2018-01-18 10:32:22 +01:00
|
|
|
fn trace_next_instruction(&mut self, _pc: usize, _instruction: u8, _current_gas: U256) -> bool { false }
|
2017-07-10 13:23:40 +02:00
|
|
|
|
|
|
|
/// Trace the preparation to execute a single valid instruction.
|
2018-10-02 16:33:19 +02:00
|
|
|
fn trace_prepare_execute(&mut self, _pc: usize, _instruction: u8, _gas_cost: U256, _mem_written: Option<(usize, usize)>, _store_written: Option<(U256, U256)>) {}
|
2017-07-10 13:23:40 +02:00
|
|
|
|
2019-09-05 16:11:51 +02:00
|
|
|
/// Trace the execution failure of a single instruction.
|
|
|
|
fn trace_failed(&mut self) {}
|
|
|
|
|
2017-07-10 13:23:40 +02:00
|
|
|
/// Trace the finalised execution of a single valid instruction.
|
2018-10-02 16:33:19 +02:00
|
|
|
fn trace_executed(&mut self, _gas_used: U256, _stack_push: &[U256], _mem: &[u8]) {}
|
2016-06-02 12:40:31 +02:00
|
|
|
|
|
|
|
/// Spawn subtracer which will be used to trace deeper levels of execution.
|
2018-10-02 16:33:19 +02:00
|
|
|
fn prepare_subtrace(&mut self, _code: &[u8]) {}
|
2016-06-02 12:40:31 +02:00
|
|
|
|
2017-05-26 11:06:48 +02:00
|
|
|
/// Finalize subtracer.
|
2018-10-02 16:33:19 +02:00
|
|
|
fn done_subtrace(&mut self) {}
|
2016-06-02 12:40:31 +02:00
|
|
|
|
|
|
|
/// Consumes self and returns the VM trace.
|
2017-10-20 15:40:25 +02:00
|
|
|
fn drain(self) -> Option<Self::Output>;
|
2018-11-25 20:12:59 +01:00
|
|
|
|
2016-06-02 12:40:31 +02:00
|
|
|
}
|
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
/// Db provides an interface to query tracesdb.
|
|
|
|
pub trait Database {
|
|
|
|
/// Returns true if tracing is enabled. Otherwise false.
|
|
|
|
fn tracing_enabled(&self) -> bool;
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
/// Imports new block traces.
|
2016-08-25 16:43:56 +02:00
|
|
|
fn import(&self, batch: &mut DBTransaction, request: ImportRequest);
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
/// Returns localized trace at given position.
|
|
|
|
fn trace(&self, block_number: BlockNumber, tx_position: usize, trace_position: Vec<usize>) -> Option<LocalizedTrace>;
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
/// Returns localized traces created by a single transaction.
|
|
|
|
fn transaction_traces(&self, block_number: BlockNumber, tx_position: usize) -> Option<Vec<LocalizedTrace>>;
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
/// Returns localized traces created in given block.
|
|
|
|
fn block_traces(&self, block_number: BlockNumber) -> Option<Vec<LocalizedTrace>>;
|
2016-04-08 01:50:55 +02:00
|
|
|
|
2016-04-30 17:41:24 +02:00
|
|
|
/// Filter traces matching given filter.
|
|
|
|
fn filter(&self, filter: &Filter) -> Vec<LocalizedTrace>;
|
2016-04-08 01:50:55 +02:00
|
|
|
}
|