Common method for tracing refactored due to comments on review

This commit is contained in:
Anton Gavrilov 2017-08-04 16:06:12 +02:00
parent 655ed93ee8
commit dd91121017
2 changed files with 11 additions and 10 deletions

View File

@ -394,7 +394,7 @@ pub trait Engine : Sync + Send {
/// Common engine utilities /// Common engine utilities
pub mod common { pub mod common {
use std::sync::Arc; use std::sync::Arc;
use block::{ExecutedBlock, IsBlock}; use block::ExecutedBlock;
use error::Error; use error::Error;
use transaction::SYSTEM_ADDRESS; use transaction::SYSTEM_ADDRESS;
use executive::Executive; use executive::Executive;
@ -473,20 +473,19 @@ pub mod common {
/// Trace rewards on closing block /// Trace rewards on closing block
pub fn bestow_block_reward<E: Engine + ?Sized>(block: &mut ExecutedBlock, engine: &E) -> Result<(), Error> { pub fn bestow_block_reward<E: Engine + ?Sized>(block: &mut ExecutedBlock, engine: &E) -> Result<(), Error> {
let tracing_enabled = block.tracing_enabled();
let fields = block.fields_mut(); let fields = block.fields_mut();
let mut tracer = ExecutiveTracer::default();
// Bestow block reward // Bestow block reward
let reward = engine.params().block_reward; let reward = engine.params().block_reward;
let res = fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty) let res = fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty)
.map_err(::error::Error::from) .map_err(::error::Error::from)
.and_then(|_| fields.state.commit()); .and_then(|_| fields.state.commit());
if tracing_enabled { let block_author = fields.header.author().clone();
let block_author = fields.header.author().clone(); fields.traces.as_mut().map(|mut traces| {
tracer.trace_reward(block_author, engine.params().block_reward, RewardType::Block); let mut tracer = ExecutiveTracer::default();
fields.traces.as_mut().map(|mut traces| traces.push(tracer.traces())); tracer.trace_reward(block_author, engine.params().block_reward, RewardType::Block);
} 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 {

View File

@ -102,7 +102,9 @@ impl Engine for NullEngine {
&(result_uncle_reward), &(result_uncle_reward),
CleanupMode::NoEmpty CleanupMode::NoEmpty
)?; )?;
tracer.trace_reward(uncle_author, result_uncle_reward, RewardType::Uncle); if tracing_enabled {
tracer.trace_reward(uncle_author, result_uncle_reward, RewardType::Uncle);
}
} }
fields.state.commit()?; fields.state.commit()?;