From 58ddaeefb89f7b2dc7c6ac5d2df55e0352845003 Mon Sep 17 00:00:00 2001 From: Andreas Fackler Date: Tue, 8 Oct 2019 12:48:01 +0200 Subject: [PATCH] Merge clear_author into MinerService::set_author. --- ethcore/src/miner/miner.rs | 57 +++++++++++++---------- ethcore/src/miner/mod.rs | 5 +- rpc/src/v1/impls/parity_set.rs | 2 +- rpc/src/v1/tests/helpers/miner_service.rs | 15 +++--- 4 files changed, 41 insertions(+), 38 deletions(-) diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index e870cf74e85..d97b1170266 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -893,32 +893,39 @@ impl miner::MinerService for Miner { self.params.write().extra_data = extra_data; } - fn set_author(&self, author: Author) { - self.params.write().author = author.address(); - - if let Author::Sealer(signer) = author { - if self.engine.sealing_state() != SealingState::External { - // Enable sealing - self.sealing.lock().enabled = true; - // -------------------------------------------------------------------------- - // | NOTE Code below may require author and sealing locks | - // | (some `Engine`s call `EngineClient.update_sealing()`) | - // | Make sure to release the locks before calling that method. | - // -------------------------------------------------------------------------- - self.engine.set_signer(Some(signer)); - } else { - warn!("Setting an EngineSigner while Engine does not require one."); + fn set_author>>(&self, author: T) { + let author_opt = author.into(); + self.params.write().author = author_opt.as_ref().map(Author::address).unwrap_or_default(); + + match author_opt { + Some(Author::Sealer(signer)) => { + if self.engine.sealing_state() != SealingState::External { + // Enable sealing + self.sealing.lock().enabled = true; + // -------------------------------------------------------------------------- + // | NOTE Code below may require author and sealing locks | + // | (some `Engine`s call `EngineClient.update_sealing()`) | + // | Make sure to release the locks before calling that method. | + // -------------------------------------------------------------------------- + self.engine.set_signer(Some(signer)); + } else { + warn!("Setting an EngineSigner while Engine does not require one."); + } + } + Some(Author::External(_address)) => (), + None => { + // Clear the author. + if self.engine.sealing_state() != SealingState::External { + // Disable sealing. + self.sealing.lock().enabled = false; + // -------------------------------------------------------------------------- + // | NOTE Code below may require author and sealing locks | + // | (some `Engine`s call `EngineClient.update_sealing()`) | + // | Make sure to release the locks before calling that method. | + // -------------------------------------------------------------------------- + self.engine.set_signer(None); + } } - } - } - - fn clear_author(&self) { - // Clear the author. - self.params.write().author = Default::default(); - if self.engine.sealing_state() != SealingState::External { - // Disable sealing. - self.sealing.lock().enabled = false; - self.engine.set_signer(None); } } diff --git a/ethcore/src/miner/mod.rs b/ethcore/src/miner/mod.rs index 4fb030d2391..9961f12af80 100644 --- a/ethcore/src/miner/mod.rs +++ b/ethcore/src/miner/mod.rs @@ -132,10 +132,7 @@ pub trait MinerService : Send + Sync { /// Set info necessary to sign consensus messages and block authoring. /// /// On chains where sealing is done externally (e.g. PoW) we provide only reward beneficiary. - fn set_author(&self, author: Author); - - /// Clears the engine signer and stops signing. - fn clear_author(&self); + fn set_author>>(&self, author: T); // Transaction Pool diff --git a/rpc/src/v1/impls/parity_set.rs b/rpc/src/v1/impls/parity_set.rs index e1c99468874..0db3c99ca27 100644 --- a/rpc/src/v1/impls/parity_set.rs +++ b/rpc/src/v1/impls/parity_set.rs @@ -167,7 +167,7 @@ impl ParitySet for ParitySetClient where } fn clear_engine_signer(&self) -> Result { - self.miner.clear_author(); + self.miner.set_author(None); Ok(true) } diff --git a/rpc/src/v1/tests/helpers/miner_service.rs b/rpc/src/v1/tests/helpers/miner_service.rs index ac23109e17f..0af99e1227c 100644 --- a/rpc/src/v1/tests/helpers/miner_service.rs +++ b/rpc/src/v1/tests/helpers/miner_service.rs @@ -127,17 +127,16 @@ impl MinerService for TestMinerService { self.authoring_params.read().clone() } - fn set_author(&self, author: miner::Author) { - self.authoring_params.write().author = author.address(); - if let miner::Author::Sealer(signer) = author { - *self.signer.write() = Some(signer); + fn set_author>>(&self, author: T) { + let author_opt = author.into(); + self.authoring_params.write().author = author_opt.as_ref().map(miner::Author::address).unwrap_or_default(); + match author_opt { + Some(miner::Author::Sealer(signer)) => *self.signer.write() = Some(signer), + Some(miner::Author::External(_addr)) => (), + None => *self.signer.write() = None, } } - fn clear_author(&self) { - *self.authoring_params.write() = Default::default(); - } - fn set_extra_data(&self, extra_data: Bytes) { self.authoring_params.write().extra_data = extra_data; }