Fixes last open invite bucket distribution

This commit is contained in:
onyinyang 2024-01-23 17:38:21 -05:00
parent 906577f6a8
commit 420d3be4bd
1 changed files with 4 additions and 3 deletions

View File

@ -156,6 +156,7 @@ pub struct BridgeDb {
pub pubkey: VerifyingKey,
/// The set of open-invitation buckets
openinv_buckets: HashSet<u32>,
/// The set of open invitation buckets that have been distributed
distributed_buckets: Vec<u32>,
#[serde(skip)]
today: DateTime<Utc>,
@ -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();