Skip to content

fix(nip46): put Amber-friendly fallback relays first in the QR; warn about unreachable user relays - #75

Merged
oth-body merged 1 commit into
masterfrom
fix/nip46-fallbacks-first-ordering
Sep 15, 2026
Merged

oth-body merged 1 commit into
masterfrom
fix/nip46-fallbacks-first-ordering

Conversation

@oth-body

Copy link
Copy Markdown
Owner

Summary

After PR #74, the QR URI Amber sees includes wss://nostr.wine and wss://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. When the user's relays.txt starts with a dead or unreachable host, Amber picks that one and fails with websocket error — even though hoot is subscribed to perfectly good fallbacks that Amber never tries.

Concretely the user's relays.txt was:

wss://purplerelay.com/    # HTTP 302 — not a Nostr relay
wss://nos.lol/             # Cloudflare 502 to non-browser requests
wss://relay.damus.io       # OK
wss://relay.nostr.band     # DEAD for >1 year (per nostr.band monitoring)

Amber picked wss://purplerelay.com/, the websocket failed, and Amber showed the user "websocket error".

Fix

Two changes in nip46/nip46.go:

  1. PairingRelays now 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.

  2. ConnectRelays now logs a one-line stderr warning for any user-configured relay that didn't come up during the dial. Example:

    hoot: 2 configured relay(s) unreachable, Amber may fail to publish to them: wss://relay.example.dead, wss://other.example. Edit ~/.config/hoot/relays.txt (or ./relays.txt) to remove them.
    

    Falls back fire only for user relays, never for the hard-coded fallbacks (those are expected to work).

Tests

  • TestPairingRelaysFallbacksFirst (replaces TestPairingRelaysPreservesUserOrder — user relays no longer come first, fallbacks do).
  • TestWarnUnreachableRelays exercises the warning function and asserts the log-line format.

CI: 7/7 (test + 6 cross-platform builds).

…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.
@oth-body
oth-body merged commit a7e98b4 into master Sep 15, 2026
7 checks passed
@oth-body
oth-body deleted the fix/nip46-fallbacks-first-ordering branch September 15, 2026 17:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant