client: pick from old lanes probabilisticlly (#1877)

* Pick from old lanes probabilisticly

* changelog: update
This commit is contained in:
Jon Häggblad
2022-12-09 18:44:40 +01:00
committed by GitHub
parent b694e675e6
commit cd1d9d1a0d
2 changed files with 10 additions and 3 deletions
+1
View File
@@ -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
@@ -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<TransmissionLane> {
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<RealMessage> {