Skip to content

friglet: broadcast to several peers, confirm via an unrelated peer (SNB-856) - #86

Open
setavenger wants to merge 3 commits into
snb-855-peer-poolfrom
snb-856-broadcast
Open

setavenger wants to merge 3 commits into
snb-855-peer-poolfrom
snb-856-broadcast

Conversation

@setavenger

@setavenger setavenger commented Oct 30, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #85 (SNB-855). Implements SNB-856.

What / why

Without an own node, a broadcast used to rest on one random peer's word: the peer that got the transaction was also the one asked whether it took it. Now (friglet/src/electrum/net_broadcast.rs):

  • 3 observers first: relay=true connections, settled, only to peers whose version says they relay transactions (blocks-only peers are refused and never handed out for relay again: PeerEvent::NoTxRelay).
  • then 2 senders: relay=false, height 0, placeholder addresses, the shared user agent, no getaddr/feefilter; inv → getdata → tx → ping/pong, then they only listen for a parent request or a disconnect.
  • All peers of a broadcast are in distinct netgroups (/16 IPv4, /32 IPv6): new PeerAddr::netgroup and PeerSource::next_outside in blindbit-lib/src/net.
  • Success only when an observer serves the tx (getdata poll every 2 s, or at once after its inv). Nothing a sender says counts.
  • Rejected only when every sender that got it gave the same signal: all asked for a parent (bad-txns-inputs-missingorspent…, Sparrow's prefix, final). All dropping it before the pong gives the "disconnected right after receiving" error but stays inconclusive, so a resend looks again. Otherwise "not confirmed" after the 25 s budget, with Sparrow's mempool min fee not met, X < Y wording when the fee is below the median of the observers' feefilters (which now feed the 855 relay-fee quorum). No observer reachable → code 2, nothing sent.
  • Pending rechecks: PendingTx.sent_to (serde default, ≤ 16). A recheck asks 2 peers outside sent_to (and their netgroups); a lost tx is handed to one of them on a sender connection and added to sent_to. A resend after an inconclusive wait asks one non-sender.
  • Own node: unchanged (relay::broadcast/in_mempool/recheck, same wording; with_relay_peer became own-node-only with_own_node).

Deviations from the plan

  • Senders keep listening after the pong until the broadcast ends (needed to see a parent request, which Core sends ~2–4 s later to an inbound peer). Core 31's private broadcast disconnects after the pong; SNB-857 can decide whether to keep that.
  • Re-announcing a pending tx uses a fresh sender connection (relay=false) instead of the observer connection that just asked, so queries and hand-overs never share a connection.
  • The group of a sender that got the tx stays reserved for the rest of the broadcast; groups of failed observers/senders are released.
  • "All senders dropped it" is not final (see above): a peer can just go away, and Core 30+ no longer disconnects for invalid txs.
  • A recheck whose sent_to peers rule out every netgroup the pool knows falls back to excluding only those peers.

Findings worth knowing

  • Live, a consensus-invalid tx (output changed, signature broken) was not dropped by the signet peers it was handed to (Bitcoin Core 30+ no longer disconnects for invalid txs), so it ends as "not confirmed", not "invalid". The "dropped" signal only fires with older nodes.
  • Observers ask for the txid before it has spread, so without Tor they also learn this IP knows it (README privacy note updated). SNB-857's per-connection circuits remove that link.
  • A tx in the tip block counts as success: Core serves the most recent block's txs to getdata. The own-node check has always behaved the same; the tx is confirmed, so the answer is harmless.

Verification

Debug builds, CARGO_BUILD_JOBS=3:

  • cargo build --workspace ok; cargo test --workspace: 301 passed, 0 failed (before the rebase onto integration 929419b, which adds 10 testkit tests; CI passes after it); cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings clean; cargo fmt --all -- --check clean.
  • New network tests run 20× in a row: 36/36 each time (plus 5× earlier with the blindbit-lib net:: tests).
  • Scenario table as tests (net_broadcast::tests, electrum::tests::discovered): unrelated peer announces → InMempool; observer only answers getdata → InMempool; sender echoes inv, serves it, then drops, observers silent → not confirmed; no observer reachable → code 2, nothing sent; all senders ask for a parent → rejected (missing inputs); one sender asks for a parent, an observer serves it → InMempool; blocks-only peer → never sender or observer, asked once per session; recheck → senders never contacted; relayfee from observers 1000/2000/2000/2000/100000 → 2000 sat/kvB, no extra connection; resend after an inconclusive wait → asks a non-sender; a sender that connects after the broadcast ended hands nothing over.
  • Sender handshake asserted in tests: relay=false, height 0, services NONE, placeholder 127.0.0.1:1 addresses, the shared user agent; only inv/tx/ping/pong/notfound on sender connections.

Live signet, daemon without p2p_node_addr, via Electrum blockchain.transaction.broadcast:

  • (a) 11 txs from the signet mempool: all accepted, each confirmed by a named observer (e.g. confirmed_by=95.179.253.55:38333). P2P part 60–204 ms (one 5.1 s), Electrum round trip 0.10–0.89 s (one 5.2 s). These were already on the network, so no hand-over was needed; the hand-over → observer path is covered by the tests only (no funded signet wallet here).
  • (b) an old confirmed tx: rejected, bad-txns-inputs-missingorspent: every peer friglet sent it to asked for a parent… in 7.4 s / 11.6 s. A mempool tx with an output lowered (signature broken): "25 seconds after friglet handed it to 2 peers, no other peer of the network had the transaction…" (the peers did not disconnect). Never success.
  • (c) own node 152.53.151.148:38333: 5 mempool txs accepted in 5.3–11.6 s (hand-over + mempool poll, as before); the old confirmed tx rejected with the unchanged own-node wording in 6.7 s.
  • Restart with pending txs whose sent_to named 4 peers: the recheck asked 175.110.114.74:38333, 78.34.61.210:38333 (not_asked=4), and handed the one tx neither had to the first on a relay=false connection, adding it to sent_to. (sent_to was seeded by editing the pending file, since (a) needed no hand-over.)

setavenger and others added 3 commits November 1, 2026 15:46
- `PeerAddr::netgroup()` / `NetGroup`: Bitcoin Core's default netgroups
  (/16 for IPv4, /32 for IPv6; an IPv4-mapped address is its IPv4).
- `PeerSource::next_outside(purpose, exclude, groups)`: `next` that also
  passes over peers in the given groups, resting fallback included.
- `PeerEvent::NoTxRelay`: a peer whose version says it relays no
  transactions (blocks-only) is never handed out for relay again this
  session; blocks may still come from it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…NB-856)

