miner will use separate spec
This commit is contained in:
parent
71278def5e
commit
994d056922
@ -14,6 +14,8 @@
|
|||||||
// You should have received a copy of the GNU General Public License
|
// You should have received a copy of the GNU General Public License
|
||||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
//! Consensus engine specification
|
||||||
|
|
||||||
use common::*;
|
use common::*;
|
||||||
use util::keys::store::AccountProvider;
|
use util::keys::store::AccountProvider;
|
||||||
use block::ExecutedBlock;
|
use block::ExecutedBlock;
|
||||||
|
@ -103,6 +103,7 @@ pub mod trace;
|
|||||||
pub mod spec;
|
pub mod spec;
|
||||||
pub mod views;
|
pub mod views;
|
||||||
pub mod pod_state;
|
pub mod pod_state;
|
||||||
|
pub mod engine;
|
||||||
|
|
||||||
mod db;
|
mod db;
|
||||||
mod common;
|
mod common;
|
||||||
@ -112,7 +113,6 @@ mod env_info;
|
|||||||
mod pod_account;
|
mod pod_account;
|
||||||
mod account_diff;
|
mod account_diff;
|
||||||
mod state_diff;
|
mod state_diff;
|
||||||
mod engine;
|
|
||||||
mod state;
|
mod state;
|
||||||
mod account;
|
mod account;
|
||||||
mod account_db;
|
mod account_db;
|
||||||
|
@ -25,6 +25,8 @@ use ethcore::block::{ClosedBlock, IsBlock};
|
|||||||
use ethcore::error::*;
|
use ethcore::error::*;
|
||||||
use ethcore::client::{Executive, Executed, EnvInfo, TransactOptions};
|
use ethcore::client::{Executive, Executed, EnvInfo, TransactOptions};
|
||||||
use ethcore::transaction::SignedTransaction;
|
use ethcore::transaction::SignedTransaction;
|
||||||
|
use ethcore::spec::Spec;
|
||||||
|
use ethcore::engine::Engine;
|
||||||
use super::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
use super::{MinerService, MinerStatus, TransactionQueue, AccountDetails, TransactionImportResult, TransactionOrigin};
|
||||||
|
|
||||||
/// Keeps track of transactions using priority queue and holds currently mined block.
|
/// Keeps track of transactions using priority queue and holds currently mined block.
|
||||||
@ -39,6 +41,7 @@ pub struct Miner {
|
|||||||
gas_floor_target: RwLock<U256>,
|
gas_floor_target: RwLock<U256>,
|
||||||
author: RwLock<Address>,
|
author: RwLock<Address>,
|
||||||
extra_data: RwLock<Bytes>,
|
extra_data: RwLock<Bytes>,
|
||||||
|
spec: Spec,
|
||||||
|
|
||||||
accounts: RwLock<Option<Arc<AccountService>>>, // TODO: this is horrible since AccountService already contains a single RwLock field. refactor.
|
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()),
|
author: RwLock::new(Address::default()),
|
||||||
extra_data: RwLock::new(Vec::new()),
|
extra_data: RwLock::new(Vec::new()),
|
||||||
accounts: RwLock::new(None),
|
accounts: RwLock::new(None),
|
||||||
|
spec: Spec::new_test(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Miner {
|
impl Miner {
|
||||||
/// Creates new instance of 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 {
|
Arc::new(Miner {
|
||||||
transaction_queue: Mutex::new(TransactionQueue::new()),
|
transaction_queue: Mutex::new(TransactionQueue::new()),
|
||||||
force_sealing: force_sealing,
|
force_sealing: force_sealing,
|
||||||
@ -72,11 +76,12 @@ impl Miner {
|
|||||||
author: RwLock::new(Address::default()),
|
author: RwLock::new(Address::default()),
|
||||||
extra_data: RwLock::new(Vec::new()),
|
extra_data: RwLock::new(Vec::new()),
|
||||||
accounts: RwLock::new(None),
|
accounts: RwLock::new(None),
|
||||||
|
spec: spec,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates new instance of miner
|
/// 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 {
|
Arc::new(Miner {
|
||||||
transaction_queue: Mutex::new(TransactionQueue::new()),
|
transaction_queue: Mutex::new(TransactionQueue::new()),
|
||||||
force_sealing: force_sealing,
|
force_sealing: force_sealing,
|
||||||
@ -87,9 +92,14 @@ impl Miner {
|
|||||||
author: RwLock::new(Address::default()),
|
author: RwLock::new(Address::default()),
|
||||||
extra_data: RwLock::new(Vec::new()),
|
extra_data: RwLock::new(Vec::new()),
|
||||||
accounts: RwLock::new(Some(accounts)),
|
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.
|
/// Prepares new block for sealing including top transactions from queue.
|
||||||
#[cfg_attr(feature="dev", allow(match_same_arms))]
|
#[cfg_attr(feature="dev", allow(match_same_arms))]
|
||||||
fn prepare_sealing(&self, chain: &BlockChainClient) {
|
fn prepare_sealing(&self, chain: &BlockChainClient) {
|
||||||
@ -166,7 +176,7 @@ impl Miner {
|
|||||||
trace!(target: "miner", "prepare_sealing: block has transaction - attempting internal seal.");
|
trace!(target: "miner", "prepare_sealing: block has transaction - attempting internal seal.");
|
||||||
// block with transactions - see if we can seal immediately.
|
// block with transactions - see if we can seal immediately.
|
||||||
let a = self.accounts.read().unwrap();
|
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),
|
Some(ref x) => Some(x.deref() as &AccountProvider),
|
||||||
None => None,
|
None => None,
|
||||||
});
|
});
|
||||||
|
@ -145,7 +145,7 @@ fn execute_client(conf: Configuration) {
|
|||||||
let client = service.client();
|
let client = service.client();
|
||||||
|
|
||||||
// Miner
|
// 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_author(conf.author());
|
||||||
miner.set_gas_floor_target(conf.gas_floor_target());
|
miner.set_gas_floor_target(conf.gas_floor_target());
|
||||||
miner.set_extra_data(conf.extra_data());
|
miner.set_extra_data(conf.extra_data());
|
||||||
|
Loading…
Reference in New Issue
Block a user