Skip to content

swapserver_gui: announce over nostr immediately on start - #1

Merged
nothing-stops-this-train merged 1 commit into
mainfrom
fix/nostr-swap-announce-on-start
Jul 7, 2026
Merged

swapserver_gui: announce over nostr immediately on start#1
nothing-stops-this-train merged 1 commit into
mainfrom
fix/nostr-swap-announce-on-start

Conversation

@nothing-stops-this-train

Copy link
Copy Markdown
Owner

Problem

A freshly-started swap server is undiscoverable over nostr for up to ~10 minutes,
so takers hit "no swap providers found" right after the server comes up.

SwapManager.run_nostr_server only emits its first announcement after
OFFER_UPDATE_INTERVAL_SEC (~10 min) when liquidity hasn't changed since the loop
started, and it keeps its NostrTransport private, so nothing can trigger an
earlier publish.

Fix

Add publish_now() to the plugin: a non-blocking helper (safe to call from the Qt
GUI thread) that spins up a short-lived NostrTransport with the server's nostr
keypair — the same pattern the client uses in get_submarine_swap_providers
waits until there is liquidity to advertise, publishes a single offer, and tears
the transport down.

It is called at the end of start_server() so the offer is live within seconds of
the server starting (instead of up to ~10 min later). It doubles as an explicit
"announce now" hook. stop_server() cancels it.

The liquidity wait matters because a server can start before its channels are
funded; publish_offer refuses to announce with no liquidity, so we poll
server_update_pairs (bounded) until there is some, then announce immediately.

Tests

PublishNowTests covers:

  • start_server() announces immediately once liquidity is present,
  • publish waits for liquidity and fires as soon as it appears,
  • no-op when the server is stopped or has no nostr keypair.

All plugin tests pass (python3 -m pytest tests/test_swapserver_gui.py).

run_nostr_server only emits its first announcement after
OFFER_UPDATE_INTERVAL_SEC (~10 min) when liquidity is unchanged, so a
freshly-started server is undiscoverable by takers for that window
(they see "no swap providers found").

Add publish_now(), a non-blocking helper that spins up a short-lived
NostrTransport with the server's nostr keypair, waits until there is
liquidity to advertise, publishes a single offer, and tears the
transport down. It is called at the end of start_server() so the offer
is live within seconds of the server coming up, and is also usable as
an explicit "announce now" action.

Add PublishNowTests covering immediate announce, waiting for liquidity,
and the no-op paths (server stopped / no nostr keypair).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@nothing-stops-this-train
nothing-stops-this-train merged commit 7f0d0f6 into main Jul 7, 2026
1 check passed
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