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();