Skip to content

Commit 8f66f70

Browse files
kalvinnchauam
andauthored
feat: raise hosted community limit to fifty (#8186)
## Summary - Raise the stock relay active ownership quota from 5 to 50 for creation and ownership transfer. Raise the absolute lifetime quota from 20 to 50 reserved hosts; completed owner deletions still permanently consume lifetime capacity to bound create/delete host squatting. - Honor the owner-list `can_create` projection across Desktop settings, create flow, and onboarding instead of imposing a client-side count. Display server `quota_used` / `quota_limit` when available; when the projection is missing, let the server's `limit_reached` decide. - Cover 49→50 and 50→51 admissions, deleted-owner lifetime exhaustion, and rendered create gates under 5/50, 0/50 exhausted, and missing projections. ## Verification - Desktop full `pnpm test` and `pnpm typecheck` pass after the 50-cap update; `cargo fmt --all -- --check` passes. Four targeted Playwright cases and `pnpm build:e2e` passed for the original dynamic-quota change at the previous commit, before changing test fixtures from 20 to 50. - `cargo test -p buzz-db --lib` cannot compile here: macOS dyld rejects the `sqlx_macros` dylib with `mis-aligned LINKEDIT string pool` on this host before the crate's tests run. CI must validate the DB package. ## Rollout / manual validation - Confirm `BUZZ_MAX_COMMUNITIES_PER_OWNER` is unset or 50 on **every** production relay replica; this per-process cached override takes precedence over the stock default. - Confirm Builderlab's list/create/transfer proxy passes the relay's `quota_used`, `quota_limit`, `can_create`, and `limit_reached` without its own 5-community gate. Its backing implementation is not in this repo and was not verified here. - Human test: with an owner at 49 live communities, create the fiftieth, verify the fifty-first returns `limit_reached`; transfer into an owner at 49 then at 50 and confirm the same boundary. Check a deleted-owner account at 0 active/50 lifetime displays the generic limit and disables creation. This manual check remains outstanding. --------- Signed-off-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz> Co-authored-by: am <6e30cd56c30e030cd31bb0939b94a7c257c9a09d5ba2d92cf2735da45629f248@buzz.block.builderlab.xyz>
1 parent a8fe2b6 commit 8f66f70

12 files changed

Lines changed: 279 additions & 47 deletions

‎crates/buzz-db/src/store/community.rs‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ mod postgres_tests {
14521452
let db = setup_db().await;
14531453
let owner = format!("{:064x}", Uuid::new_v4().as_u128());
14541454

1455-
// Fill the configured default ownership limit.
1455+
// The fiftieth create succeeds, then the fifty-first is rejected.
14561456
for i in 0..crate::relay_members::MAX_COMMUNITIES_PER_OWNER {
14571457
let host = format!("limit-test-{}-{}.example", i, Uuid::new_v4().simple());
14581458
assert!(matches!(
@@ -1463,6 +1463,16 @@ mod postgres_tests {
14631463
));
14641464
}
14651465

1466+
let page = db
1467+
.list_communities_owned_by(&owner)
1468+
.await
1469+
.expect("owner quota at fifty");
1470+
assert_eq!(
1471+
page.quota_used,
1472+
crate::relay_members::MAX_COMMUNITIES_PER_OWNER
1473+
);
1474+
assert!(!page.can_create);
1475+
14661476
let host = format!("limit-test-overflow-{}.example", Uuid::new_v4().simple());
14671477
assert_eq!(
14681478
db.create_community_with_owner(&host, &owner)
@@ -1566,7 +1576,7 @@ mod postgres_tests {
15661576
let recipient = format!("{}{}", Uuid::new_v4().simple(), Uuid::new_v4().simple());
15671577
let source_owner = format!("{}{}", Uuid::new_v4().simple(), Uuid::new_v4().simple());
15681578

1569-
for index in 0..3 {
1579+
for index in 0..(crate::relay_members::MAX_COMMUNITIES_PER_OWNER - 2) {
15701580
let host = format!("quota-live-{index}-{}.example", Uuid::new_v4().simple());
15711581
assert!(matches!(
15721582
db.create_community_with_owner(&host, &recipient)
@@ -1687,6 +1697,11 @@ mod postgres_tests {
16871697
.await
16881698
.expect("owner list at lifetime cap");
16891699
assert_eq!(page.quota_used, 0, "completed deletions free active slots");
1700+
assert_eq!(
1701+
page.quota_limit,
1702+
crate::relay_members::max_communities_per_owner(),
1703+
"active limit is shown separately"
1704+
);
16901705
assert!(!page.can_create, "the lifetime cap still blocks creation");
16911706

16921707
let host = format!("lifetime-overflow-{}.example", Uuid::new_v4().simple());

‎crates/buzz-db/src/store/relay_members.rs‎

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ pub enum ProvisionOwnerResult {
564564
/// Default maximum number of communities a single pubkey can own. Enforced at
565565
/// the relay layer — the authoritative layer — so that concurrent transfers or
566566
/// transfer-vs-create races cannot both pass a preflight count.
567-
pub const MAX_COMMUNITIES_PER_OWNER: i64 = 5;
567+
pub const MAX_COMMUNITIES_PER_OWNER: i64 = 50;
568568

569569
/// Effective per-owner community limit for this deployment.
570570
///
@@ -611,7 +611,7 @@ pub fn owner_count_advisory_lock_key(pubkey_hex: &str) -> i64 {
611611
/// communities whose tombstones permanently retain their hosts. Bounds
612612
/// create-then-delete host squatting. Absolute: it does not scale with
613613
/// `BUZZ_MAX_COMMUNITIES_PER_OWNER`.
614-
pub const MAX_LIFETIME_COMMUNITIES_PER_OWNER: i64 = 20;
614+
pub const MAX_LIFETIME_COMMUNITIES_PER_OWNER: i64 = 50;
615615

616616
/// One owner's quota usage, read inside the admitting transaction.
617617
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -1307,7 +1307,8 @@ mod postgres_tests {
13071307
fn owner_limit_defaults_when_unset_or_invalid() {
13081308
assert_eq!(
13091309
super::effective_owner_limit(None),
1310-
super::MAX_COMMUNITIES_PER_OWNER
1310+
50,
1311+
"stock deployment permits 50 active communities"
13111312
);
13121313
assert_eq!(
13131314
super::effective_owner_limit(Some("not-a-number")),
@@ -1751,34 +1752,66 @@ mod postgres_tests {
17511752
let owner = test_pubkey();
17521753
let transferee = test_pubkey();
17531754

1754-
// Fill the configured default ownership limit.
1755-
for _ in 0..MAX_COMMUNITIES_PER_OWNER {
1755+
// At 49 ownerships, the fiftieth transfer succeeds; at 50, the
1756+
// fifty-first is rejected by the same transaction-side admission.
1757+
for _ in 0..(MAX_COMMUNITIES_PER_OWNER - 1) {
17561758
let c = make_test_community(&pool).await;
17571759
bootstrap_owner(&pool, c, &transferee)
17581760
.await
17591761
.expect("bootstrap transferee community");
17601762
}
17611763

1762-
// Create a community owned by `owner` and try to transfer to `transferee`.
1763-
let community = make_test_community(&pool).await;
1764-
bootstrap_owner(&pool, community, &owner)
1764+
let fiftieth = make_test_community(&pool).await;
1765+
bootstrap_owner(&pool, fiftieth, &owner)
17651766
.await
17661767
.expect("bootstrap owner");
1768+
assert!(matches!(
1769+
transfer_ownership(&pool, fiftieth, &transferee, &owner)
1770+
.await
1771+
.expect("fiftieth transfer"),
1772+
TransferResult::Transferred { .. }
1773+
));
1774+
assert_eq!(
1775+
get_relay_member(&pool, fiftieth, &transferee)
1776+
.await
1777+
.expect("get transferee")
1778+
.expect("exists")
1779+
.role,
1780+
"owner"
1781+
);
1782+
assert_eq!(
1783+
get_relay_member(&pool, fiftieth, &owner)
1784+
.await
1785+
.expect("get previous owner")
1786+
.expect("exists")
1787+
.role,
1788+
"member"
1789+
);
17671790

1768-
let result = transfer_ownership(&pool, community, &transferee, &owner)
1791+
let fifty_first = make_test_community(&pool).await;
1792+
bootstrap_owner(&pool, fifty_first, &owner)
17691793
.await
1770-
.expect("transfer to maxed transferee");
1771-
1772-
assert_eq!(result, TransferResult::LimitReached);
1773-
1774-
// Owner is still owner — transfer did not happen.
1794+
.expect("bootstrap owner");
1795+
assert_eq!(
1796+
transfer_ownership(&pool, fifty_first, &transferee, &owner)
1797+
.await
1798+
.expect("fifty-first transfer"),
1799+
TransferResult::LimitReached
1800+
);
17751801
assert_eq!(
1776-
get_relay_member(&pool, community, &owner)
1802+
get_relay_member(&pool, fifty_first, &owner)
17771803
.await
17781804
.expect("get owner")
17791805
.expect("exists")
17801806
.role,
17811807
"owner"
17821808
);
1809+
assert!(
1810+
get_relay_member(&pool, fifty_first, &transferee)
1811+
.await
1812+
.expect("get transferee")
1813+
.is_none(),
1814+
"rejected transfer must not add transferee"
1815+
);
17831816
}
17841817
}

‎desktop/src/features/communities/hostedCommunityApi.test.mjs‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import test from "node:test";
1414
import { npubEncode } from "nostr-tools/nip19";
1515

1616
import {
17+
hostedCommunityErrorMessage,
18+
hostedCommunityQuotaLimit,
19+
hostedCommunityQuotaUsed,
1720
normalizedBoundKeyHex,
1821
usableBoundIdentityNpub,
1922
} from "./hostedCommunityApi.ts";
@@ -96,3 +99,27 @@ test("the string normalizer rejects the same non-key values directly", () => {
9699
assert.equal(normalizedBoundKeyHex("f".repeat(65)), null);
97100
assert.equal(normalizedBoundKeyHex(" "), null);
98101
});
102+
103+
test("quota used accepts zero but rejects missing and invalid projections", () => {
104+
assert.equal(hostedCommunityQuotaUsed(undefined), null);
105+
assert.equal(hostedCommunityQuotaUsed(-1), null);
106+
assert.equal(hostedCommunityQuotaUsed(0), 0);
107+
assert.equal(hostedCommunityQuotaUsed(49), 49);
108+
assert.equal(hostedCommunityQuotaUsed(1.5), null);
109+
assert.equal(hostedCommunityQuotaUsed(Number.MAX_SAFE_INTEGER + 1), null);
110+
});
111+
112+
test("quota projection never invents a fixed client limit", () => {
113+
assert.equal(hostedCommunityQuotaLimit(undefined), null);
114+
assert.equal(hostedCommunityQuotaLimit(0), null);
115+
assert.equal(hostedCommunityQuotaLimit(5), 5);
116+
assert.equal(hostedCommunityQuotaLimit(50), 50);
117+
assert.equal(
118+
hostedCommunityErrorMessage(
119+
{ code: "limit_reached" },
120+
undefined,
121+
"fallback",
122+
),
123+
"You’ve reached your hosted community creation limit.",
124+
);
125+
});

‎desktop/src/features/communities/hostedCommunityApi.ts‎

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { invoke } from "@tauri-apps/api/core";
33
import { safeNpub } from "@/shared/lib/nostrUtils";
44

55
export const HOSTED_COMMUNITY_SUFFIX = "communities.buzz.xyz";
6-
export const HOSTED_COMMUNITY_LIMIT = 5;
76
export const VALID_HOSTED_COMMUNITY_NAME = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
87

98
export type BuilderlabAuth = {
@@ -40,6 +39,9 @@ export type HostedCommunity = {
4039

4140
export type HostedCommunitiesResponse = {
4241
communities?: HostedCommunity[];
42+
quota_used?: number;
43+
quota_limit?: number;
44+
can_create?: boolean;
4345
error?: HostedCommunityApiError;
4446
correlation_id?: string;
4547
};
@@ -59,9 +61,27 @@ export type HostedCommunityMutationResponse = {
5961

6062
export type HostedCommunityAccount = {
6163
communities: HostedCommunity[];
64+
canCreate: boolean;
6265
identity: HostedNostrIdentity | null;
6366
};
6467

68+
/** A missing projection must not invent a client-side quota; create remains server-authoritative. */
69+
export function hostedCommunityQuotaLimit(
70+
value: number | undefined,
71+
): number | null {
72+
return typeof value === "number" && Number.isSafeInteger(value) && value > 0
73+
? value
74+
: null;
75+
}
76+
77+
export function hostedCommunityQuotaUsed(
78+
value: number | undefined,
79+
): number | null {
80+
return typeof value === "number" && Number.isSafeInteger(value) && value >= 0
81+
? value
82+
: null;
83+
}
84+
6585
export function hostedCommunityErrorMessage(
6686
error: HostedCommunityApiError | undefined,
6787
correlationId: string | undefined,
@@ -71,7 +91,7 @@ export function hostedCommunityErrorMessage(
7191
missing_mapping: "Connect your Buzz identity before creating a community.",
7292
invalid_name: "Use lowercase letters, numbers, and hyphens.",
7393
taken: "That Buzz address is already taken.",
74-
limit_reached: `You've reached the limit of ${HOSTED_COMMUNITY_LIMIT} hosted communities.`,
94+
limit_reached: "You’ve reached your hosted community creation limit.",
7595
relay_unavailable: "Community provisioning is temporarily unavailable.",
7696
identity_already_bound:
7797
"This Builderlab account is connected to another Buzz identity.",
@@ -187,6 +207,7 @@ export async function loadHostedCommunityAccount(): Promise<HostedCommunityAccou
187207
return {
188208
identity: identityResponse.identity ?? null,
189209
communities: communitiesResponse.communities ?? [],
210+
canCreate: communitiesResponse.can_create !== false,
190211
};
191212
}
192213

‎desktop/src/features/communities/ui/HostedCommunityCreateFlow.tsx‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import {
99
createHostedCommunity,
1010
deleteBuilderlabIdentity,
1111
getBuilderlabAuth,
12-
HOSTED_COMMUNITY_LIMIT,
1312
HOSTED_COMMUNITY_SUFFIX,
1413
hostedCommunityErrorMessage,
1514
hostedCommunityRelayUrl,
@@ -19,7 +18,6 @@ import {
1918
usableBoundIdentityNpub,
2019
VALID_HOSTED_COMMUNITY_NAME,
2120
type BuilderlabAuth,
22-
type HostedCommunity,
2321
type HostedNostrIdentity,
2422
} from "@/features/communities/hostedCommunityApi";
2523
import { useCommunityOnboarding } from "@/features/onboarding/communityOnboarding";
@@ -47,7 +45,7 @@ export function HostedCommunityCreateFlow({
4745
const [identity, setIdentity] = React.useState<HostedNostrIdentity | null>(
4846
null,
4947
);
50-
const [communities, setCommunities] = React.useState<HostedCommunity[]>([]);
48+
const [canCreate, setCanCreate] = React.useState(true);
5149
const [name, setName] = React.useState("");
5250
const [availability, setAvailability] = React.useState<boolean | null>(null);
5351
const [checkingName, setCheckingName] = React.useState(false);
@@ -60,7 +58,7 @@ export function HostedCommunityCreateFlow({
6058
const loadAccount = React.useCallback(async () => {
6159
const account = await loadHostedCommunityAccount();
6260
setIdentity(account.identity);
63-
setCommunities(account.communities);
61+
setCanCreate(account.canCreate);
6462
}, []);
6563

6664
React.useEffect(() => {
@@ -147,7 +145,7 @@ export function HostedCommunityCreateFlow({
147145
await clearBuilderlabAuth();
148146
setAuth(null);
149147
setIdentity(null);
150-
setCommunities([]);
148+
setCanCreate(true);
151149
});
152150

153151
// Identity rows display npubs derived from the same key the mismatch gate
@@ -209,7 +207,7 @@ export function HostedCommunityCreateFlow({
209207
const validName =
210208
normalizedName.length <= 63 &&
211209
VALID_HOSTED_COMMUNITY_NAME.test(normalizedName);
212-
const atCommunityLimit = communities.length >= HOSTED_COMMUNITY_LIMIT;
210+
const atCommunityLimit = !canCreate;
213211
const ready = Boolean(auth && usableBoundIdentity && !identityMismatch);
214212

215213
React.useEffect(() => {
@@ -400,7 +398,7 @@ export function HostedCommunityCreateFlow({
400398
}
401399

402400
const feedback = atCommunityLimit
403-
? `You’ve reached the limit of ${HOSTED_COMMUNITY_LIMIT} hosted communities.`
401+
? "You’ve reached your hosted community creation limit."
404402
: name && !validName
405403
? "Use lowercase letters, numbers, and single hyphens."
406404
: checkingName

‎desktop/src/features/communities/ui/HostedCommunityOnboarding.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
createHostedCommunity,
1111
deleteBuilderlabIdentity,
1212
getBuilderlabAuth,
13-
HOSTED_COMMUNITY_LIMIT,
1413
HOSTED_COMMUNITY_SUFFIX,
1514
hostedCommunityErrorMessage,
1615
hostedCommunityRelayUrl,
@@ -87,6 +86,7 @@ export function HostedCommunityOnboarding({
8786
null,
8887
);
8988
const [communities, setCommunities] = React.useState<HostedCommunity[]>([]);
89+
const [canCreate, setCanCreate] = React.useState(true);
9090
const [showCreate, setShowCreate] = React.useState(false);
9191
const [name, setName] = React.useState("");
9292
const [availability, setAvailability] = React.useState<boolean | null>(null);
@@ -100,6 +100,7 @@ export function HostedCommunityOnboarding({
100100
const account = await loadHostedCommunityAccount();
101101
setIdentity(account.identity);
102102
setCommunities(account.communities);
103+
setCanCreate(account.canCreate);
103104
}, []);
104105

105106
React.useEffect(() => {
@@ -170,6 +171,7 @@ export function HostedCommunityOnboarding({
170171
setAuth(null);
171172
setIdentity(null);
172173
setCommunities([]);
174+
setCanCreate(true);
173175
setShowCreate(false);
174176
setName("");
175177
setAvailability(null);
@@ -259,7 +261,7 @@ export function HostedCommunityOnboarding({
259261
const validName =
260262
normalizedName.length <= 63 &&
261263
VALID_HOSTED_COMMUNITY_NAME.test(normalizedName);
262-
const atCommunityLimit = communities.length >= HOSTED_COMMUNITY_LIMIT;
264+
const atCommunityLimit = !canCreate;
263265
const hasCommunities = activeCommunities.length > 0;
264266

265267
React.useEffect(() => {
@@ -385,7 +387,7 @@ export function HostedCommunityOnboarding({
385387
) : null;
386388

387389
const creationFeedback = atCommunityLimit
388-
? `You’ve reached the limit of ${HOSTED_COMMUNITY_LIMIT} hosted communities.`
390+
? "You’ve reached your hosted community creation limit."
389391
: name && !validName
390392
? "Use lowercase letters, numbers, and single hyphens."
391393
: checkingName

0 commit comments

Comments
 (0)