Modification of traces moved to engines
This commit is contained in:
parent
01a02a8985
commit
30434325a2
@ -107,7 +107,7 @@ pub struct BlockRefMut<'a> {
|
|||||||
/// State.
|
/// State.
|
||||||
pub state: &'a mut State<StateDB>,
|
pub state: &'a mut State<StateDB>,
|
||||||
/// Traces.
|
/// Traces.
|
||||||
pub traces: &'a Option<Vec<Vec<FlatTrace>>>,
|
pub traces: &'a mut Option<Vec<Vec<FlatTrace>>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A set of immutable references to `ExecutedBlock` fields that are publicly accessible.
|
/// A set of immutable references to `ExecutedBlock` fields that are publicly accessible.
|
||||||
@ -148,7 +148,7 @@ impl ExecutedBlock {
|
|||||||
uncles: &self.uncles,
|
uncles: &self.uncles,
|
||||||
state: &mut self.state,
|
state: &mut self.state,
|
||||||
receipts: &self.receipts,
|
receipts: &self.receipts,
|
||||||
traces: &self.traces,
|
traces: &mut self.traces,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -395,11 +395,8 @@ impl<'x> OpenBlock<'x> {
|
|||||||
|
|
||||||
let unclosed_state = s.block.state.clone();
|
let unclosed_state = s.block.state.clone();
|
||||||
|
|
||||||
match s.engine.on_close_block(&mut s.block) {
|
if let Err(e) = s.engine.on_close_block(&mut s.block) {
|
||||||
Ok(outcome) => if let Some(t) = outcome.trace {
|
warn!("Encountered error on closing the block: {}", e);
|
||||||
s.block.traces.as_mut().map(|traces| traces.push(t));
|
|
||||||
},
|
|
||||||
Err(e) => warn!("Encountered error on closing the block: {}", e),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = s.block.state.commit() {
|
if let Err(e) = s.block.state.commit() {
|
||||||
@ -425,14 +422,8 @@ impl<'x> OpenBlock<'x> {
|
|||||||
pub fn close_and_lock(self) -> LockedBlock {
|
pub fn close_and_lock(self) -> LockedBlock {
|
||||||
let mut s = self;
|
let mut s = self;
|
||||||
|
|
||||||
match s.engine.on_close_block(&mut s.block) {
|
if let Err(e) = s.engine.on_close_block(&mut s.block) {
|
||||||
Ok(outcome) => match outcome.trace {
|
warn!("Encountered error on closing the block: {}", e);
|
||||||
Some(t) => {
|
|
||||||
s.block.traces.as_mut().map(|traces| traces.push(t));
|
|
||||||
},
|
|
||||||
None => {},
|
|
||||||
},
|
|
||||||
Err(e) => warn!("Encountered error on closing the block: {}", e),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Err(e) = s.block.state.commit() {
|
if let Err(e) = s.block.state.commit() {
|
||||||
|
@ -26,7 +26,7 @@ use account_provider::AccountProvider;
|
|||||||
use block::*;
|
use block::*;
|
||||||
use builtin::Builtin;
|
use builtin::Builtin;
|
||||||
use client::{Client, EngineClient};
|
use client::{Client, EngineClient};
|
||||||
use engines::{Call, Engine, Seal, EngineError, ConstructedVerifier, CloseOutcome};
|
use engines::{Call, Engine, Seal, EngineError, ConstructedVerifier};
|
||||||
use trace::{Tracer, ExecutiveTracer, RewardType};
|
use trace::{Tracer, ExecutiveTracer, RewardType};
|
||||||
use error::{Error, TransactionError, BlockError};
|
use error::{Error, TransactionError, BlockError};
|
||||||
use ethjson;
|
use ethjson;
|
||||||
@ -546,7 +546,7 @@ impl Engine for AuthorityRound {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<CloseOutcome, Error> {
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
let tracing_enabled = block.tracing_enabled();
|
let tracing_enabled = block.tracing_enabled();
|
||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
let mut tracer = ExecutiveTracer::default();
|
let mut tracer = ExecutiveTracer::default();
|
||||||
@ -559,19 +559,14 @@ impl Engine for AuthorityRound {
|
|||||||
if tracing_enabled {
|
if tracing_enabled {
|
||||||
let block_author = fields.header.author().clone();
|
let block_author = fields.header.author().clone();
|
||||||
tracer.trace_reward(block_author, self.params().block_reward, RewardType::Block);
|
tracer.trace_reward(block_author, self.params().block_reward, RewardType::Block);
|
||||||
|
fields.traces.as_mut().map(|mut traces| traces.push(tracer.traces()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
if let Err(ref e) = res {
|
if let Err(ref e) = res {
|
||||||
warn!("Encountered error on closing block: {}", e);
|
warn!("Encountered error on closing block: {}", e);
|
||||||
}
|
}
|
||||||
match res {
|
res
|
||||||
Ok(_) => match tracing_enabled {
|
|
||||||
true => Ok(CloseOutcome { trace: Some(tracer.traces()) } ),
|
|
||||||
false => Ok(CloseOutcome { trace: None } )
|
|
||||||
},
|
|
||||||
Err(e) => Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Check the number of seal fields.
|
/// Check the number of seal fields.
|
||||||
|
@ -49,7 +49,6 @@ use vm::{EnvInfo, LastHashes, Schedule, CreateContractAddress};
|
|||||||
use error::Error;
|
use error::Error;
|
||||||
use header::{Header, BlockNumber};
|
use header::{Header, BlockNumber};
|
||||||
use receipt::Receipt;
|
use receipt::Receipt;
|
||||||
use trace::FlatTrace;
|
|
||||||
use snapshot::SnapshotComponents;
|
use snapshot::SnapshotComponents;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use transaction::{UnverifiedTransaction, SignedTransaction};
|
use transaction::{UnverifiedTransaction, SignedTransaction};
|
||||||
@ -82,13 +81,6 @@ pub enum EngineError {
|
|||||||
RequiresClient,
|
RequiresClient,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Used to return information about close block operation.
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub struct CloseOutcome {
|
|
||||||
/// The trace for the closing block, if None if tracing is disabled.
|
|
||||||
pub trace: Option<Vec<FlatTrace>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl fmt::Display for EngineError {
|
impl fmt::Display for EngineError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use self::EngineError::*;
|
use self::EngineError::*;
|
||||||
@ -236,8 +228,8 @@ pub trait Engine : Sync + Send {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Block transformation functions, after the transactions.
|
/// Block transformation functions, after the transactions.
|
||||||
fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<CloseOutcome, Error> {
|
fn on_close_block(&self, _block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
Ok(CloseOutcome{trace: None})
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// None means that it requires external input (e.g. PoW) to seal a block.
|
/// None means that it requires external input (e.g. PoW) to seal a block.
|
||||||
|
@ -19,7 +19,7 @@ use util::Address;
|
|||||||
use builtin::Builtin;
|
use builtin::Builtin;
|
||||||
use block::{ExecutedBlock, IsBlock};
|
use block::{ExecutedBlock, IsBlock};
|
||||||
use util::U256;
|
use util::U256;
|
||||||
use engines::{Engine, CloseOutcome};
|
use engines::Engine;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
use header::BlockNumber;
|
use header::BlockNumber;
|
||||||
@ -70,9 +70,9 @@ impl Engine for NullEngine {
|
|||||||
Some(Box::new(::snapshot::PowSnapshot(10000)))
|
Some(Box::new(::snapshot::PowSnapshot(10000)))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<CloseOutcome, Error> {
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
if self.params.block_reward == U256::zero() {
|
if self.params.block_reward == U256::zero() {
|
||||||
return Ok(CloseOutcome{trace: None});
|
return Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Block reward
|
/// Block reward
|
||||||
@ -105,9 +105,9 @@ impl Engine for NullEngine {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fields.state.commit()?;
|
fields.state.commit()?;
|
||||||
match tracing_enabled {
|
if tracing_enabled {
|
||||||
true => Ok(CloseOutcome { trace: Some(tracer.traces()) } ),
|
fields.traces.as_mut().map(|mut traces| traces.push(tracer.traces()));
|
||||||
false => Ok(CloseOutcome { trace: None } )
|
|
||||||
}
|
}
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,7 @@ use ethkey::{Message, public_to_address, recover, Signature};
|
|||||||
use account_provider::AccountProvider;
|
use account_provider::AccountProvider;
|
||||||
use block::*;
|
use block::*;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use engines::{Engine, Seal, EngineError, CloseOutcome, ConstructedVerifier};
|
use engines::{Engine, Seal, EngineError, ConstructedVerifier};
|
||||||
use trace::{Tracer, ExecutiveTracer, RewardType};
|
use trace::{Tracer, ExecutiveTracer, RewardType};
|
||||||
use state::CleanupMode;
|
use state::CleanupMode;
|
||||||
use io::IoService;
|
use io::IoService;
|
||||||
@ -541,7 +541,7 @@ impl Engine for Tendermint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<CloseOutcome, Error>{
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error>{
|
||||||
let tracing_enabled = block.tracing_enabled();
|
let tracing_enabled = block.tracing_enabled();
|
||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
let mut tracer = ExecutiveTracer::default();
|
let mut tracer = ExecutiveTracer::default();
|
||||||
@ -554,19 +554,14 @@ impl Engine for Tendermint {
|
|||||||
if tracing_enabled {
|
if tracing_enabled {
|
||||||
let block_author = fields.header.author().clone();
|
let block_author = fields.header.author().clone();
|
||||||
tracer.trace_reward(block_author, self.params().block_reward, RewardType::Block);
|
tracer.trace_reward(block_author, self.params().block_reward, RewardType::Block);
|
||||||
|
fields.traces.as_mut().map(|mut traces| traces.push(tracer.traces()));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
if let Err(ref e) = res {
|
if let Err(ref e) = res {
|
||||||
warn!("Encountered error on closing block: {}", e);
|
warn!("Encountered error on closing block: {}", e);
|
||||||
}
|
}
|
||||||
match res {
|
res
|
||||||
Ok(_) => match tracing_enabled {
|
|
||||||
true => Ok(CloseOutcome { trace: Some(tracer.traces()) } ),
|
|
||||||
false => Ok(CloseOutcome { trace: None } )
|
|
||||||
},
|
|
||||||
Err(e) => Err(e)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||||
|
@ -29,7 +29,7 @@ use header::{Header, BlockNumber};
|
|||||||
use state::CleanupMode;
|
use state::CleanupMode;
|
||||||
use spec::CommonParams;
|
use spec::CommonParams;
|
||||||
use transaction::UnverifiedTransaction;
|
use transaction::UnverifiedTransaction;
|
||||||
use engines::{self, Engine, CloseOutcome};
|
use engines::{self, Engine};
|
||||||
use evm::Schedule;
|
use evm::Schedule;
|
||||||
use ethjson;
|
use ethjson;
|
||||||
use rlp::{self, UntrustedRlp};
|
use rlp::{self, UntrustedRlp};
|
||||||
@ -275,7 +275,8 @@ impl Engine for Arc<Ethash> {
|
|||||||
|
|
||||||
/// Apply the block reward on finalisation of the block.
|
/// Apply the block reward on finalisation of the block.
|
||||||
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
|
/// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current).
|
||||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<CloseOutcome, Error> {
|
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||||
|
use std::ops::Shr;
|
||||||
let reward = self.params().block_reward;
|
let reward = self.params().block_reward;
|
||||||
let tracing_enabled = block.tracing_enabled();
|
let tracing_enabled = block.tracing_enabled();
|
||||||
let fields = block.fields_mut();
|
let fields = block.fields_mut();
|
||||||
@ -284,7 +285,7 @@ impl Engine for Arc<Ethash> {
|
|||||||
let mut tracer = ExecutiveTracer::default();
|
let mut tracer = ExecutiveTracer::default();
|
||||||
|
|
||||||
// Bestow block reward
|
// Bestow block reward
|
||||||
let result_block_reward = reward + reward / U256::from(32) * U256::from(fields.uncles.len());
|
let result_block_reward = reward + reward.shr(5) * U256::from(fields.uncles.len());
|
||||||
fields.state.add_balance(
|
fields.state.add_balance(
|
||||||
fields.header.author(),
|
fields.header.author(),
|
||||||
&result_block_reward,
|
&result_block_reward,
|
||||||
@ -303,14 +304,14 @@ impl Engine for Arc<Ethash> {
|
|||||||
let result_uncle_reward: U256;
|
let result_uncle_reward: U256;
|
||||||
|
|
||||||
if eras == 0 {
|
if eras == 0 {
|
||||||
result_uncle_reward = reward * U256::from(8 + u.number() - current_number) / U256::from(8);
|
result_uncle_reward = (reward * U256::from(8 + u.number() - current_number)).shr(3);
|
||||||
fields.state.add_balance(
|
fields.state.add_balance(
|
||||||
u.author(),
|
u.author(),
|
||||||
&result_uncle_reward,
|
&result_uncle_reward,
|
||||||
CleanupMode::NoEmpty
|
CleanupMode::NoEmpty
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
result_uncle_reward = reward / U256::from(32);
|
result_uncle_reward = reward.shr(5);
|
||||||
fields.state.add_balance(
|
fields.state.add_balance(
|
||||||
u.author(),
|
u.author(),
|
||||||
&result_uncle_reward,
|
&result_uncle_reward,
|
||||||
@ -326,10 +327,10 @@ impl Engine for Arc<Ethash> {
|
|||||||
|
|
||||||
// Commit state so that we can actually figure out the state root.
|
// Commit state so that we can actually figure out the state root.
|
||||||
fields.state.commit()?;
|
fields.state.commit()?;
|
||||||
match tracing_enabled {
|
if tracing_enabled {
|
||||||
true => Ok(CloseOutcome { trace: Some(tracer.traces()) } ),
|
fields.traces.as_mut().map(|mut traces| traces.push(tracer.traces()));
|
||||||
false => Ok(CloseOutcome { trace: None } )
|
}
|
||||||
}
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||||
|
@ -151,11 +151,7 @@ impl Tracer for ExecutiveTracer {
|
|||||||
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address) {
|
fn trace_suicide(&mut self, address: Address, balance: U256, refund_address: Address) {
|
||||||
let trace = FlatTrace {
|
let trace = FlatTrace {
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
action: Action::Suicide(Suicide {
|
action: Action::Suicide(Suicide { address, refund_address, balance } ),
|
||||||
address: address,
|
|
||||||
refund_address: refund_address,
|
|
||||||
balance: balance,
|
|
||||||
}),
|
|
||||||
result: Res::None,
|
result: Res::None,
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
};
|
};
|
||||||
@ -166,11 +162,7 @@ impl Tracer for ExecutiveTracer {
|
|||||||
fn trace_reward(&mut self, author: Address, value: U256, reward_type: RewardType) {
|
fn trace_reward(&mut self, author: Address, value: U256, reward_type: RewardType) {
|
||||||
let trace = FlatTrace {
|
let trace = FlatTrace {
|
||||||
subtraces: 0,
|
subtraces: 0,
|
||||||
action: Action::Reward(Reward {
|
action: Action::Reward(Reward { author, value, reward_type } ),
|
||||||
author: author,
|
|
||||||
value: value,
|
|
||||||
reward_type: reward_type,
|
|
||||||
}),
|
|
||||||
result: Res::None,
|
result: Res::None,
|
||||||
trace_address: Default::default(),
|
trace_address: Default::default(),
|
||||||
};
|
};
|
||||||
|
@ -222,8 +222,6 @@ impl Create {
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
#[cfg_attr(feature = "ipc", binary)]
|
#[cfg_attr(feature = "ipc", binary)]
|
||||||
pub enum RewardType {
|
pub enum RewardType {
|
||||||
/// None
|
|
||||||
None,
|
|
||||||
/// Block
|
/// Block
|
||||||
Block,
|
Block,
|
||||||
/// Uncle
|
/// Uncle
|
||||||
@ -233,9 +231,8 @@ pub enum RewardType {
|
|||||||
impl Encodable for RewardType {
|
impl Encodable for RewardType {
|
||||||
fn rlp_append(&self, s: &mut RlpStream) {
|
fn rlp_append(&self, s: &mut RlpStream) {
|
||||||
let v = match *self {
|
let v = match *self {
|
||||||
RewardType::None => 0u32,
|
RewardType::Block => 0u32,
|
||||||
RewardType::Block => 1,
|
RewardType::Uncle => 1,
|
||||||
RewardType::Uncle => 2,
|
|
||||||
};
|
};
|
||||||
Encodable::rlp_append(&v, s);
|
Encodable::rlp_append(&v, s);
|
||||||
}
|
}
|
||||||
@ -244,9 +241,8 @@ impl Encodable for RewardType {
|
|||||||
impl Decodable for RewardType {
|
impl Decodable for RewardType {
|
||||||
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
fn decode(rlp: &UntrustedRlp) -> Result<Self, DecoderError> {
|
||||||
rlp.as_val().and_then(|v| Ok(match v {
|
rlp.as_val().and_then(|v| Ok(match v {
|
||||||
0u32 => RewardType::None,
|
0u32 => RewardType::Block,
|
||||||
1 => RewardType::Block,
|
1 => RewardType::Uncle,
|
||||||
2 => RewardType::Uncle,
|
|
||||||
_ => return Err(DecoderError::Custom("Invalid value of RewardType item")),
|
_ => return Err(DecoderError::Custom("Invalid value of RewardType item")),
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
@ -302,9 +302,6 @@ impl From<trace::Call> for Call {
|
|||||||
/// Reward type.
|
/// Reward type.
|
||||||
#[derive(Debug, Serialize)]
|
#[derive(Debug, Serialize)]
|
||||||
pub enum RewardType {
|
pub enum RewardType {
|
||||||
/// None
|
|
||||||
#[serde(rename="none")]
|
|
||||||
None,
|
|
||||||
/// Block
|
/// Block
|
||||||
#[serde(rename="block")]
|
#[serde(rename="block")]
|
||||||
Block,
|
Block,
|
||||||
@ -316,7 +313,6 @@ pub enum RewardType {
|
|||||||
impl From<trace::RewardType> for RewardType {
|
impl From<trace::RewardType> for RewardType {
|
||||||
fn from(c: trace::RewardType) -> Self {
|
fn from(c: trace::RewardType) -> Self {
|
||||||
match c {
|
match c {
|
||||||
trace::RewardType::None => RewardType::None,
|
|
||||||
trace::RewardType::Block => RewardType::Block,
|
trace::RewardType::Block => RewardType::Block,
|
||||||
trace::RewardType::Uncle => RewardType::Uncle,
|
trace::RewardType::Uncle => RewardType::Uncle,
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user