move Sealing methods to MiningBlockChainClient

This commit is contained in:
keorn 2016-12-10 17:40:20 +01:00
parent 239ba61a99
commit b9909da8b1
5 changed files with 37 additions and 20 deletions

View File

@ -580,23 +580,6 @@ impl Client {
self.miner.clone() 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<Bytes>) {
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. /// Attempt to get a copy of a specific block's final state.
/// ///
/// This will not fail if given BlockID::Latest. /// This will not fail if given BlockID::Latest.
@ -1335,7 +1318,6 @@ impl BlockChainClient for Client {
} }
impl MiningBlockChainClient for Client { impl MiningBlockChainClient for Client {
fn latest_schedule(&self) -> Schedule { fn latest_schedule(&self) -> Schedule {
self.engine.schedule(&self.latest_env_info()) self.engine.schedule(&self.latest_env_info())
} }
@ -1378,6 +1360,20 @@ impl MiningBlockChainClient for Client {
&self.factories.vm &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<Bytes>) {
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) { fn broadcast_proposal_block(&self, block: SealedBlock) {
self.notify(|notify| { self.notify(|notify| {
notify.new_blocks( notify.new_blocks(

View File

@ -362,6 +362,18 @@ impl MiningBlockChainClient for TestBlockChainClient {
} }
fn broadcast_proposal_block(&self, _block: SealedBlock) {} 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<Bytes>) {
if self.miner.submit_seal(self, block_hash, seal).is_err() {
warn!(target: "poa", "Wrong internal seal submission!")
}
}
} }
impl BlockChainClient for TestBlockChainClient { impl BlockChainClient for TestBlockChainClient {

View File

@ -276,6 +276,15 @@ pub trait MiningBlockChainClient: BlockChainClient {
/// Returns EvmFactory. /// Returns EvmFactory.
fn vm_factory(&self) -> &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<Bytes>);
/// Used by PoA to communicate with peers.
fn broadcast_message(&self, message: Bytes);
/// Broadcast a block proposal. /// Broadcast a block proposal.
fn broadcast_proposal_block(&self, block: SealedBlock); fn broadcast_proposal_block(&self, block: SealedBlock);

View File

@ -667,7 +667,7 @@ mod tests {
use super::*; use super::*;
use super::message::*; 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<AccountProvider>) { fn setup() -> (Spec, Arc<AccountProvider>) {
let tap = Arc::new(AccountProvider::transient_provider()); let tap = Arc::new(AccountProvider::transient_provider());
let spec = Spec::new_test_tendermint(); let spec = Spec::new_test_tendermint();

View File

@ -21,7 +21,7 @@ use rlp::{UntrustedRlp, View};
use io::*; use io::*;
use spec::Spec; use spec::Spec;
use error::*; use error::*;
use client::{Client, ClientConfig, ChainNotify}; use client::{Client, MiningBlockChainClient, ClientConfig, ChainNotify};
use miner::Miner; use miner::Miner;
use snapshot::ManifestData; use snapshot::ManifestData;
use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams}; use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};