Common engine method for bestowing rewards created
This commit is contained in:
parent
30434325a2
commit
655ed93ee8
@ -27,12 +27,10 @@ use block::*;
|
||||
use builtin::Builtin;
|
||||
use client::{Client, EngineClient};
|
||||
use engines::{Call, Engine, Seal, EngineError, ConstructedVerifier};
|
||||
use trace::{Tracer, ExecutiveTracer, RewardType};
|
||||
use error::{Error, TransactionError, BlockError};
|
||||
use ethjson;
|
||||
use header::{Header, BlockNumber};
|
||||
use spec::CommonParams;
|
||||
use state::CleanupMode;
|
||||
use transaction::UnverifiedTransaction;
|
||||
|
||||
use super::signer::EngineSigner;
|
||||
@ -547,26 +545,7 @@ impl Engine for AuthorityRound {
|
||||
|
||||
/// Apply the block reward on finalisation of the block.
|
||||
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();
|
||||
// Bestow block reward
|
||||
let reward = self.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();
|
||||
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);
|
||||
}
|
||||
res
|
||||
::engines::common::bestow_block_reward(block, self)
|
||||
}
|
||||
|
||||
/// Check the number of seal fields.
|
||||
|
@ -394,13 +394,14 @@ pub trait Engine : Sync + Send {
|
||||
/// Common engine utilities
|
||||
pub mod common {
|
||||
use std::sync::Arc;
|
||||
use block::ExecutedBlock;
|
||||
use block::{ExecutedBlock, IsBlock};
|
||||
use error::Error;
|
||||
use transaction::SYSTEM_ADDRESS;
|
||||
use executive::Executive;
|
||||
use vm::{CallType, ActionParams, ActionValue, EnvInfo, LastHashes};
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
use trace::{NoopTracer, NoopVMTracer, Tracer, ExecutiveTracer, RewardType};
|
||||
use state::Substate;
|
||||
use state::CleanupMode;
|
||||
|
||||
use util::*;
|
||||
use super::Engine;
|
||||
@ -469,4 +470,28 @@ pub mod common {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// 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();
|
||||
tracer.trace_reward(block_author, engine.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 bestowing reward: {}", e);
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
@ -72,6 +72,7 @@ impl Engine for NullEngine {
|
||||
|
||||
fn on_close_block(&self, block: &mut ExecutedBlock) -> Result<(), Error> {
|
||||
if self.params.block_reward == U256::zero() {
|
||||
// we don't have to apply reward in this case
|
||||
return Ok(())
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,6 @@ use account_provider::AccountProvider;
|
||||
use block::*;
|
||||
use spec::CommonParams;
|
||||
use engines::{Engine, Seal, EngineError, ConstructedVerifier};
|
||||
use trace::{Tracer, ExecutiveTracer, RewardType};
|
||||
use state::CleanupMode;
|
||||
use io::IoService;
|
||||
use super::signer::EngineSigner;
|
||||
use super::validator_set::{ValidatorSet, SimpleList};
|
||||
@ -542,26 +540,7 @@ impl Engine for Tendermint {
|
||||
|
||||
/// Apply the block reward on finalisation of the block.
|
||||
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();
|
||||
// Bestow block reward
|
||||
let reward = self.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();
|
||||
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);
|
||||
}
|
||||
res
|
||||
::engines::common::bestow_block_reward(block, self)
|
||||
}
|
||||
|
||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||
|
Loading…
Reference in New Issue
Block a user