Gossip refactoring (#1811)

* First part of gossip protocol refactoring

* Message validation in GRANDPA

* Reverted to time-based expiration for future round messages

* Removed collect_garbage_for_topic

* Use consensus engine id instead of kind

* Use try_init

Co-Authored-By: arkpar <arkady.paronyan@gmail.com>

* Comment

Co-Authored-By: arkpar <arkady.paronyan@gmail.com>

* Added expiration check on broadcast

Co-Authored-By: arkpar <arkady.paronyan@gmail.com>

* Apply suggestions from code review

Co-Authored-By: arkpar <arkady.paronyan@gmail.com>

* Style

* Style
This commit is contained in:
Arkadiy Paronyan
2019-02-20 12:40:03 +01:00
committed by Gav Wood
parent 21779b8cf2
commit b3eae17f65
10 changed files with 456 additions and 269 deletions
+7 -7
View File
@@ -34,12 +34,12 @@ use consensus::import_queue::{BasicQueue, ImportQueue, IncomingBlock};
use consensus::import_queue::{Link, SharedBlockImport, SharedJustificationImport, Verifier};
use consensus::{Error as ConsensusError, ErrorKind as ConsensusErrorKind};
use consensus::{BlockOrigin, ForkChoiceStrategy, ImportBlock, JustificationImport};
use crate::consensus_gossip::{ConsensusGossip, ConsensusMessage};
use crate::consensus_gossip::ConsensusGossip;
use crossbeam_channel::{self as channel, Sender, select};
use futures::Future;
use futures::sync::{mpsc, oneshot};
use keyring::Keyring;
use crate::message::Message;
use crate::message::{Message, ConsensusEngineId};
use network_libp2p::{NodeIndex, ProtocolId};
use parity_codec::Encode;
use parking_lot::Mutex;
@@ -274,21 +274,21 @@ impl<D> Peer<D> {
/// Push a message into the gossip network and relay to peers.
/// `TestNet::sync_step` needs to be called to ensure it's propagated.
pub fn gossip_message(&self, topic: <Block as BlockT>::Hash, data: Vec<u8>, broadcast: bool) {
pub fn gossip_message(&self, topic: <Block as BlockT>::Hash, engine_id: ConsensusEngineId, data: Vec<u8>) {
let _ = self
.protocol_sender
.send(ProtocolMsg::GossipConsensusMessage(topic, data, broadcast));
.send(ProtocolMsg::GossipConsensusMessage(topic, engine_id, data));
}
pub fn consensus_gossip_collect_garbage_for_topic(&self, topic: <Block as BlockT>::Hash) {
self.with_gossip(move |gossip, _| gossip.collect_garbage_for_topic(topic))
pub fn consensus_gossip_collect_garbage_for_topic(&self, _topic: <Block as BlockT>::Hash) {
self.with_gossip(move |gossip, _| gossip.collect_garbage())
}
/// access the underlying consensus gossip handler
pub fn consensus_gossip_messages_for(
&self,
topic: <Block as BlockT>::Hash,
) -> mpsc::UnboundedReceiver<ConsensusMessage> {
) -> mpsc::UnboundedReceiver<Vec<u8>> {
let (tx, rx) = oneshot::channel();
self.with_gossip(move |gossip, _| {
let inner_rx = gossip.messages_for(topic);