gfe-relnote: For QUIC BBRv2: 1) Don't grow inflight_hi unless it's fully used, and 2) Cap inflight_lo in PROBE_CRUISE. Protected by --gfe2_reloadable_flag_quic_bbr2_fix_inflight_bounds.

PiperOrigin-RevId: 271636423
Change-Id: I3eeb334f3d09086c9d546cee3bcb34f005c75d9c
diff --git a/quic/core/congestion_control/bbr2_misc.h b/quic/core/congestion_control/bbr2_misc.h
index 4ad351e..bf2c00d 100644
--- a/quic/core/congestion_control/bbr2_misc.h
+++ b/quic/core/congestion_control/bbr2_misc.h
@@ -379,6 +379,11 @@
     return std::numeric_limits<QuicByteCount>::max();
   }
   void clear_inflight_lo() { inflight_lo_ = inflight_lo_default(); }
+  void cap_inflight_lo(QuicByteCount cap) {
+    if (inflight_lo_ != inflight_lo_default() && inflight_lo_ > cap) {
+      inflight_lo_ = cap;
+    }
+  }
 
   QuicByteCount inflight_hi_with_headroom() const;
   QuicByteCount inflight_hi() const { return inflight_hi_; }
diff --git a/quic/core/congestion_control/bbr2_probe_bw.cc b/quic/core/congestion_control/bbr2_probe_bw.cc
index ed65cf9..fcaa6a1 100644
--- a/quic/core/congestion_control/bbr2_probe_bw.cc
+++ b/quic/core/congestion_control/bbr2_probe_bw.cc
@@ -266,23 +266,40 @@
   DCHECK_EQ(cycle_.phase, CyclePhase::PROBE_UP);
   if (!model_->IsCongestionWindowLimited(congestion_event)) {
     QUIC_DVLOG(3) << sender_
-                  << " Rasing inflight_hi early return: Not cwnd limited.";
+                  << " Raising inflight_hi early return: Not cwnd limited.";
     // Not fully utilizing cwnd, so can't safely grow.
     return;
   }
 
+  if (GetQuicReloadableFlag(quic_bbr2_fix_inflight_bounds) &&
+      congestion_event.prior_cwnd < model_->inflight_hi()) {
+    QUIC_RELOADABLE_FLAG_COUNT_N(quic_bbr2_fix_inflight_bounds, 1, 2);
+    QUIC_DVLOG(3)
+        << sender_
+        << " Raising inflight_hi early return: inflight_hi not fully used.";
+    // Not fully using inflight_hi, so don't grow it.
+    return;
+  }
+
   // Increase inflight_hi by the number of probe_up_bytes within probe_up_acked.
   cycle_.probe_up_acked += congestion_event.bytes_acked;
   if (cycle_.probe_up_acked >= cycle_.probe_up_bytes) {
     uint64_t delta = cycle_.probe_up_acked / cycle_.probe_up_bytes;
     cycle_.probe_up_acked -= delta * cycle_.probe_up_bytes;
-    QUIC_DVLOG(3) << sender_ << " Rasing inflight_hi from "
-                  << model_->inflight_hi() << " to "
-                  << model_->inflight_hi() + delta * kDefaultTCPMSS
-                  << ". probe_up_bytes:" << cycle_.probe_up_bytes
-                  << ", delta:" << delta
-                  << ", (new)probe_up_acked:" << cycle_.probe_up_acked;
-    model_->set_inflight_hi(model_->inflight_hi() + delta * kDefaultTCPMSS);
+    QuicByteCount new_inflight_hi =
+        model_->inflight_hi() + delta * kDefaultTCPMSS;
+    if (new_inflight_hi > model_->inflight_hi()) {
+      QUIC_DVLOG(3) << sender_ << " Raising inflight_hi from "
+                    << model_->inflight_hi() << " to " << new_inflight_hi
+                    << ". probe_up_bytes:" << cycle_.probe_up_bytes
+                    << ", delta:" << delta
+                    << ", (new)probe_up_acked:" << cycle_.probe_up_acked;
+
+      model_->set_inflight_hi(new_inflight_hi);
+    } else {
+      QUIC_BUG << "Not growing inflight_hi due to wrap around. Old value:"
+               << model_->inflight_hi() << ", new value:" << new_inflight_hi;
+    }
   }
 
   if (congestion_event.end_of_round_trip) {
@@ -400,6 +417,10 @@
                 << congestion_event.event_time - cycle_.phase_start_time
                 << ", or " << cycle_.rounds_in_phase << " rounds.  @ "
                 << congestion_event.event_time;
+  if (GetQuicReloadableFlag(quic_bbr2_fix_inflight_bounds)) {
+    QUIC_RELOADABLE_FLAG_COUNT_N(quic_bbr2_fix_inflight_bounds, 2, 2);
+    model_->cap_inflight_lo(model_->inflight_hi());
+  }
   cycle_.phase = CyclePhase::PROBE_CRUISE;
   cycle_.rounds_in_phase = 0;
   cycle_.phase_start_time = congestion_event.event_time;