Add block rewards to more Engines (#4055)
* add block rewards * imports
This commit is contained in:
@@ -37,6 +37,7 @@ use service::ClientIoMessage;
|
||||
use transaction::SignedTransaction;
|
||||
use env_info::EnvInfo;
|
||||
use builtin::Builtin;
|
||||
use state::CleanupMode;
|
||||
|
||||
/// `AuthorityRound` params.
|
||||
#[derive(Debug, PartialEq)]
|
||||
@@ -49,6 +50,8 @@ pub struct AuthorityRoundParams {
|
||||
pub authorities: Vec<Address>,
|
||||
/// Number of authorities.
|
||||
pub authority_n: usize,
|
||||
/// Block reward.
|
||||
pub block_reward: U256,
|
||||
/// Starting step,
|
||||
pub start_step: Option<u64>,
|
||||
}
|
||||
@@ -60,6 +63,7 @@ impl From<ethjson::spec::AuthorityRoundParams> for AuthorityRoundParams {
|
||||
step_duration: Duration::from_secs(p.step_duration.into()),
|
||||
authority_n: p.authorities.len(),
|
||||
authorities: p.authorities.into_iter().map(Into::into).collect::<Vec<_>>(),
|
||||
block_reward: p.block_reward.map_or_else(U256::zero, Into::into),
|
||||
start_step: p.start_step.map(Into::into),
|
||||
}
|
||||
}
|
||||
@@ -249,6 +253,20 @@ impl Engine for AuthorityRound {
|
||||
Seal::None
|
||||
}
|
||||
|
||||
/// Apply the block reward on finalisation of the block.
|
||||
fn on_close_block(&self, block: &mut ExecutedBlock) {
|
||||
let reward = self.our_params.block_reward;
|
||||
let fields = block.fields_mut();
|
||||
|
||||
// Bestow block reward
|
||||
fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty);
|
||||
|
||||
// Commit state so that we can actually figure out the state root.
|
||||
if let Err(e) = fields.state.commit() {
|
||||
warn!("Encountered error on state commit: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
/// Check the number of seal fields.
|
||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||
if header.seal().len() != self.seal_fields() {
|
||||
|
||||
@@ -45,6 +45,7 @@ use views::HeaderView;
|
||||
use evm::Schedule;
|
||||
use io::{IoService, IoChannel};
|
||||
use service::ClientIoMessage;
|
||||
use state::CleanupMode;
|
||||
use self::message::*;
|
||||
use self::transition::TransitionHandler;
|
||||
use self::params::TendermintParams;
|
||||
@@ -469,6 +470,20 @@ impl Engine for Tendermint {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Apply the block reward on finalisation of the block.
|
||||
fn on_close_block(&self, block: &mut ExecutedBlock) {
|
||||
let reward = self.our_params.block_reward;
|
||||
let fields = block.fields_mut();
|
||||
|
||||
// Bestow block reward
|
||||
fields.state.add_balance(fields.header.author(), &reward, CleanupMode::NoEmpty);
|
||||
|
||||
// Commit state so that we can actually figure out the state root.
|
||||
if let Err(e) = fields.state.commit() {
|
||||
warn!("Encountered error on state commit: {}", e);
|
||||
}
|
||||
}
|
||||
|
||||
fn verify_block_basic(&self, header: &Header, _block: Option<&[u8]>) -> Result<(), Error> {
|
||||
let seal_length = header.seal().len();
|
||||
if seal_length == self.seal_fields() {
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
use ethjson;
|
||||
use super::transition::TendermintTimeouts;
|
||||
use util::{Address, U256};
|
||||
use util::{Address, Uint, U256};
|
||||
use time::Duration;
|
||||
|
||||
/// `Tendermint` params.
|
||||
@@ -32,6 +32,8 @@ pub struct TendermintParams {
|
||||
pub authority_n: usize,
|
||||
/// Timeout durations for different steps.
|
||||
pub timeouts: TendermintTimeouts,
|
||||
/// Block reward.
|
||||
pub block_reward: U256,
|
||||
}
|
||||
|
||||
impl Default for TendermintParams {
|
||||
@@ -42,6 +44,7 @@ impl Default for TendermintParams {
|
||||
gas_limit_bound_divisor: 0x0400.into(),
|
||||
authorities: authorities,
|
||||
authority_n: val_n,
|
||||
block_reward: U256::zero(),
|
||||
timeouts: TendermintTimeouts::default(),
|
||||
}
|
||||
}
|
||||
@@ -67,6 +70,7 @@ impl From<ethjson::spec::TendermintParams> for TendermintParams {
|
||||
precommit: p.timeout_precommit.map_or(dt.precommit, to_duration),
|
||||
commit: p.timeout_commit.map_or(dt.commit, to_duration),
|
||||
},
|
||||
block_reward: p.block_reward.map_or_else(U256::zero, Into::into),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user