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