From bcbd8b3baa2b648b43275684129bd7ac6135d0a4 Mon Sep 17 00:00:00 2001 From: Bo QIU <35757521+boqiu@users.noreply.github.com> Date: Tue, 5 Nov 2024 15:10:44 +0800 Subject: [PATCH] Ban peer if failed to decode pubsub message (#259) --- node/network/src/behaviour/mod.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/node/network/src/behaviour/mod.rs b/node/network/src/behaviour/mod.rs index e848e26..4df7c6d 100644 --- a/node/network/src/behaviour/mod.rs +++ b/node/network/src/behaviour/mod.rs @@ -592,7 +592,7 @@ where // peer that originally published the message. match PubsubMessage::decode(&gs_msg.topic, &gs_msg.data) { Err(e) => { - debug!(topic = ?gs_msg.topic, error = ?e, "Could not decode gossipsub message"); + debug!(topic = ?gs_msg.topic, %propagation_source, error = ?e, "Could not decode gossipsub message"); //reject the message if let Err(e) = self.gossipsub.report_message_validation_result( &id, @@ -601,6 +601,24 @@ where ) { warn!(message_id = %id, peer_id = %propagation_source, error = ?e, "Failed to report message validation"); } + + self.peer_manager.report_peer( + &propagation_source, + PeerAction::Fatal, + ReportSource::Gossipsub, + None, + "gossipsub message decode error", + ); + + if let Some(source) = &gs_msg.source { + self.peer_manager.report_peer( + source, + PeerAction::Fatal, + ReportSource::Gossipsub, + None, + "gossipsub message decode error", + ); + } } Ok(msg) => { // Notify the network