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
pub mod common {
use std::sync::Arc;
use block::{ExecutedBlock, IsBlock};
use block::ExecutedBlock;
use error::Error;
use transaction::SYSTEM_ADDRESS;
use executive::Executive;
@ -473,20 +473,19 @@ pub mod common {
/// Trace rewards on closing block
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 mut tracer = ExecutiveTracer::default();
// Bestow block reward
let reward = engine.params().block_reward;
let res = fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty)
.map_err(::error::Error::from)
.and_then(|_| fields.state.commit());
if tracing_enabled {
let block_author = fields.header.author().clone();
fields.traces.as_mut().map(|mut traces| {
let mut tracer = ExecutiveTracer::default();
tracer.trace_reward(block_author, engine.params().block_reward, RewardType::Block);
fields.traces.as_mut().map(|mut traces| traces.push(tracer.traces()));
}
traces.push(tracer.traces())
});
// Commit state so that we can actually figure out the state root.
if let Err(ref e) = res {

View File

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