From 420d3be4bda7ee348d4cbbbc05903e5b0ff8caf2 Mon Sep 17 00:00:00 2001 From: onyinyang Date: Tue, 23 Jan 2024 17:38:21 -0500 Subject: [PATCH] Fixes last open invite bucket distribution --- crates/lox-library/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/crates/lox-library/src/lib.rs b/crates/lox-library/src/lib.rs index 16027ca..7ac891e 100644 --- a/crates/lox-library/src/lib.rs +++ b/crates/lox-library/src/lib.rs @@ -156,6 +156,7 @@ pub struct BridgeDb { pub pubkey: VerifyingKey, /// The set of open-invitation buckets openinv_buckets: HashSet, + /// The set of open invitation buckets that have been distributed distributed_buckets: Vec, #[serde(skip)] today: DateTime, @@ -229,14 +230,14 @@ impl BridgeDb { self.today = Utc::now(); self.daily_bridges_distributed = 0; } - if self.openinv_buckets.is_empty() { - return Err(OpenInvitationError::NoBridgesAvailable); - } if self.daily_bridges_distributed < MAX_DAILY_BRIDGES { if self.current_k < OPENINV_K && !self.distributed_buckets.is_empty() { bucket_num = *self.distributed_buckets.last().unwrap(); self.current_k += 1; } else { + if self.openinv_buckets.is_empty() { + return Err(OpenInvitationError::NoBridgesAvailable); + } // Choose a random bucket number (from the set of open // invitation buckets) and serialize it let openinv_vec: Vec<&u32> = self.openinv_buckets.iter().collect();