miner will use separate spec

This commit is contained in:
Nikolay Volf 2016-05-16 19:16:56 +03:00
parent 71278def5e
commit 994d056922
4 changed files with 17 additions and 5 deletions

View File

@ -14,6 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
//! Consensus engine specification
use common::*;
use util::keys::store::AccountProvider;
use block::ExecutedBlock;

View File

@ -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;

View File

@ -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<U256>,
author: RwLock<Address>,
extra_data: RwLock<Bytes>,
spec: Spec,
accounts: RwLock<Option<Arc<AccountService>>>, // 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<Miner> {
pub fn new(force_sealing: bool, spec: Spec) -> Arc<Miner> {
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<AccountService>) -> Arc<Miner> {
pub fn with_accounts(force_sealing: bool, spec: Spec, accounts: Arc<AccountService>) -> Arc<Miner> {
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,
});

View File

@ -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());