From c0201bd891d5992a2adeb9a773f4ada2b084d0ba Mon Sep 17 00:00:00 2001 From: keorn Date: Mon, 12 Sep 2016 11:07:40 +0200 Subject: [PATCH] replace cli with engine method, simplify --- ethcore/src/engines/basic_authority.rs | 2 ++ ethcore/src/engines/instant_seal.rs | 2 ++ ethcore/src/engines/mod.rs | 2 ++ ethcore/src/miner/miner.rs | 35 +++++++++++--------------- parity/cli.rs | 4 --- parity/configuration.rs | 1 - rpc/src/v1/tests/eth.rs | 1 - 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 18dfeec46..5cb2be9ed 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -99,6 +99,8 @@ impl Engine for BasicAuthority { /// This assumes that all uncles are valid uncles (i.e. of at least one generation before the current). fn on_close_block(&self, _block: &mut ExecutedBlock) {} + fn seals_internally(&self) -> bool { true } + /// Attempt to seal the block internally. /// /// This operation is synchronous and may (quite reasonably) not be available, in which `false` will diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index 3c95f3465..9153d1913 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -58,6 +58,8 @@ impl Engine for InstantSeal { Schedule::new_homestead() } + fn seals_internally(&self) -> bool { true } + fn generate_seal(&self, _block: &ExecutedBlock, _accounts: Option<&AccountProvider>) -> Option> { Some(Vec::new()) } diff --git a/ethcore/src/engines/mod.rs b/ethcore/src/engines/mod.rs index 6414ba5e4..0394426ce 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -71,6 +71,8 @@ pub trait Engine : Sync + Send { /// Block transformation functions, after the transactions. fn on_close_block(&self, _block: &mut ExecutedBlock) {} + /// If true, generate_seal has to be implemented. + fn seals_internally(&self) -> bool { false } /// Attempt to seal the block internally. /// /// If `Some` is returned, then you get a valid seal. diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index b79395c0c..fdfd43c60 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -60,8 +60,6 @@ pub struct MinerOptions { pub reseal_on_own_tx: bool, /// Minimum period between transaction-inspired reseals. pub reseal_min_period: Duration, - /// Seal blocks internally. - pub internal_sealing: bool, /// Maximum amount of gas to bother considering for block insertion. pub tx_gas_limit: U256, /// Maximum size of the transaction queue. @@ -81,7 +79,6 @@ impl Default for MinerOptions { force_sealing: false, reseal_on_external_tx: false, reseal_on_own_tx: true, - internal_sealing: false, tx_gas_limit: !U256::zero(), tx_queue_size: 1024, pending_set: PendingSet::AlwaysQueue, @@ -245,6 +242,7 @@ impl Miner { self.sealing_work.lock().queue.peek_last_ref().map(|b| b.base().clone()) } + /// Prepares new block for sealing including top transactions from queue. fn prepare_block(&self, chain: &MiningBlockChainClient) -> (ClosedBlock, Option) { { trace!(target: "miner", "prepare_block: recalibrating..."); @@ -355,19 +353,19 @@ impl Miner { } } - fn seal_and_import_block_internally(&self, chain: &MiningBlockChainClient) -> bool { - let (block, _) = self.prepare_block(chain); - + /// Uses engine to seal the block and then imports it to chain. + fn seal_and_import_block_internally(&self, chain: &MiningBlockChainClient, block: ClosedBlock) -> bool { if !block.transactions().is_empty() { if let Ok(sealed) = self.seal_block_internally(block) { if chain.import_block(sealed.rlp_bytes()).is_ok() { - return true; + return true } } } false } + /// Prepares work which has to be done to seal. fn prepare_work(&self, block: ClosedBlock, original_work_hash: Option) { let (work, is_new) = { let mut sealing_work = self.sealing_work.lock(); @@ -396,15 +394,6 @@ impl Miner { } } - /// Prepares new block for sealing including top transactions from queue. - fn prepare_block_and_work(&self, chain: &MiningBlockChainClient) { - trace!(target: "miner", "prepare_block_and_work: entering"); - - let (block, original_work_hash) = self.prepare_block(chain); - - self.prepare_work(block, original_work_hash); - } - fn update_gas_limit(&self, chain: &MiningBlockChainClient) { let gas_limit = HeaderView::new(&chain.best_block_header()).gas_limit(); let mut queue = self.transaction_queue.lock(); @@ -430,7 +419,8 @@ impl Miner { // | NOTE Code below requires transaction_queue and sealing_work locks. | // | Make sure to release the locks before calling that method. | // -------------------------------------------------------------------------- - self.prepare_block_and_work(chain); + let (block, original_work_hash) = self.prepare_block(chain); + self.prepare_work(block, original_work_hash); } let mut sealing_block_last_request = self.sealing_block_last_request.lock(); let best_number = chain.chain_info().best_block_number; @@ -823,10 +813,14 @@ impl MinerService for Miner { // | NOTE Code below requires transaction_queue and sealing_work locks. | // | Make sure to release the locks before calling that method. | // -------------------------------------------------------------------------- - if self.options.internal_sealing { - self.seal_and_import_block_internally(chain); + trace!(target: "miner", "update_sealing: preparing a block"); + let (block, original_work_hash) = self.prepare_block(chain); + if self.engine.seals_internally() { + trace!(target: "miner", "update_sealing: engine indicates internal sealing"); + self.seal_and_import_block_internally(chain, block); } else { - self.prepare_block_and_work(chain); + trace!(target: "miner", "update_sealing: engine does not seal internally, preparing work"); + self.prepare_work(block, original_work_hash); } } } @@ -985,7 +979,6 @@ mod tests { force_sealing: false, reseal_on_external_tx: false, reseal_on_own_tx: true, - internal_sealing: false, reseal_min_period: Duration::from_secs(5), tx_gas_limit: !U256::zero(), tx_queue_size: 1024, diff --git a/parity/cli.rs b/parity/cli.rs index 652bcec8f..bb46bda13 100644 --- a/parity/cli.rs +++ b/parity/cli.rs @@ -163,9 +163,6 @@ Sealing/Mining Options: --reseal-min-period MS Specify the minimum time between reseals from incoming transactions. MS is time measured in milliseconds [default: 2000]. - --internal-sealing Use an internal sealing mechanism, - suitable for PoA or PoS. - --work-queue-size ITEMS Specify the number of historical work packages which are kept cached lest a solution is found for them later. High values take more memory but result @@ -369,7 +366,6 @@ pub struct Args { pub flag_force_sealing: bool, pub flag_reseal_on_txs: String, pub flag_reseal_min_period: u64, - pub flag_internal_sealing: bool, pub flag_work_queue_size: usize, pub flag_remove_solved: bool, pub flag_tx_gas_limit: Option, diff --git a/parity/configuration.rs b/parity/configuration.rs index 083b70768..51d637580 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -326,7 +326,6 @@ impl Configuration { let options = MinerOptions { new_work_notify: self.work_notify(), force_sealing: self.args.flag_force_sealing, - internal_sealing: self.args.flag_internal_sealing, reseal_on_external_tx: reseal.external, reseal_on_own_tx: reseal.own, tx_gas_limit: match self.args.flag_tx_gas_limit { diff --git a/rpc/src/v1/tests/eth.rs b/rpc/src/v1/tests/eth.rs index 06cc6f065..448fa4734 100644 --- a/rpc/src/v1/tests/eth.rs +++ b/rpc/src/v1/tests/eth.rs @@ -56,7 +56,6 @@ fn miner_service(spec: &Spec, accounts: Arc) -> Arc { force_sealing: true, reseal_on_external_tx: true, reseal_on_own_tx: true, - internal_sealing: false, tx_queue_size: 1024, tx_gas_limit: !U256::zero(), pending_set: PendingSet::SealingOrElseQueue,