From f449dc66670db030903b46ec07293bb4e63f5096 Mon Sep 17 00:00:00 2001 From: David Palm Date: Fri, 26 Mar 2021 13:24:54 +0100 Subject: [PATCH] Add a `Mute` message Send a `Mute` message to `NodeConnector` when a node is from a chain on the denylist OR if the chain is overquota. (Also: dial down logging of finalized blocks a bit) --- backend/src/aggregator.rs | 13 +++++++++---- backend/src/chain.rs | 2 +- backend/src/node/connector.rs | 19 ++++++++++++++++--- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/backend/src/aggregator.rs b/backend/src/aggregator.rs index 10b02a0..459118b 100644 --- a/backend/src/aggregator.rs +++ b/backend/src/aggregator.rs @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet}; use actix::prelude::*; use lazy_static::lazy_static; -use crate::node::connector::Initialize; +use crate::node::connector::{Initialize, Mute}; use crate::feed::connector::{FeedConnector, Connected, FeedId}; use crate::util::DenseMap; use crate::feed::{self, FeedMessageSerializer}; @@ -30,7 +30,7 @@ pub struct ChainEntry { } lazy_static! { - /// Labels of chains we consider "first party". These chains are allowed any + /// Labels of chains we consider "first party". These chains allow any /// number of nodes to connect. static ref FIRST_PARTY_NETWORKS: HashSet<&'static str> = { let mut set = HashSet::new(); @@ -131,6 +131,8 @@ pub struct AddNode { pub conn_id: ConnId, /// Recipient for the initialization message pub rec: Recipient, + /// Recipient for the mute message + pub mute: Recipient, } /// Message sent from the Chain to the Aggregator when the Chain loses all nodes @@ -196,10 +198,12 @@ impl Handler for Aggregator { fn handle(&mut self, msg: AddNode, ctx: &mut Self::Context) { if self.denylist.contains(&*msg.node.chain) { - log::debug!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain); + log::warn!(target: "Aggregator::AddNode", "'{}' is on the denylist.", msg.node.chain); + let AddNode { mute, .. } = msg; + let _ = mute.do_send(Mute {}); return; } - let AddNode { node, conn_id, rec } = msg; + let AddNode { node, conn_id, rec, mute } = msg; log::trace!(target: "Aggregator::AddNode", "New node connected. Chain '{}'", node.chain); let cid = self.lazy_chain(&node.chain, ctx); @@ -212,6 +216,7 @@ impl Handler for Aggregator { }); } else { log::warn!(target: "Aggregator::AddNode", "Chain {} is over quota ({})", chain.label, chain.max_nodes); + let _ = mute.do_send(Mute {}); } } } diff --git a/backend/src/chain.rs b/backend/src/chain.rs index 1f4ea4c..bcef302 100644 --- a/backend/src/chain.rs +++ b/backend/src/chain.rs @@ -284,7 +284,7 @@ impl Chain { if node.update_block(*block) { if block.height > self.best.height { self.best = *block; - log::info!( + log::debug!( "[{}] [nodes={}/feeds={}] new best block={}/{:?}", self.label.0, nodes_len, diff --git a/backend/src/node/connector.rs b/backend/src/node/connector.rs index c810b7b..3363751 100644 --- a/backend/src/node/connector.rs +++ b/backend/src/node/connector.rs @@ -109,8 +109,6 @@ impl NodeConnector { ConnMultiplex::Waiting { backlog } => { if let Payload::SystemConnected(connected) = msg.payload() { let mut node = connected.node.clone(); - let rec = ctx.address().recipient(); - // FIXME: Use genesis hash instead of names to avoid this mess match &*node.chain { "Kusama CC3" => node.chain = "Kusama".into(), @@ -123,7 +121,10 @@ impl NodeConnector { _ => () } - self.aggregator.do_send(AddNode { node, conn_id, rec }); + let rec = ctx.address().recipient(); + let mute = ctx.address().recipient(); + + self.aggregator.do_send(AddNode { node, conn_id, rec, mute }); } else { if backlog.len() >= 10 { backlog.remove(0); @@ -157,6 +158,18 @@ impl NodeConnector { } } +#[derive(Message)] +#[rtype(result = "()")] +pub struct Mute; + +impl Handler for NodeConnector { + type Result = (); + fn handle(&mut self, _msg: Mute, ctx: &mut Self::Context) { + log::trace!(target: "NodeConnector::Mute", "Muting a node"); + ctx.stop(); + } +} + #[derive(Message)] #[rtype(result = "()")] pub struct Initialize {