Skip to content

Commit 418c697

Browse files
authored
fix(wot): bound a trust graph rebuild and space out the rebuilds contact lists trigger (#1339)
2 parents 1b957d4 + 0aa6759 commit 418c697

10 files changed

Lines changed: 654 additions & 61 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'nostream': patch
3+
---
4+
5+
fix(wot): bound a trust graph rebuild and space out the rebuilds contact lists trigger
6+
7+
A Web of Trust rebuild read follow lists one at a time with no limit on accounts, lists or follows, and every contact list (kind 3) from an account in the graph started or queued another full rebuild. A rebuild now stops at `wot.maxPubkeys`, `wot.maxFollowListReads` or `wot.maxEdges` (defaults 500000, 10000 and 2000000), logs which limit it hit, and keeps the graph built so far, which can only trust fewer accounts, never more. Follow lists are read 100 at a time, and a `p` value that is not a 64-character hex key is no longer looked up as an author prefix. Rebuilds triggered by contact lists wait `wot.minRebuildIntervalSeconds` (default 60) after the previous one ended. A deliberate limit: a follow-list change can take up to that interval longer to reach the graph.

‎CONFIGURATION.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,12 @@ The settings below are listed in alphabetical order by name. Please keep this ta
311311
| workers.count | Number of workers to spin up to handle incoming connections. Spin workers as many CPUs are available when set to zero. Defaults to zero. |
312312
| wot.enabled | Enables the Web of Trust graph, rooted at `wot.seedPubkey`, built from NIP-02 contact lists. Defaults to false. |
313313
| wot.maxDepth | How many hops out from `wot.seedPubkey` the trust graph extends. Direct follows are distance 1. Defaults to 2. |
314+
| wot.maxEdges | Most follows one graph rebuild counts, each account a contact list names counted once per list. Defaults to 2000000. A rebuild that reaches this, `wot.maxFollowListReads` or `wot.maxPubkeys` stops, logs a warning naming the limit, and keeps the graph built up to that point: every account in it has its full-graph distance, and some accounts the full graph would trust are left out, so they get no proof-of-work discount (`limits.event.pow.wotThresholds`) and their NIP-56 reports no WoT weight until a rebuild with higher limits. Each worker builds its own graph. |
315+
| wot.maxFollowListReads | Most follow lists one graph rebuild reads (one for the seed, one for each trusted account it expands). Defaults to 10000. Reaching it stops the rebuild as described for `wot.maxEdges`. |
316+
| wot.maxPubkeys | Most distinct pubkeys one graph rebuild counts followers for, which bounds the memory it uses. Defaults to 500000. Reaching it stops the rebuild as described for `wot.maxEdges`. |
314317
| wot.minimumFollowers | Minimum number of already-trusted accounts that must follow a pubkey before it enters the graph at 2+ hops. Direct follows are always trusted. Defaults to 1. |
315-
| wot.refreshIntervalHours | Reserved for a future periodic full rebuild; not yet read by any code (real-time kind-3 ingestion already keeps the graph current). Defaults to 24. |
318+
| wot.minRebuildIntervalSeconds | Seconds a graph rebuild triggered by a contact list (kind 3) from an account in the graph waits after the previous rebuild ended; every contact list that arrives meanwhile is applied by that one rebuild, so a follow-list change can reach the graph up to this many seconds later than with `0`, which rebuilds at once. The first build, and the rebuild after a change to `wot.enabled`, `wot.seedPubkey`, `wot.maxDepth`, `wot.minimumFollowers`, `wot.maxPubkeys`, `wot.maxFollowListReads` or `wot.maxEdges`, do not wait. Defaults to 60. |
319+
| wot.refreshIntervalHours | Reserved for a future periodic full rebuild; not yet read by any code (kind-3 ingestion already triggers rebuilds, see `wot.minRebuildIntervalSeconds`). Defaults to 24. |
316320
| wot.seedPubkey | The relay owner's pubkey in hex. Root of the trust graph. Required when `wot.enabled` is true. |
317321

318322
## Peering advertisement (NIP-11)

‎resources/default-settings.yaml‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ nip66:
140140
historyRetentionHours: 0
141141
wot:
142142
# Web of Trust graph. When enabled, the relay builds a trust graph rooted
143-
# at seedPubkey from NIP-02 contact lists, updated in real time as kind-3
144-
# events arrive.
143+
# at seedPubkey from NIP-02 contact lists, and rebuilds it as kind-3
144+
# events from accounts in the graph arrive.
145145
enabled: false
146146
# The relay owner's pubkey in hex. This is the root of the trust graph.
147147
# Required when enabled is true.
@@ -151,6 +151,17 @@ wot:
151151
minimumFollowers: 1
152152
# How many hops out from seedPubkey the trust graph extends.
153153
maxDepth: 2
154+
# Limits on one rebuild. A rebuild that reaches one stops, logs which one,
155+
# and keeps the graph built so far, so it can only trust fewer accounts.
156+
# Most distinct pubkeys a rebuild counts followers for.
157+
maxPubkeys: 500000
158+
# Most follow lists a rebuild reads.
159+
maxFollowListReads: 10000
160+
# Most follows a rebuild counts (each account a list names, once).
161+
maxEdges: 2000000
162+
# Seconds a rebuild triggered by a contact list waits after the previous
163+
# rebuild ended. Updates in the meantime share one rebuild. 0 rebuilds at once.
164+
minRebuildIntervalSeconds: 60
154165
# Reserved for a future periodic rebuild; not yet read by any code.
155166
refreshIntervalHours: 24
156167
nip56:

‎src/@types/services.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ export interface IWotGraphService {
1919
*/
2020
getDistance(pubkey: Pubkey): Promise<number | undefined>
2121
isTrusted(pubkey: Pubkey): Promise<boolean>
22-
/** Applies a pubkey's current NIP-02 follow list to the graph. */
22+
/**
23+
* Stores a pubkey's current NIP-02 follow list. When it can change the
24+
* graph, a rebuild follows, at least `wot.minRebuildIntervalSeconds` after
25+
* the previous one ended.
26+
*/
2327
updateFollowList(pubkey: Pubkey, follows: Pubkey[]): Promise<void>
2428
/**
2529
* Fire-and-forget: kicks off the initial graph build without waiting on it,

‎src/@types/settings.ts‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,9 +476,24 @@ export interface WoTSettings {
476476
* Defaults to 2.
477477
*/
478478
maxDepth: number
479+
/**
480+
* Most distinct pubkeys one rebuild counts followers for. A rebuild that
481+
* reaches a limit stops, logs which one, and keeps the graph built so far.
482+
* Defaults to 500000.
483+
*/
484+
maxPubkeys: number
485+
/** Most follow lists one rebuild reads. Defaults to 10000. */
486+
maxFollowListReads: number
487+
/** Most follows one rebuild counts, each listed account once per list. Defaults to 2000000. */
488+
maxEdges: number
489+
/**
490+
* Seconds a rebuild asked for by a contact-list update waits after the
491+
* previous rebuild ended. 0 rebuilds at once. Defaults to 60.
492+
*/
493+
minRebuildIntervalSeconds: number
479494
/**
480495
* Reserved for a future periodic full consistency rebuild, on top of the
481-
* real-time updates already applied as kind-3 events are ingested. Not
496+
* rebuilds already triggered as kind-3 events are ingested. Not
482497
* yet consumed by any code — no background worker reads this field.
483498
* Defaults to 24.
484499
*/

0 commit comments

Comments
 (0)