Without an own node, a broadcast no longer rests on one random peer's word
(new `electrum/net_broadcast.rs`):

- 3 observers first: relay=true connections, settled, to peers whose
  version relays transactions; then 2 senders: relay=false, no getaddr or
  feefilter, inv -> getdata -> tx -> ping/pong, then they only listen. All
  peers of a broadcast are in distinct netgroups (/16, /32).
- Success only when an observer serves the transaction (getdata poll every
  2 s, or at once after its inv). Nothing a sender says counts.
- Rejected only when every sender that got it gave the same signal: all
  asked for a parent (bad-txns-inputs-missingorspent) or all dropped it
  before the pong. Otherwise "not confirmed" after the 25 s budget, with
  Sparrow's fee wording when the fee is below the median of the observers'
  feefilters, which now feed the relay fee quorum. No observer reachable:
  error code 2, nothing sent.
- Pending broadcasts remember the peers they were handed to (`sent_to`,
  at most 16); a recheck asks 2 other peers and hands a lost one to one of
  them on a sender connection. A resend after an inconclusive wait asks
  one non-sender.
- Own node: `relay::broadcast`/`recheck` and their wording unchanged.

Tests: FakePeer gets a relay flag, announcements, echo_inv and a shared
FakeNet mempool on 127.N.0.1; the plan's scenario table runs against it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- A sender checks the stop token before announcing and before handing the
  transaction over, so a broadcast that has ended (deadline, error) never
  leaves a peer holding the transaction that is missing from `sent_to`.
- Every sender dropping the connection is reported as before but kept
  inconclusive (a resend looks again): a peer can also just go away, and
  Bitcoin Core 30+ no longer disconnects for invalid transactions.
- No early "not confirmed" when observers go away: replacements are
  launched and the wait runs to the budget.
- A recheck whose sent_to peers rule out every network group the pool
  knows asks peers in those groups (never the peers themselves).
- README: the observers learn this IP asks for the transaction too.
- Tests: a stopped sender hands nothing over; the recheck group fallback;
  the own node's fee-shortfall wording, word for word.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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