Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Merge clear_author into MinerService::set_author.
Browse files Browse the repository at this point in the history
  • Loading branch information
afck committed Oct 8, 2019
1 parent 972c60d commit 58ddaee
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 38 deletions.
57 changes: 32 additions & 25 deletions ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<Option<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);
}
}

Expand Down
5 changes: 1 addition & 4 deletions ethcore/src/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<Option<Author>>>(&self, author: T);

// Transaction Pool

Expand Down
2 changes: 1 addition & 1 deletion rpc/src/v1/impls/parity_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<C, M, U, F> ParitySet for ParitySetClient<C, M, U, F> where
}

fn clear_engine_signer(&self) -> Result<bool> {
self.miner.clear_author();
self.miner.set_author(None);
Ok(true)
}

Expand Down
15 changes: 7 additions & 8 deletions rpc/src/v1/tests/helpers/miner_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T: Into<Option<miner::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;
}
Expand Down

0 comments on commit 58ddaee

Please sign in to comment.