Skip to content

feat(network): per-message-type size limit - #16173

Open
jancionear wants to merge 2 commits into
near:masterfrom
jancionear:netsize-master
Open

feat(network): per-message-type size limit#16173
jancionear wants to merge 2 commits into
near:masterfrom
jancionear:netsize-master

Conversation

@jancionear

@jancionear jancionear commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Add a size limit for all network message types. Previously the size was only limited by the main network message limit (512 MB)

cherry-pick 5ac2fcd to master

@codecov

codecov Bot commented Aug 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.00000% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 73.62%. Comparing base (3dc780d) to head (bf0da67).
⚠️ Report is 11 commits behind head on master.

Files with missing lines Patch % Lines
chain/network/src/peer/peer_actor.rs 37.50% 5 Missing ⚠️
chain/network/src/network_protocol/mod.rs 81.25% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #16173      +/-   ##
==========================================
- Coverage   73.62%   73.62%   -0.01%     
==========================================
  Files         865      865              
  Lines      191633   191657      +24     
  Branches   191633   191657      +24     
==========================================
+ Hits       141090   141103      +13     
- Misses      46065    46079      +14     
+ Partials     4478     4475       -3     
Flag Coverage Δ
pytests-nightly 1.20% <0.00%> (-0.01%) ⬇️
unittests 70.15% <68.00%> (+0.01%) ⬆️
unittests-nightly 70.19% <68.00%> (+<0.01%) ⬆️
unittests-spice 65.94% <68.00%> (-0.02%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jancionear
jancionear requested a review from pugachAG August 10, 2026 12:59
@jancionear
jancionear marked this pull request as ready for review August 10, 2026 12:59
@jancionear
jancionear requested a review from a team as a code owner August 10, 2026 12:59
Copilot AI balanced review requested due to automatic review settings August 10, 2026 12:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds per-message-type limits to reduce oversized inbound network messages.

Changes:

  • Defines four message-size tiers.
  • Drops and logs messages exceeding their type’s limit.
  • Records oversized-message metrics by type.

Reviewed changes

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

File Description
chain/network/src/network_protocol/mod.rs Maps message variants to size limits.
chain/network/src/peer/peer_actor.rs Enforces limits on incoming messages.
chain/network/src/stats/metrics.rs Adds oversized-message drop metrics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +1666 to +1669
let max_size = peer_msg.max_size();
if msg.len() > max_size {
let msg_variant = peer_msg.msg_variant();
metrics::MessageDropped::TooLargeForType.inc_msg_type(msg_variant);
Comment on lines +1665 to +1667
// Enforce a per-message-type size limit.
let max_size = peer_msg.max_size();
if msg.len() > max_size {
@greptile-apps

greptile-apps Bot commented Aug 10, 2026

Copy link
Copy Markdown

Greptile Summary

Adds per-message-type limits to incoming network traffic, replacing reliance on the single 512 MiB framing ceiling.

  • Classifies top-level and routed messages into 512 KiB, 32 MiB, 128 MiB, and 512 MiB limits.
  • Drops decoded frames exceeding their type-specific limit before dispatch and rate-limit processing.
  • Adds a dedicated metric reason for type-specific size-limit drops.

Confidence Score: 5/5

The PR appears safe to merge with no concrete blocking or independently actionable issue established.

The new checks consistently classify decoded message variants, drop frames above the corresponding threshold before dispatch, and account for those drops through the existing metrics infrastructure.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart LR
    Peer[Remote peer] --> Frame[Receive framed message]
    Frame --> Decode[Deserialize PeerMessage]
    Decode --> Limit{Frame within type limit?}
    Limit -- No --> Metric[Record TooLargeForType]
    Metric --> Drop[Drop message]
    Limit -- Yes --> Rate{Allowed by rate limit?}
    Rate -- No --> RateDrop[Drop rate-limited message]
    Rate -- Yes --> Dispatch[Dispatch by connection state and message type]
Loading

Reviews (1): Last reviewed commit: "fix clippy" | Re-trigger Greptile

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.

2 participants