diff --git a/substrate/tendermint/client/src/authority/gossip.rs b/substrate/tendermint/client/src/authority/gossip.rs index 79350f60..9e1b54ef 100644 --- a/substrate/tendermint/client/src/authority/gossip.rs +++ b/substrate/tendermint/client/src/authority/gossip.rs @@ -1,41 +1,49 @@ use std::sync::{Arc, RwLock}; -use sp_core::{Decode, sr25519::Signature}; +use sp_core::Decode; use sp_runtime::traits::{Hash, Header, Block}; use sc_network::PeerId; use sc_network_gossip::{Validator, ValidatorContext, ValidationResult}; -use tendermint_machine::{SignedMessage, ext::SignatureScheme}; +use tendermint_machine::{ext::SignatureScheme, SignedMessage}; + +use crate::{TendermintValidator, validators::TendermintValidators}; #[derive(Clone)] -pub struct TendermintGossip> { +pub(crate) struct TendermintGossip { number: Arc>, - signature_scheme: Arc, + signature_scheme: Arc>, } -impl> TendermintGossip { - pub(crate) fn new(number: Arc>, signature_scheme: Arc) -> TendermintGossip { +impl TendermintGossip { + pub(crate) fn new( + number: Arc>, + signature_scheme: Arc>, + ) -> Self { TendermintGossip { number, signature_scheme } } - pub(crate) fn topic(number: u64) -> B::Hash { - <::Hashing as Hash>::hash( + pub(crate) fn topic(number: u64) -> ::Hash { + <<::Header as Header>::Hashing as Hash>::hash( &[b"Tendermint Block Topic".as_ref(), &number.to_le_bytes()].concat(), ) } } -impl> Validator - for TendermintGossip -{ +impl Validator for TendermintGossip { fn validate( &self, - _: &mut dyn ValidatorContext, + _: &mut dyn ValidatorContext, _: &PeerId, data: &[u8], - ) -> ValidationResult { - let msg = match SignedMessage::::decode(&mut &*data) { + ) -> ValidationResult<::Hash> { + let msg = match SignedMessage::< + u16, + T::Block, + as SignatureScheme>::Signature, + >::decode(&mut &*data) + { Ok(msg) => msg, Err(_) => return ValidationResult::Discard, }; @@ -48,6 +56,6 @@ impl> Val return ValidationResult::Discard; } - ValidationResult::ProcessAndKeep(Self::topic::(msg.number().0)) + ValidationResult::ProcessAndKeep(Self::topic(msg.number().0)) } } diff --git a/substrate/tendermint/client/src/authority/mod.rs b/substrate/tendermint/client/src/authority/mod.rs index e7fb97d0..51d1c923 100644 --- a/substrate/tendermint/client/src/authority/mod.rs +++ b/substrate/tendermint/client/src/authority/mod.rs @@ -9,7 +9,7 @@ use log::warn; use tokio::task::yield_now; -use sp_core::{Encode, Decode, sr25519::Signature}; +use sp_core::{Encode, Decode}; use sp_inherents::{InherentData, InherentDataProvider, CreateInherentDataProviders}; use sp_runtime::{ traits::{Header, Block}, @@ -29,7 +29,7 @@ use sc_network_gossip::GossipEngine; use substrate_prometheus_endpoint::Registry; use tendermint_machine::{ - ext::{BlockError, BlockNumber, Commit, Network}, + ext::{BlockError, BlockNumber, Commit, SignatureScheme, Network}, SignedMessage, TendermintMachine, }; @@ -51,7 +51,11 @@ struct ActiveAuthority { // Block whose gossip is being tracked number: Arc>, // Outgoing message queue, placed here as the GossipEngine itself can't be - gossip_queue: Arc>>>, + gossip_queue: Arc< + RwLock< + Vec as SignatureScheme>::Signature>>, + >, + >, // Block producer env: T::Environment, @@ -188,18 +192,13 @@ impl TendermintAuthority { }; // Start receiving messages about the Tendermint process for this block - let mut recv = gossip - .messages_for(TendermintGossip::>::topic::(last_number)); + let mut recv = gossip.messages_for(TendermintGossip::::topic(last_number)); 'outer: loop { // Send out any queued messages let mut queue = gossip_queue.write().unwrap().drain(..).collect::>(); for msg in queue.drain(..) { - gossip.gossip_message( - TendermintGossip::>::topic::(msg.number().0), - msg.encode(), - false, - ); + gossip.gossip_message(TendermintGossip::::topic(msg.number().0), msg.encode(), false); } // Handle any received messages @@ -232,9 +231,7 @@ impl TendermintAuthority { last_number = curr; // TODO: Will this return existing messages on the new height? Or will those have // been ignored and are now gone? - recv = gossip.messages_for(TendermintGossip::>::topic::< - T::Block, - >(last_number)); + recv = gossip.messages_for(TendermintGossip::::topic(last_number)); } // If there are no messages available, yield to not hog the thread, then return to the @@ -265,7 +262,10 @@ impl Network for TendermintAuthority { self.import.validators.clone() } - async fn broadcast(&mut self, msg: SignedMessage) { + async fn broadcast( + &mut self, + msg: SignedMessage as SignatureScheme>::Signature>, + ) { self.active.as_mut().unwrap().gossip_queue.write().unwrap().push(msg); }