mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 23:31:07 +00:00
Gossip through all peers. (#359)
* Added some traces * Gossip for all * Fixed formatting
This commit is contained in:
committed by
Gav Wood
parent
7b8463aaf1
commit
73613f45c1
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user