From fef94205e3644cea58852d168aae23ac4a84373b Mon Sep 17 00:00:00 2001 From: keorn Date: Tue, 13 Sep 2016 19:59:34 +0200 Subject: [PATCH] enable internal sealing based on author --- 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 | 9 +++++++-- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ethcore/src/engines/basic_authority.rs b/ethcore/src/engines/basic_authority.rs index 5cb2be9ed..74b30ff6a 100644 --- a/ethcore/src/engines/basic_authority.rs +++ b/ethcore/src/engines/basic_authority.rs @@ -99,7 +99,7 @@ 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 } + fn seals_internally(&self, _author: &Address) -> bool { true } /// Attempt to seal the block internally. /// diff --git a/ethcore/src/engines/instant_seal.rs b/ethcore/src/engines/instant_seal.rs index e88c1d102..fc670b839 100644 --- a/ethcore/src/engines/instant_seal.rs +++ b/ethcore/src/engines/instant_seal.rs @@ -58,7 +58,7 @@ impl Engine for InstantSeal { Schedule::new_homestead() } - fn seals_internally(&self) -> bool { true } + fn seals_internally(&self, _author: &Address) -> 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 0394426ce..c2877cfa5 100644 --- a/ethcore/src/engines/mod.rs +++ b/ethcore/src/engines/mod.rs @@ -72,7 +72,7 @@ pub trait Engine : Sync + Send { fn on_close_block(&self, _block: &mut ExecutedBlock) {} /// If true, generate_seal has to be implemented. - fn seals_internally(&self) -> bool { false } + fn seals_internally(&self, _author: &Address) -> 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 152b0e994..fc6fe32ce 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -16,6 +16,7 @@ use rayon::prelude::*; use std::time::{Instant, Duration}; +use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering}; use util::*; use util::using_queue::{UsingQueue, GetAction}; @@ -175,6 +176,7 @@ pub struct Miner { sealing_block_last_request: Mutex, // for sealing... options: MinerOptions, + seals_internally: AtomicBool, gas_range_target: RwLock<(U256, U256)>, author: RwLock
, @@ -195,6 +197,7 @@ impl Miner { next_allowed_reseal: Mutex::new(Instant::now()), sealing_block_last_request: Mutex::new(0), sealing_work: Mutex::new(SealingWork{queue: UsingQueue::new(20), enabled: false}), + seals_internally: AtomicBool::new(spec.engine.seals_internally(&Address::default())), gas_range_target: RwLock::new((U256::zero(), U256::zero())), author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), @@ -214,6 +217,7 @@ impl Miner { next_allowed_reseal: Mutex::new(Instant::now()), sealing_block_last_request: Mutex::new(0), sealing_work: Mutex::new(SealingWork{queue: UsingQueue::new(options.work_queue_size), enabled: options.force_sealing || !options.new_work_notify.is_empty()}), + seals_internally: AtomicBool::new(spec.engine.seals_internally(&Address::default())), gas_range_target: RwLock::new((U256::zero(), U256::zero())), author: RwLock::new(Address::default()), extra_data: RwLock::new(Vec::new()), @@ -578,6 +582,7 @@ impl MinerService for Miner { } fn set_author(&self, author: Address) { + self.seals_internally.store(self.engine.seals_internally(&author), AtomicOrdering::SeqCst); *self.author.write() = author; } @@ -703,7 +708,7 @@ impl MinerService for Miner { if imported.is_ok() && self.options.reseal_on_own_tx && self.tx_reseal_allowed() { // Make sure to do it after transaction is imported and lock is droped. // We need to create pending block and enable sealing. - if self.engine.seals_internally() || !self.prepare_work_sealing(chain) { + if self.seals_internally.load(AtomicOrdering::SeqCst) || !self.prepare_work_sealing(chain) { // If new block has not been prepared (means we already had one) // or Engine might be able to seal internally, // we need to update sealing. @@ -821,7 +826,7 @@ impl MinerService for Miner { // -------------------------------------------------------------------------- trace!(target: "miner", "update_sealing: preparing a block"); let (block, original_work_hash) = self.prepare_block(chain); - if self.engine.seals_internally() { + if self.seals_internally.load(AtomicOrdering::SeqCst) { trace!(target: "miner", "update_sealing: engine indicates internal sealing"); self.seal_and_import_block_internally(chain, block); } else {