Skip to content
Snippets Groups Projects
Commit 73613f45 authored by Arkadiy Paronyan's avatar Arkadiy Paronyan Committed by Gav Wood
Browse files

Gossip through all peers. (#359)

* Added some traces

* Gossip for all

* Fixed formatting
parent 7b8463aa
No related merge requests found
......@@ -183,6 +183,7 @@ impl CurrentConsensus {
}
/// Polkadot-specific messages.
#[derive(Debug)]
pub enum Message {
/// signed statement and localized parent hash.
Statement(Hash, SignedStatement),
......@@ -250,6 +251,7 @@ impl Decode for Message {
}
fn send_polkadot_message(ctx: &mut Context<Block>, to: PeerId, message: Message) {
trace!(target: "p_net", "Sending polkadot message to {}: {:?}", to, message);
let encoded = message.encode();
ctx.send_message(to, generic_message::Message::ChainSpecific(encoded))
}
......@@ -386,6 +388,7 @@ impl PolkadotProtocol {
}
fn on_polkadot_message(&mut self, ctx: &mut Context<Block>, peer_id: PeerId, raw: Vec<u8>, msg: Message) {
trace!(target: "p_net", "Polkadot message from {}: {:?}", peer_id, msg);
match msg {
Message::Statement(parent_hash, _statement) =>
self.consensus_gossip.on_chain_specific(ctx, peer_id, raw, parent_hash),
......@@ -535,6 +538,7 @@ impl Specialization<Block> for PolkadotProtocol {
fn on_message(&mut self, ctx: &mut Context<Block>, peer_id: PeerId, message: message::Message<Block>) {
match message {
generic_message::Message::BftMessage(msg) => {
trace!(target: "p_net", "Polkadot BFT message from {}: {:?}", peer_id, msg);
// TODO: check signature here? what if relevant block is unknown?
self.consensus_gossip.on_bft_message(ctx, peer_id, msg)
}
......
......@@ -75,8 +75,8 @@ impl<B: BlockT> ConsensusGossip<B> where B::Header: HeaderT<Number=u64> {
/// Handle new connected peer.
pub fn new_peer(&mut self, protocol: &mut Context<B>, peer_id: PeerId, roles: Roles) {
if roles.contains(Roles::AUTHORITY) {
trace!(target:"gossip", "Registering authority {}", peer_id);
if roles.intersects(Roles::AUTHORITY | Roles::FULL) {
trace!(target:"gossip", "Registering {:?} {}", roles, peer_id);
// Send out all known messages.
// TODO: limit by size
let mut known_messages = HashSet::new();
......@@ -98,6 +98,7 @@ impl<B: BlockT> ConsensusGossip<B> where B::Header: HeaderT<Number=u64> {
fn propagate(&mut self, protocol: &mut Context<B>, message: message::Message<B>, hash: B::Hash) {
for (id, ref mut peer) in self.peers.iter_mut() {
if peer.known_messages.insert(hash.clone()) {
trace!(target:"gossip", "Propagating to {}: {:?}", id, message);
protocol.send_message(*id, message.clone());
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment