A node switch waits for the slowest relay before it finishes

Aperta
#842 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Catrya ci sta già lavorando.

Dal 21/10/2026.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
dart, rust

Direzione di ricerca

Start with rust/src/api/orders.rs, especially refresh_subscriptions_for_active_node and refetch_active_node_orders; compare the book fetch flow with the existing nostr::first_answer::newest_answer capability-fetch fix. Trace restart_orders_subscription to confirm manual refresh uses the same path. Done when slow relays no longer delay switching or refresh, fast-relay orders are ingested, and capability fetching proceeds without waiting for the book refetch; add the described relay-double test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area: relays bug priority: medium

Context

A node switch (Settings → Mostro node) runs refresh_subscriptions_for_active_node (rust/src/api/orders.rs), awaited
by set_active_mostro_node. Among other things, it:

  1. clears the order book, the escrow mode, the bond policy and the fee;
  2. re-subscribes the node's filters;
  3. refetches the new node's book with refetch_active_node_orders;
  4. fetches the node's capabilities (fetch_and_set_node_capabilities).

The node selector (mostro_node_selector.dart) waits for the whole call before it closes and says the node was switched.

Problem

refetch_active_node_orders makes two fetch_events calls, one for the pending book and one for the recent changes, one after the other, each with a 10 s timeout. fetch_events returns only once every relay has sent EOSE. So a single slow relay holds the switch until it answers, or for up to 10 s per fetch (20 s in total), even when every other relay answered at once. The capability fetch only starts after that, so the new node's escrow mode, bond policy and fee stay unknown for as long as the slowest relay takes.

Seen in a log on a switch to 00000235, with relay.shadowbip.com slow:

20:40:10  every relay but relay.shadowbip.com has answered both book queries
20:40:17  eose sub=35c2d571… relay=wss://relay.shadowbip.com   (pending book)
20:40:18  eose sub=aec58186… relay=wss://relay.shadowbip.com   (recent changes)
20:40:18  switched subscriptions to mostro=00000235…

The switch took about 8 s. A switch a few minutes earlier, with the same relay answering in under a second, took about 2 s. The requests were the same both times; only that relay's speed changed. The same happens on the manual book refresh (restart_orders_subscription), which calls the same function.

This is the mistake the startup path already fixed for the capability fetch (Kind 38385), which used to cost ten seconds the same way. That fix (nostr::first_answer::newest_answer) reads one replaceable event. The book is many events, so it needs its own approach.

Proposed change

  • Do not hold the switch on the slowest relay. Options, to be decided in the PR:
    • ingest the book as it arrives (stream_events) and stop a short grace after the first relays send EOSE, instead of waiting for all of them;
    • run the two book fetches at the same time instead of one after the other;
    • start the capability fetch without waiting for the book refetch.
  • Relays that answer late are not lost: the live subscription opened in step 2 keeps delivering the new node's events.

Out of scope

  • What the relays are asked (filters, the 48 h window).
  • The cold start path, which already subscribes the book before anything relay-bound (CLAUDE.md, "Nothing relay-bound may sit in front of subscribe_orders()").
  • Relays that reject a REQ because they hit their subscription limit.

Acceptance criteria

  • With one relay that never answers, or answers after the timeout, a node switch finishes about as fast as with that relay removed.
  • The new node's book still shows every order the fast relays hold.
  • The capabilities of the new node do not wait for the book refetch.
  • The manual book refresh gets the same behaviour.

Testing

  • Unit test with a relay double that answers at once and one that never sends EOSE: the refetch returns within the grace, with the fast relay's events ingested.
  • Manual: add a relay that holds REQs open (or a slow public one), switch nodes, and compare the time between the switch and switched subscriptions to mostro=… in the log with and without it.
Lingua principale
Dart
Stelle
11
Fork
9
Merge medio
2g 1h
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di MostroP2P/app

Tutte le issue di MostroP2P/app

Issue simili

Altre issue su Dart

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.