Skip to content

payments: an NWC wallet's fast reply is lost because the request is published after the subscription #1099

Closed

Description

@chappie-daemon

Found by the round-9 static review of #870 (PR #1094). Pre-existing on rewrite/main at 68be6f3: the file is untouched by that PR.

The mechanism

crates/nostream-services/src/payments/processors/nwc_relay.rs:147-158 sends the two frames in this order:

let event_frame = serde_json::json!(["EVENT", event]);
let request_frame = serde_json::json!(["REQ", subscription, subscription_filter]);

for frame in [event_frame, request_frame] { socket.send(...).await?; }

EVENT goes out before REQ, so the wallet can answer in the window where this client holds no subscription. NIP-47's reply is kind 23195, which is live-forwarded and not stored, so the reply is not delayed for us: it is gone, and the payment call blocks until the request times out.

The window is small but not theoretical: a self-hosted wallet on the same relay is one hop away, and the reply is published the moment the request is decrypted.

What a fix needs

Send request_frame first, then event_frame, then read. A regression test needs a relay double that publishes the reply as soon as it sees the EVENT, and asserts the client's REQ was already registered — a plain ordering assertion on the two frames would pass before the fix if it only checked both were sent.

Activity

  1. chappie-daemon commented on Nov 10, 2026

    @chappie-daemon
    CollaboratorAuthor

    PR open: #1104 — factory/026-nwc-req-before-event at cce07fb, base rewrite/main.

    This issue stays open: the base is not the repository default branch, so no keyword can close it — it is closed by hand after the merge.

  2. added
    rewritenostream 4.0 Rust/LMDB rewrite
    rustRust implementation work
    factoryBuilt by the software factory
    on Nov 10, 2026
  3. chappie-daemon commented on Nov 10, 2026

    @chappie-daemon
    CollaboratorAuthor

    Fixed by #1104, merged as 2c151f2aa4a9460d5f70ca89ee5ccdbf420f62d7 into rewrite/main (true merge of 4adaa42 + cce07fb; tree byte-identical to the reviewed head).

    nwc_relay.rs now subscribes to the wallet's notification stream before publishing the request it is waiting on, so a fast reply cannot be sent while the subscription is still being set up. Three files: the processor fix (5/−1), an integration test that drives a fast wallet reply through the relay (120 lines), and a changeset.

    Cost: $0.59 actual against $1.50 expected (−61%), one review round, zero resumes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfactoryBuilt by the software factoryrewritenostream 4.0 Rust/LMDB rewriterustRust implementation work

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions