Repository navigation
feat(admin): NIP-11 vs probe mismatch warnings on Network Health #799
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "nostream": minor | ||
| --- | ||
|
|
||
| feat(admin): add NIP-11 vs probe mismatch warnings on Network Health | ||
|
|
||
| Closes #798 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| import { StoredProbeResult } from '../@types/relay-probe-snapshot' | ||
| import { normalizeRelayUrlForDTag } from './nip66-events' | ||
|
|
||
| export type NetworkHealthMismatchSeverity = 'warning' | 'info' | ||
|
|
||
| export interface NetworkHealthMismatch { | ||
| code: string | ||
| severity: NetworkHealthMismatchSeverity | ||
| message: string | ||
| } | ||
|
|
||
| export interface NetworkHealthMismatchContext { | ||
| configuredRelayUrl?: string | ||
| /** Normalized keys from resolvePublicProbeTargetKeys (publish/probe set). */ | ||
| publicTargetKeys?: Set<string> | ||
| } | ||
|
|
||
| const normalizeRelayUrlOrUndefined = (relayUrl: string | undefined): string | undefined => { | ||
| if (!relayUrl?.trim()) { | ||
| return undefined | ||
| } | ||
|
|
||
| try { | ||
| return normalizeRelayUrlForDTag(relayUrl.trim()) | ||
| } catch { | ||
| return undefined | ||
| } | ||
| } | ||
|
|
||
| export const collectNetworkHealthMismatches = ( | ||
| result: StoredProbeResult, | ||
| context: NetworkHealthMismatchContext = {}, | ||
| ): NetworkHealthMismatch[] => { | ||
| const mismatches: NetworkHealthMismatch[] = [] | ||
| const nip11 = result.nip11.status === 'ok' ? result.nip11.data : undefined | ||
| const ws = result.wsRtt.status === 'ok' ? result.wsRtt.data : undefined | ||
| const limitation = nip11?.limitation | ||
|
|
||
| if (nip11 && Array.isArray(nip11.supportedNips) && !nip11.supportedNips.includes(66)) { | ||
| mismatches.push({ | ||
| code: 'nip66-not-advertised', | ||
| severity: 'warning', | ||
| message: 'NIP-11 supported_nips does not include 66 while this relay publishes NIP-66 monitor data.', | ||
| }) | ||
| } | ||
|
|
||
| const configuredKey = normalizeRelayUrlOrUndefined(context.configuredRelayUrl) | ||
| const probedKey = normalizeRelayUrlOrUndefined(result.target.relayUrl) | ||
| const singlePublicTarget = | ||
| context.publicTargetKeys?.size === 1 && configuredKey && context.publicTargetKeys.has(configuredKey) | ||
|
|
||
| if (singlePublicTarget && configuredKey && probedKey && probedKey !== configuredKey) { | ||
|
Ferryx349 marked this conversation as resolved.
Outdated
|
||
| mismatches.push({ | ||
| code: 'public-url', | ||
| severity: 'warning', | ||
| message: `Probe target ${result.target.relayUrl} does not match info.relay_url (${context.configuredRelayUrl}).`, | ||
| }) | ||
| } | ||
|
|
||
| if (nip11 && ws) { | ||
| const advertisesAuth = limitation?.authRequired === true | ||
| const observedAuth = ws.nip42AuthRequired === true || ws.nip42ChallengeObserved === true | ||
|
|
||
| if (advertisesAuth && !observedAuth) { | ||
| mismatches.push({ | ||
| code: 'nip42-not-observed', | ||
| severity: 'warning', | ||
| message: 'NIP-11 advertises auth-required but the WebSocket probe did not observe NIP-42.', | ||
| }) | ||
| } | ||
|
|
||
| if (!advertisesAuth && observedAuth) { | ||
| mismatches.push({ | ||
| code: 'nip42-not-advertised', | ||
| severity: 'warning', | ||
| message: 'WebSocket probe observed NIP-42 but NIP-11 does not advertise auth-required.', | ||
|
Ferryx349 marked this conversation as resolved.
Outdated
|
||
| }) | ||
| } | ||
| } | ||
|
|
||
| if (nip11 && typeof limitation?.minPowDifficulty === 'number' && limitation.minPowDifficulty > 0) { | ||
| mismatches.push({ | ||
| code: 'pow-advertised', | ||
| severity: 'info', | ||
| message: `NIP-11 advertises min PoW difficulty ${limitation.minPowDifficulty}; probes do not validate PoW on publish.`, | ||
| }) | ||
| } | ||
|
|
||
| if (nip11 && limitation?.paymentRequired === true) { | ||
| mismatches.push({ | ||
| code: 'payment-advertised', | ||
| severity: 'info', | ||
| message: 'NIP-11 advertises payment-required; confirm fee/admission settings match operator expectations.', | ||
| }) | ||
| } | ||
|
|
||
| return mismatches | ||
| } | ||
|
|
||
| export const enrichSnapshotWithMismatches = <T extends { results: StoredProbeResult[] }>( | ||
| snapshot: T, | ||
| context: NetworkHealthMismatchContext, | ||
| ): T & { results: Array<StoredProbeResult & { mismatches: NetworkHealthMismatch[] }> } => { | ||
| return { | ||
| ...snapshot, | ||
| results: snapshot.results.map((result) => ({ | ||
| ...result, | ||
| mismatches: collectNetworkHealthMismatches(result, context), | ||
| })), | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.