Skip to content

fix(proto): let the initial window leave in one burst before the first RTT sample - #922

Open
PQCrypta wants to merge 2 commits into
n0-computer:mainfrom
PQCrypta:pacing-initial-window
Open

PQCrypta wants to merge 2 commits into
n0-computer:mainfrom
PQCrypta:pacing-initial-window

Conversation

@PQCrypta

@PQCrypta PQCrypta commented Dec 2, 2026

Copy link
Copy Markdown

Refs #879 (the pacing part; you asked for this PR on 2 and 18 Nov).

Before a path has an RTT sample, the pacer uses the 333 ms initial RTT, so its burst is one datagram, and a ClientHello that needs two (any with an ML-KEM key share) waits about 27 ms for the second. Until the first sample, the burst may be the congestion window, the initial window RFC 9002 §7.7 allows, still bounded by MIN/MAX_BURST_SIZE. Once there's a sample nothing changes.

Test: initial_window_bursts_before_an_rtt_sample. sent_packets_stats_snapshot_test counts one more server packet, because the NEW_CONNECTION_IDs now go out right behind the Handshake flight.

…t RTT sample

Before a path has an RTT sample, `smoothed_rtt` is the configured initial RTT
(333 ms), so `optimal_capacity` limited the pacer's burst to one MTU and refilled
it at about one datagram per 27 ms. A ClientHello that takes two datagrams (any
with an ML-KEM key share) had its second held until the server's ACK or the
pacing timer, and a server's handshake flight was split the same way.

Until the first RTT sample, the burst may now be the congestion window (the
initial window then, as RFC 9002 section 7.7 allows), bounded by
MIN_BURST_SIZE and MAX_BURST_SIZE times the MTU. Once the path has a sample,
capacity is computed as before, so MAX_BURST_INTERVAL still bounds
window-paced flows. The pacer recomputes capacity when the path gets its
first sample (`RttEstimator::has_sample`), as it does when the window or the
MTU change. A controller that reports a pacing rate (BBRv3) never reaches
this path.

`sent_packets_stats_snapshot_test` counts one more server packet: the
NEW_CONNECTION_IDs now leave as 0.5-RTT data right behind the Handshake flight
instead of with HANDSHAKE_DONE. New test:
`initial_window_bursts_before_an_rtt_sample`.

Refs n0-computer#879
@n0bot n0bot Bot added this to iroh Dec 2, 2026
@github-project-automation github-project-automation Bot moved this to 🚑 Needs Triage in iroh Dec 2, 2026

@flub flub left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for following up with this PR!

Comment thread noq-proto/src/connection/pacing.rs Outdated
Comment on lines +257 to +263
/// section 7.7 allows. Limiting it by [`MAX_BURST_INTERVAL`] of the initial
/// RTT instead allowed a single datagram, and refilled at a datagram per
/// ~27 ms: a ClientHello that takes two datagrams (any with an ML-KEM key
/// share) had its second held until the server's acknowledgement or that
/// timer, and a server's first flight after its first datagram the same way.
/// (A controller that reports a pacing rate never comes here: BBRv3 starts
/// from a 1 ms nominal RTT, so its first flight leaves in one burst too.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's not describe how this used to behave. And also the motivation is for the PR description.

Comment thread noq-proto/src/connection/pacing.rs Outdated
Ord::max(window, mtu),
);
}
rate_capacity(rate, mtu)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you put this in an explicit else branch so that you don't need the return statement above? That makes the control flow more clear.

Comment thread noq-proto/src/connection/pacing.rs Outdated
let mtu = u64::from(mtu);
let target_capacity =
((rate as u128 * TARGET_BURST_INTERVAL.as_nanos()) / 1_000_000_000) as u64;
return Ord::min(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you re-write the comparisons using use std::cmp; and cmp::min & cmp::max? The trait methods do read rather odd like this.

Comment thread noq-proto/src/connection/paths.rs Outdated
self.smoothed.unwrap_or(self.latest)
}

/// Whether an RTT has been measured, or [`Self::get`] is still the initial RTT

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
/// Whether an RTT has been measured, or [`Self::get`] is still the initial RTT
/// Whether an RTT has been measured, or [`Self::get`] is still the initial RTT.

We're writing new doc comments using the rustdoc style guide, which requires a full stop.

// Before the first RTT sample the pacer lets the initial window go out in
// one burst (`pacing::optimal_capacity`), so the server's
// NEW_CONNECTION_IDs leave as 0.5-RTT data right behind its Handshake
// flight, instead of waiting for the packet that carries HANDSHAKE_DONE.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

oh, this is a lovely improvement actually

@github-project-automation github-project-automation Bot moved this from 🚑 Needs Triage to 🏗 In progress in iroh Dec 3, 2026
@flub

flub commented Dec 3, 2026

Copy link
Copy Markdown
Member

Don't worry about the cargo-deny failure, we'll sort that out.

@PQCrypta

PQCrypta commented Dec 4, 2026

Copy link
Copy Markdown
Author

Thanks! All four are in 16c73d7: the doc comment only says what the function does now, there's an explicit else, the comparisons use cmp::min/cmp::max, and the full stop is there. I imported core::cmp rather than std::cmp, since noq-proto denies clippy's std_instead_of_core.

This branch has not been deployed

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

Labels

None yet

Projects

Status: 🏗 In progress

Development

Successfully merging this pull request may close these issues.

3 participants