Fix grandpa issue for InvalidViewChanges (#2468)

* fix: add message_allowed to send_topic to avoid InvalidViewChanges

* fix: this should be strict

* fix typo

* fix: simplify
This commit is contained in:
Marcio Diaz
2019-05-04 01:16:14 +02:00
committed by GitHub
parent 32c85a61b5
commit 18ec2d14d0
@@ -445,11 +445,22 @@ impl<B: BlockT> ConsensusGossip<B> {
/// Send all messages with given topic to a peer.
pub fn send_topic(&mut self, protocol: &mut Context<B>, who: &PeerId, topic: B::Hash, engine_id: ConsensusEngineId, force: bool) {
let validator = self.validators.get(&engine_id);
let mut message_allowed = match validator {
None => return, // treat all messages with no validator as not allowed
Some(validator) => validator.message_allowed(),
};
let intent = if force { MessageIntent::ForcedBroadcast } else { MessageIntent::Broadcast };
if let Some(ref mut peer) = self.peers.get_mut(who) {
for entry in self.messages.iter().filter(|m| m.topic == topic && m.message.engine_id == engine_id) {
if !force && peer.known_messages.contains(&entry.message_hash) {
continue
}
if !message_allowed(who, intent, &entry.topic, &entry.message.data) {
continue
}
peer.known_messages.insert(entry.message_hash.clone());
trace!(target: "gossip", "Sending topic message to {}: {:?}", who, entry.message);
protocol.send_consensus(who.clone(), ConsensusMessage {