From b9909da8b13cc103dddb8c647d03e579a9acf203 Mon Sep 17 00:00:00 2001 From: keorn Date: Sat, 10 Dec 2016 17:40:20 +0100 Subject: [PATCH] move Sealing methods to MiningBlockChainClient --- ethcore/src/client/client.rs | 32 ++++++++++++--------------- ethcore/src/client/test_client.rs | 12 ++++++++++ ethcore/src/client/traits.rs | 9 ++++++++ ethcore/src/engines/tendermint/mod.rs | 2 +- ethcore/src/service.rs | 2 +- 5 files changed, 37 insertions(+), 20 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index e685969cc..eb7311975 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -580,23 +580,6 @@ impl Client { self.miner.clone() } - /// Used by PoA to try sealing on period change. - pub fn update_sealing(&self) { - self.miner.update_sealing(self) - } - - /// Used by PoA to submit gathered signatures. - pub fn submit_seal(&self, block_hash: H256, seal: Vec) { - if self.miner.submit_seal(self, block_hash, seal).is_err() { - warn!(target: "poa", "Wrong internal seal submission!") - } - } - - /// Used by PoA to communicate with peers. - pub fn broadcast_message(&self, message: Bytes) { - self.notify(|notify| notify.broadcast(message.clone())); - } - /// Attempt to get a copy of a specific block's final state. /// /// This will not fail if given BlockID::Latest. @@ -1335,7 +1318,6 @@ impl BlockChainClient for Client { } impl MiningBlockChainClient for Client { - fn latest_schedule(&self) -> Schedule { self.engine.schedule(&self.latest_env_info()) } @@ -1378,6 +1360,20 @@ impl MiningBlockChainClient for Client { &self.factories.vm } + fn broadcast_message(&self, message: Bytes) { + self.notify(|notify| notify.broadcast(message.clone())); + } + + fn update_sealing(&self) { + self.miner.update_sealing(self) + } + + fn submit_seal(&self, block_hash: H256, seal: Vec) { + if self.miner.submit_seal(self, block_hash, seal).is_err() { + warn!(target: "poa", "Wrong internal seal submission!") + } + } + fn broadcast_proposal_block(&self, block: SealedBlock) { self.notify(|notify| { notify.new_blocks( diff --git a/ethcore/src/client/test_client.rs b/ethcore/src/client/test_client.rs index 43dd366b0..9be4f8ae0 100644 --- a/ethcore/src/client/test_client.rs +++ b/ethcore/src/client/test_client.rs @@ -362,6 +362,18 @@ impl MiningBlockChainClient for TestBlockChainClient { } fn broadcast_proposal_block(&self, _block: SealedBlock) {} + + fn broadcast_message(&self, _message: Bytes) {} + + fn update_sealing(&self) { + self.miner.update_sealing(self) + } + + fn submit_seal(&self, block_hash: H256, seal: Vec) { + if self.miner.submit_seal(self, block_hash, seal).is_err() { + warn!(target: "poa", "Wrong internal seal submission!") + } + } } impl BlockChainClient for TestBlockChainClient { diff --git a/ethcore/src/client/traits.rs b/ethcore/src/client/traits.rs index 7488b8baf..69ff7e05a 100644 --- a/ethcore/src/client/traits.rs +++ b/ethcore/src/client/traits.rs @@ -276,6 +276,15 @@ pub trait MiningBlockChainClient: BlockChainClient { /// Returns EvmFactory. fn vm_factory(&self) -> &EvmFactory; + /// Used by PoA to try sealing on period change. + fn update_sealing(&self); + + /// Used by PoA to submit gathered signatures. + fn submit_seal(&self, block_hash: H256, seal: Vec); + + /// Used by PoA to communicate with peers. + fn broadcast_message(&self, message: Bytes); + /// Broadcast a block proposal. fn broadcast_proposal_block(&self, block: SealedBlock); diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index 7da2a9566..2b779950a 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -667,7 +667,7 @@ mod tests { use super::*; use super::message::*; - /// Accounts inserted with "1" and "2" are authorities. First proposer is "0". + /// Accounts inserted with "0" and "1" are authorities. First proposer is "0". fn setup() -> (Spec, Arc) { let tap = Arc::new(AccountProvider::transient_provider()); let spec = Spec::new_test_tendermint(); diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index 0429d3539..c2cb1889e 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -21,7 +21,7 @@ use rlp::{UntrustedRlp, View}; use io::*; use spec::Spec; use error::*; -use client::{Client, ClientConfig, ChainNotify}; +use client::{Client, MiningBlockChainClient, ClientConfig, ChainNotify}; use miner::Miner; use snapshot::ManifestData; use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};