From cd1d9d1a0db41214f1691bbc565c61d53a1bbfad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Fri, 9 Dec 2022 18:44:40 +0100 Subject: [PATCH] client: pick from old lanes probabilisticlly (#1877) * Pick from old lanes probabilisticly * changelog: update --- CHANGELOG.md | 1 + .../real_traffic_stream/transmission_buffer.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 77afb36529..7d6679628a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Post 1.0.0 release, the changelog format is based on [Keep a Changelog](https:// - validator-api: can recover from shutdown during DKG process ([#1872]) - client-core: deduplicate gateway inititialization, part of work towards a rust-sdk +- clients: keep all transmission lanes going at all times by making priority probabilistic ### Fixed diff --git a/clients/client-core/src/client/real_messages_control/real_traffic_stream/transmission_buffer.rs b/clients/client-core/src/client/real_messages_control/real_traffic_stream/transmission_buffer.rs index b47aaf470e..20c7ce6cb7 100644 --- a/clients/client-core/src/client/real_messages_control/real_traffic_stream/transmission_buffer.rs +++ b/clients/client-core/src/client/real_messages_control/real_traffic_stream/transmission_buffer.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use client_connections::TransmissionLane; -use rand::seq::SliceRandom; +use rand::{seq::SliceRandom, Rng}; use std::{ collections::{HashMap, HashSet, VecDeque}, time::Duration, @@ -116,9 +116,15 @@ impl TransmissionBuffer { lanes.choose(&mut rand::thread_rng()).copied() } + // 2/3 chance to pick from the old lanes fn pick_random_old_lane(&self) -> Option { - let lanes = self.get_oldest_set(); - lanes.choose(&mut rand::thread_rng()).copied() + let rand = &mut rand::thread_rng(); + if rand.gen_ratio(2, 3) { + let lanes = self.get_oldest_set(); + lanes.choose(rand).copied() + } else { + self.pick_random_lane().copied() + } } fn pop_front_from_lane(&mut self, lane: &TransmissionLane) -> Option {