From 51bbad66d06d4ecc7dbaeba3fe01740d74076866 Mon Sep 17 00:00:00 2001 From: keorn Date: Wed, 16 Nov 2016 15:56:16 +0000 Subject: [PATCH] add a path to submit seal from engine --- ethcore/src/client/client.rs | 7 +++++++ ethcore/src/engines/tendermint/mod.rs | 9 +++++++++ ethcore/src/miner/miner.rs | 6 +++--- ethcore/src/service.rs | 8 +++++++- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/ethcore/src/client/client.rs b/ethcore/src/client/client.rs index e0f33af6a..e7aa716bd 100644 --- a/ethcore/src/client/client.rs +++ b/ethcore/src/client/client.rs @@ -569,6 +569,13 @@ impl Client { 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!") + } + } + /// Attempt to get a copy of a specific block's final state. /// /// This will not fail if given BlockID::Latest. diff --git a/ethcore/src/engines/tendermint/mod.rs b/ethcore/src/engines/tendermint/mod.rs index 47ed8f828..bb87b8ab2 100644 --- a/ethcore/src/engines/tendermint/mod.rs +++ b/ethcore/src/engines/tendermint/mod.rs @@ -116,6 +116,15 @@ impl Tendermint { } } + fn submit_seal(&self, block_hash: H256, seal: Vec) { + if let Some(ref channel) = *self.message_channel.lock() { + match channel.send(ClientIoMessage::SubmitSeal(block_hash, seal)) { + Ok(_) => trace!(target: "poa", "timeout: SubmitSeal message sent."), + Err(err) => warn!(target: "poa", "timeout: Could not send a sealing message {}.", err), + } + } + } + fn nonce_proposer(&self, proposer_nonce: usize) -> &Address { let ref p = self.our_params; p.authorities.get(proposer_nonce % p.authority_n).unwrap() diff --git a/ethcore/src/miner/miner.rs b/ethcore/src/miner/miner.rs index 84e29458d..f93203b00 100644 --- a/ethcore/src/miner/miner.rs +++ b/ethcore/src/miner/miner.rs @@ -1008,7 +1008,7 @@ impl MinerService for Miner { ret.map(f) } - fn submit_seal(&self, chain: &MiningBlockChainClient, pow_hash: H256, seal: Vec) -> Result<(), Error> { + fn submit_seal(&self, chain: &MiningBlockChainClient, block_hash: H256, seal: Vec) -> Result<(), Error> { let result = if let Some(b) = self.sealing_work.lock().queue.get_used_if( if self.options.enable_resubmission { @@ -1016,9 +1016,9 @@ impl MinerService for Miner { } else { GetAction::Take }, - |b| &b.hash() == &pow_hash + |b| &b.hash() == &block_hash ) { - trace!(target: "miner", "Sealing block {}={}={} with seal {:?}", pow_hash, b.hash(), b.header().bare_hash(), seal); + trace!(target: "miner", "Sealing block {}={}={} with seal {:?}", block_hash, b.hash(), b.header().bare_hash(), seal); b.lock().try_seal(&*self.engine, seal).or_else(|(e, _)| { warn!(target: "miner", "Mined solution rejected: {}", e); Err(Error::PowInvalid) diff --git a/ethcore/src/service.rs b/ethcore/src/service.rs index 36b5e7157..b19de72e9 100644 --- a/ethcore/src/service.rs +++ b/ethcore/src/service.rs @@ -50,6 +50,8 @@ pub enum ClientIoMessage { TakeSnapshot(u64), /// Trigger sealing update (useful for internal sealing). UpdateSealing, + /// Submit seal (useful for internal sealing). + SubmitSeal(H256, Vec), } /// Client service setup. Creates and registers client and network services with the IO subsystem. @@ -219,9 +221,13 @@ impl IoHandler for ClientIoHandler { } }, ClientIoMessage::UpdateSealing => { - trace!(target: "authorityround", "message: UpdateSealing"); + trace!(target: "poa", "message: UpdateSealing"); self.client.update_sealing() }, + ClientIoMessage::SubmitSeal(ref hash, ref seal) => { + trace!(target: "poa", "message: SubmitSeal"); + self.client.submit_seal(*hash, seal.clone()) + }, _ => {} // ignore other messages } }