fix(nip46): put Amber-friendly fallback relays first in the QR; warn about unreachable user relays - #75
Merged
Conversation
…about unreachable user relays After PR #74 the QR URI Amber sees includes nostr.wine + relay.damus.io as fallbacks, but they came AFTER the user's configured relays. Amber picks the first relay in the URI list to publish the connect ack to, so when the user's relays.txt started with a dead or unreachable host (e.g. relay.nostr.band, which has been offline for over a year, or purplerelay.com, which returns HTTP 302), Amber picked THAT one and failed to publish with 'websocket error' — even though hoot was subscribed to a perfectly good fallback that Amber never tried. Two changes: - PairingRelays now orders fallback relays FIRST and user relays after. Signers that pick the URI's first listed relay will pick a known-alive fallback, the publish will succeed, and the connect ack will arrive. The previously-documented TestPairingRelaysPreservesUserOrder is replaced with TestPairingRelaysFallbacksFirst that pins the new ordering. - ConnectRelays now logs a one-line stderr warning for any user-configured relay that didn't come up during the dial. Format: hoot: 2 configured relay(s) unreachable, Amber may fail to publish to them: wss://relay.example.dead, wss://other. Edit ~/.config/hoot/relays.txt (or ./relays.txt) to remove them. Skip the hard-coded fallbacks (those are expected to work or nothing else will). The warning fires once at QR time so the user knows their relays.txt is stale without having to wait for Amber to fail. Tests: - TestPairingRelaysFallbacksFirst (replaces TestPairingRelaysPreservesUserOrder). - TestWarnUnreachableRelays exercises the warning function and asserts the log line format.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
After PR #74, the QR URI Amber sees includes
wss://nostr.wineandwss://relay.damus.ioas fallbacks, but they came AFTER the user's configured relays. Amber picks the first relay in the URI list to publish the connect ack to. When the user'srelays.txtstarts with a dead or unreachable host, Amber picks that one and fails withwebsocket error— even though hoot is subscribed to perfectly good fallbacks that Amber never tries.Concretely the user's
relays.txtwas:Amber picked
wss://purplerelay.com/, the websocket failed, and Amber showed the user "websocket error".Fix
Two changes in
nip46/nip46.go:PairingRelaysnow puts fallback relays first, user relays second. Signers that pick the URI's first listed relay will pick a known-alive fallback. The dedup behaviour is unchanged.ConnectRelaysnow logs a one-line stderr warning for any user-configured relay that didn't come up during the dial. Example:Falls back fire only for user relays, never for the hard-coded fallbacks (those are expected to work).
Tests
TestPairingRelaysFallbacksFirst(replacesTestPairingRelaysPreservesUserOrder— user relays no longer come first, fallbacks do).TestWarnUnreachableRelaysexercises the warning function and asserts the log-line format.CI: 7/7 (test + 6 cross-platform builds).