Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/wot-bound-graph-rebuilds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'nostream': patch
---

fix(wot): bound a trust graph rebuild and space out the rebuilds contact lists trigger

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.
6 changes: 5 additions & 1 deletion CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,12 @@ The settings below are listed in alphabetical order by name. Please keep this ta
| 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. |
| wot.enabled | Enables the Web of Trust graph, rooted at `wot.seedPubkey`, built from NIP-02 contact lists. Defaults to false. |
| wot.maxDepth | How many hops out from `wot.seedPubkey` the trust graph extends. Direct follows are distance 1. Defaults to 2. |
| 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. |
| 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`. |
| 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`. |
| 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. |
| 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. |
| 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. |
| 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. |
| wot.seedPubkey | The relay owner's pubkey in hex. Root of the trust graph. Required when `wot.enabled` is true. |

## Peering advertisement (NIP-11)
Expand Down
15 changes: 13 additions & 2 deletions resources/default-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ nip66:
historyRetentionHours: 0
wot:
# Web of Trust graph. When enabled, the relay builds a trust graph rooted
# at seedPubkey from NIP-02 contact lists, updated in real time as kind-3
# events arrive.
# at seedPubkey from NIP-02 contact lists, and rebuilds it as kind-3
# events from accounts in the graph arrive.
enabled: false
# The relay owner's pubkey in hex. This is the root of the trust graph.
# Required when enabled is true.
Expand All @@ -151,6 +151,17 @@ wot:
minimumFollowers: 1
# How many hops out from seedPubkey the trust graph extends.
maxDepth: 2
# Limits on one rebuild. A rebuild that reaches one stops, logs which one,
# and keeps the graph built so far, so it can only trust fewer accounts.
# Most distinct pubkeys a rebuild counts followers for.
maxPubkeys: 500000
# Most follow lists a rebuild reads.
maxFollowListReads: 10000
# Most follows a rebuild counts (each account a list names, once).
maxEdges: 2000000
# Seconds a rebuild triggered by a contact list waits after the previous
# rebuild ended. Updates in the meantime share one rebuild. 0 rebuilds at once.
minRebuildIntervalSeconds: 60
# Reserved for a future periodic rebuild; not yet read by any code.
refreshIntervalHours: 24
nip56:
Expand Down
6 changes: 5 additions & 1 deletion src/@types/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export interface IWotGraphService {
*/
getDistance(pubkey: Pubkey): Promise<number | undefined>
isTrusted(pubkey: Pubkey): Promise<boolean>
/** Applies a pubkey's current NIP-02 follow list to the graph. */
/**
* Stores a pubkey's current NIP-02 follow list. When it can change the
* graph, a rebuild follows, at least `wot.minRebuildIntervalSeconds` after
* the previous one ended.
*/
updateFollowList(pubkey: Pubkey, follows: Pubkey[]): Promise<void>
/**
* Fire-and-forget: kicks off the initial graph build without waiting on it,
Expand Down
17 changes: 16 additions & 1 deletion src/@types/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -476,9 +476,24 @@ export interface WoTSettings {
* Defaults to 2.
*/
maxDepth: number
/**
* Most distinct pubkeys one rebuild counts followers for. A rebuild that
* reaches a limit stops, logs which one, and keeps the graph built so far.
* Defaults to 500000.
*/
maxPubkeys: number
/** Most follow lists one rebuild reads. Defaults to 10000. */
maxFollowListReads: number
/** Most follows one rebuild counts, each listed account once per list. Defaults to 2000000. */
maxEdges: number
/**
* Seconds a rebuild asked for by a contact-list update waits after the
* previous rebuild ended. 0 rebuilds at once. Defaults to 60.
*/
minRebuildIntervalSeconds: number
/**
* Reserved for a future periodic full consistency rebuild, on top of the
* real-time updates already applied as kind-3 events are ingested. Not
* rebuilds already triggered as kind-3 events are ingested. Not
* yet consumed by any code — no background worker reads this field.
* Defaults to 24.
*/
Expand Down
Loading
Loading