From 994d056922316dd20a475d8bab2081a6e0fe8608 Mon Sep 17 00:00:00 2001 From: Nikolay Volf Date: Mon, 16 May 2016 19:16:56 +0300 Subject: [PATCH] miner will use separate spec --- ethcore/src/engine.rs | 2 ++ ethcore/src/lib.rs | 2 +- miner/src/miner.rs | 16 +++++++++++++--- parity/main.rs | 2 +- 4 files changed, 17 insertions(+), 5 deletions(-) diff --git a/ethcore/src/engine.rs b/ethcore/src/engine.rs index 344144c6e..050d5b499 100644 --- a/ethcore/src/engine.rs +++ b/ethcore/src/engine.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +//! Consensus engine specification + use common::*; use util::keys::store::AccountProvider; use block::ExecutedBlock; diff --git a/ethcore/src/lib.rs b/ethcore/src/lib.rs index 0b62ec4fb..346711327 100644 --- a/ethcore/src/lib.rs +++ b/ethcore/src/lib.rs @@ -103,6 +103,7 @@ pub mod trace; pub mod spec; pub mod views; pub mod pod_state; +pub mod engine; mod db; mod common; @@ -112,7 +113,6 @@ mod env_info; mod pod_account; mod account_diff; mod state_diff; -mod engine; mod state; mod account; mod account_db; diff --git a/miner/src/miner.rs b/miner/src/miner.rs index 33d21613f..e89fe2bf8 100644 --- a/miner/src/miner.rs +++ b/miner/src/miner.rs @@ -25,6 +25,8 @@ use ethcore::block::{ClosedBlock, IsBlock}; use ethcore::error::*; use ethcore::client::{Executive, Executed, EnvInfo, TransactOptions}; use ethcore::transaction::SignedTransaction; +use ethcore::spec::Spec; +use ethcore::engine::Engine; use super::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin}; /// Keeps track of transactions using priority queue and holds currently mined block. @@ -39,6 +41,7 @@ pub struct Miner { gas_floor_target: RwLock, author: RwLock
, extra_data: RwLock, + spec: Spec, accounts: RwLock>>, // TODO: this is horrible since AccountService already contains a single RwLock field. refactor. } @@ -55,13 +58,14 @@ impl Default for Miner { author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), accounts: RwLock::new(None), + spec: Spec::new_test(), } } } impl Miner { /// Creates new instance of miner - pub fn new(force_sealing: bool) -> Arc { + pub fn new(force_sealing: bool, spec: Spec) -> Arc { Arc::new(Miner { transaction_queue: Mutex::new(TransactionQueue::new()), force_sealing: force_sealing, @@ -72,11 +76,12 @@ impl Miner { author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), accounts: RwLock::new(None), + spec: spec, }) } /// Creates new instance of miner - pub fn with_accounts(force_sealing: bool, accounts: Arc) -> Arc { + pub fn with_accounts(force_sealing: bool, spec: Spec, accounts: Arc) -> Arc { Arc::new(Miner { transaction_queue: Mutex::new(TransactionQueue::new()), force_sealing: force_sealing, @@ -87,9 +92,14 @@ impl Miner { author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), accounts: RwLock::new(Some(accounts)), + spec: spec, }) } + fn engine(&self) -> &Engine { + self.spec.engine.deref() + } + /// Prepares new block for sealing including top transactions from queue. #[cfg_attr(feature="dev", allow(match_same_arms))] fn prepare_sealing(&self, chain: &BlockChainClient) { @@ -166,7 +176,7 @@ impl Miner { trace!(target: "miner", "prepare_sealing: block has transaction - attempting internal seal."); // block with transactions - see if we can seal immediately. let a = self.accounts.read().unwrap(); - let s = chain.generate_seal(block.block(), match *a.deref() { + let s = self.engine().generate_seal(block.block(), match *a.deref() { Some(ref x) => Some(x.deref() as &AccountProvider), None => None, }); diff --git a/parity/main.rs b/parity/main.rs index dd70d39cc..4896e42cf 100644 --- a/parity/main.rs +++ b/parity/main.rs @@ -145,7 +145,7 @@ fn execute_client(conf: Configuration) { let client = service.client(); // Miner - let miner = Miner::with_accounts(conf.args.flag_force_sealing, account_service.clone()); + let miner = Miner::with_accounts(conf.args.flag_force_sealing, conf.spec(), account_service.clone()); miner.set_author(conf.author()); miner.set_gas_floor_target(conf.gas_floor_target()); miner.set_extra_data(conf.extra_data());