Skip to content

Conversation

patrick-ogrady
Copy link
Contributor

@patrick-ogrady patrick-ogrady commented Jun 25, 2025

Related: #1133

We should align the error (which already exists) with the metric name.

@patrick-ogrady patrick-ogrady marked this pull request as ready for review June 25, 2025 19:30

/// Unpack `msg` and verify the underlying `channel` is registered.
fn validate_msg<V>(msg: Option<Data>, rate_limits: &HashMap<u32, V>) -> Result<Data, Error> {
fn validate_outbound_msg<V>(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a double take and thought this was checking incoming messages were on a valid channel, so figured it would be clearer to rename.

@patrick-ogrady patrick-ogrady changed the title [p2p] Use existing InvalidChannel error [p2p] Use existing Error::InvalidChannel Jun 25, 2025
None => { // Treat unknown channels as invalid
debug!(?peer, channel = data.channel, "invalid channel");
self.received_messages
.get_or_create(&metrics::Message::new_invalid(&peer))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think error should be aligned with the metric name.

if !rate_limits.contains_key(&data.channel) {
return Err(Error::InvalidChannel);
}
assert!(
Copy link
Contributor Author

@patrick-ogrady patrick-ogrady Jun 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This indicates there exists some serious logic error somewhere in p2p and we should exit to avoid getting banned/blacklisted by peers.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that's fine

we should exit to avoid getting banned/blacklisted by peers

It did already short-circuit and not send the message, but I guess assert is fine if you prefer crashing

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should never actually be able to hit this with the public interface, so I think it is worth asserting.

@patrick-ogrady patrick-ogrady changed the title [p2p] Use existing Error::InvalidChannel [p2p] Use existing Error::InvalidChannel + Assert on Invalid Message Sends Jun 25, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adapts error handling for channel validation by removing the unused UnknownChannel variant and updating outbound messaging functions to assert invalid channel usage.

  • Remove the UnknownChannel error variant from both peer modules
  • Replace conditional error returns with assertions in outbound message validation
  • Update log messages to reflect the unified error type

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
p2p/src/authenticated/lookup/actors/peer/mod.rs Removed the UnknownChannel variant from the Error enum to align with existing errors
p2p/src/authenticated/lookup/actors/peer/actor.rs Updated inbound validation to outbound assertions and modified error logging
p2p/src/authenticated/discovery/actors/peer/mod.rs Removed the UnknownChannel variant from the Error enum to align with existing errors
p2p/src/authenticated/discovery/actors/peer/actor.rs Updated inbound validation to outbound assertions and modified error logging

if !rate_limits.contains_key(&data.channel) {
return Err(Error::InvalidChannel);
}
assert!(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure that's fine

we should exit to avoid getting banned/blacklisted by peers

It did already short-circuit and not send the message, but I guess assert is fine if you prefer crashing

BrendanChou
BrendanChou previously approved these changes Jun 25, 2025
@patrick-ogrady patrick-ogrady modified the milestone: v0.0.55 Jun 25, 2025
@patrick-ogrady patrick-ogrady merged commit db829b7 into main Jun 25, 2025
16 checks passed
@patrick-ogrady patrick-ogrady deleted the use-invalid-channel branch June 25, 2025 20:40
Copy link

codecov bot commented Jun 25, 2025

Codecov Report

Attention: Patch coverage is 63.63636% with 8 lines in your changes missing coverage. Please review.

Project coverage is 91.02%. Comparing base (0049a0d) to head (e16a2a0).
Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...p/src/authenticated/discovery/actors/peer/actor.rs 63.63% 4 Missing ⚠️
p2p/src/authenticated/lookup/actors/peer/actor.rs 63.63% 4 Missing ⚠️
@@           Coverage Diff           @@
##             main    #1158   +/-   ##
=======================================
  Coverage   91.02%   91.02%           
=======================================
  Files         215      215           
  Lines       57433    57439    +6     
=======================================
+ Hits        52276    52282    +6     
  Misses       5157     5157           
Files with missing lines Coverage Δ
...p/src/authenticated/discovery/actors/peer/actor.rs 84.00% <63.63%> (+0.27%) ⬆️
p2p/src/authenticated/lookup/actors/peer/actor.rs 79.87% <63.63%> (+0.38%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0049a0d...e16a2a0. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants