Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(gossipsub): remove duplicated call to inbound_transform #5767

Merged
merged 9 commits into from
Jan 16, 2025
59 changes: 27 additions & 32 deletions protocols/gossipsub/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1672,7 +1672,8 @@ where
);
self.handle_invalid_message(
propagation_source,
raw_message,
&raw_message.topic,
Some(msg_id),
RejectReason::BlackListedSource,
);
return false;
Expand Down Expand Up @@ -1701,7 +1702,12 @@ where
source=%propagation_source,
"Dropping message claiming to be from self but forwarded from source"
);
self.handle_invalid_message(propagation_source, raw_message, RejectReason::SelfOrigin);
self.handle_invalid_message(
propagation_source,
&raw_message.topic,
Some(msg_id),
RejectReason::SelfOrigin,
);
return false;
}

Expand Down Expand Up @@ -1729,7 +1735,8 @@ where
// Reject the message and return
self.handle_invalid_message(
propagation_source,
&raw_message,
&raw_message.topic,
None,
RejectReason::ValidationError(ValidationError::TransformFailed),
);
return;
Expand Down Expand Up @@ -1815,42 +1822,29 @@ where
fn handle_invalid_message(
&mut self,
propagation_source: &PeerId,
raw_message: &RawMessage,
topic_hash: &TopicHash,
message_id: Option<&MessageId>,
reject_reason: RejectReason,
) {
if let Some(metrics) = self.metrics.as_mut() {
metrics.register_invalid_message(&raw_message.topic);
metrics.register_invalid_message(topic_hash);
}

let message = self.data_transform.inbound_transform(raw_message.clone());

match (&mut self.peer_score, message) {
(Some((peer_score, ..)), Ok(message)) => {
let message_id = self.config.message_id(&message);

peer_score.reject_message(
propagation_source,
&message_id,
&message.topic,
reject_reason,
);

self.gossip_promises
.reject_message(&message_id, &reject_reason);
}
(Some((peer_score, ..)), Err(_)) => {
if let Some((peer_score, ..)) = &mut self.peer_score {
if let Some(msg_id) = message_id {
peer_score.reject_message(propagation_source, msg_id, topic_hash, reject_reason);
// The message itself is valid, but is from a banned peer or
// claiming to be self-origin but is actually forwarded from other peers.
return self.gossip_promises.reject_message(msg_id, &reject_reason);
elenaf9 marked this conversation as resolved.
Show resolved Hide resolved
} else {
// The message is invalid, we reject it ignoring any gossip promises. If a peer is
// advertising this message via an IHAVE and it's invalid it will be double
// penalized, one for sending us an invalid and again for breaking a promise.
peer_score.reject_invalid_message(propagation_source, &raw_message.topic);
return peer_score.reject_invalid_message(propagation_source, topic_hash);
}
(None, Ok(message)) => {
// Valid transformation without peer scoring
let message_id = self.config.message_id(&message);
self.gossip_promises
.reject_message(&message_id, &reject_reason);
}
(None, Err(_)) => {}
}
if let Some(msg_id) = message_id {
// Valid transformation without peer scoring
self.gossip_promises.reject_message(msg_id, &reject_reason);
}
}

Expand Down Expand Up @@ -3219,7 +3213,8 @@ where
for (raw_message, validation_error) in invalid_messages {
self.handle_invalid_message(
&propagation_source,
&raw_message,
&raw_message.topic,
None,
jxs marked this conversation as resolved.
Show resolved Hide resolved
RejectReason::ValidationError(validation_error),
)
}
Expand Down
Loading