Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Commit

Permalink
Gossip through all peers. (#359)
Browse files Browse the repository at this point in the history
* Added some traces

* Gossip for all

* Fixed formatting
  • Loading branch information
arkpar authored and gavofyork committed Jul 18, 2018
1 parent 113cbda commit 97b801a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions polkadot/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ impl CurrentConsensus {
}

/// Polkadot-specific messages.
#[derive(Debug)]
pub enum Message {
/// signed statement and localized parent hash.
Statement(Hash, SignedStatement),
Expand Down Expand Up @@ -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))
}
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
}
Expand Down
5 changes: 3 additions & 2 deletions substrate/network/src/consensus_gossip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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());
}
}
Expand Down

0 comments on commit 97b801a

Please sign in to comment.