mirror of
https://github.com/block/buzz.git
synced 2026-10-28 21:11:48 +00:00
fix(db): make the lifetime owner cap absolute and rustfmt the quota test
Signed-off-by: Elrond <28d6302a099e5225b02c4155ac4236e4912603df2ab08dbfc2f4fef08ce598c8@buzz.block.builderlab.xyz>
This commit is contained in:
@@ -606,7 +606,8 @@ pub fn owner_count_advisory_lock_key(pubkey_hex: &str) -> i64 {
|
||||
|
||||
/// Lifetime cap on communities a pubkey may own, counting owner-deleted
|
||||
/// communities whose tombstones permanently retain their hosts. Bounds
|
||||
/// create-then-delete host squatting; never below the active limit.
|
||||
/// create-then-delete host squatting. Absolute: it does not scale with
|
||||
/// `BUZZ_MAX_COMMUNITIES_PER_OWNER`.
|
||||
pub const MAX_LIFETIME_COMMUNITIES_PER_OWNER: i64 = 20;
|
||||
|
||||
/// One owner's quota usage, read inside the admitting transaction.
|
||||
@@ -621,8 +622,8 @@ pub(crate) struct OwnerQuota {
|
||||
impl OwnerQuota {
|
||||
/// Whether this owner may gain one more community.
|
||||
pub fn admits(self) -> bool {
|
||||
let limit = max_communities_per_owner();
|
||||
self.active < limit && self.lifetime < MAX_LIFETIME_COMMUNITIES_PER_OWNER.max(limit)
|
||||
self.active < max_communities_per_owner()
|
||||
&& self.lifetime < MAX_LIFETIME_COMMUNITIES_PER_OWNER
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1307,11 +1308,14 @@ mod postgres_tests {
|
||||
fn owner_quota_admits_only_under_active_and_lifetime_caps() {
|
||||
let quota = |active, lifetime| super::OwnerQuota { active, lifetime };
|
||||
let limit = super::max_communities_per_owner();
|
||||
let lifetime = super::MAX_LIFETIME_COMMUNITIES_PER_OWNER.max(limit);
|
||||
let lifetime = super::MAX_LIFETIME_COMMUNITIES_PER_OWNER;
|
||||
assert!(quota(0, 0).admits());
|
||||
assert!(quota(limit - 1, lifetime - 1).admits());
|
||||
assert!(!quota(limit, limit).admits(), "active cap");
|
||||
assert!(!quota(0, lifetime).admits(), "tombstones count toward lifetime");
|
||||
assert!(
|
||||
!quota(0, lifetime).admits(),
|
||||
"tombstones count toward lifetime"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -166,7 +166,7 @@ The relay enforces two per-owner caps on create and on transfer-in, both as
|
||||
(`BUZZ_MAX_COMMUNITIES_PER_OWNER`, default 5). A deletion keeps its slot
|
||||
until logical completion records `completed_at`.
|
||||
- **Lifetime:** live ownership plus every non-aborted owner deletion, including
|
||||
completed ones, capped at 20 (or the active limit if that is higher).
|
||||
completed ones, capped at an absolute 20 regardless of the active limit.
|
||||
Deleted communities keep their hosts as permanent tombstones, so this bounds
|
||||
create-then-delete host squatting. Aborted deletions restore the community
|
||||
and count only through its live membership.
|
||||
|
||||
Reference in New Issue
Block a user