Repository navigation
friglet: peer pool with discovery and failover; own node optional (SNB-855) - #85
Open
setavenger wants to merge 6 commits into
Open
setavenger wants to merge 6 commits into
setavenger wants to merge 6 commits into
Conversation
…B-855) Without p2p_node_addr, friglet now finds peers of the network through its DNS seeds and address gossip and downloads blocks, headers and (for now) broadcasts through them. With an own node configured, every connection still goes only to that node, with the same retries, timeouts and messages. - blindbit-lib `net`: PeerSource (OwnNode | Discovered(PeerPool)), Dialer (the TCP seam for a later proxy), Seeds (kernel-node's DNS seed lists, x9. filter first; none on regtest), shared USER_AGENT. The pool keeps bitcoin-address-book new/tried tables (Kyoto's sizes) and learns from PeerEvents: tried promotion, rest after failures, session ban after a bad block, IPv6 skipped without a route, the serving peer asked first. - BlockFetcher takes Arc<PeerSource>. Discovered: up to 8 different peers per round, NETWORK|WITNESS required, peers below the block skipped before getdata, addresses requested while few are known, an overall deadline per connection. FetchFailure gains NoPeers and Behind; BlockFetchError says who was asked (FetchedFrom) and summarises discovered peers' failures. - friglet: p2p_node_addr optional (empty = unset, regtest still needs a node); one PeerSource shared by scanner, Electrum (headers try up to 3 peers, relayfee = median of recent peers' feefilters, relay jobs move on when a peer cannot be asked) and GetStatus (new `p2p` field). - Tray: node field optional except on regtest, privacy hint, "Blocks from" status row. blindbit-cli: --p2p-node-addr optional. fetch_block example accepts `dns`. - Tests: pool unit tests, multi-peer discovery tests on 127.0.0.x, a thread soak test, chain tests with two fake peers. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…SNB-855) A peer that already gossiped is not sent getaddr again (Bitcoin Core answers repeats from a cache), so a sticky block peer stops resending the same addresses with every block. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Relay fee with discovered peers: the median needs fresh feefilters from three peers; with fewer, friglet samples more peers at once (and at Electrum start), and reports the lowest seen until the quorum is there, so one peer cannot raise the fee. Even counts take the lower middle. - DNS seed answers that are not public addresses are dropped (a captive portal or hijacked resolver could otherwise make "local" peers that may gossip local addresses). Gossiped peers must use the network's port or one above 1023. More reserved IPv4 ranges count as not public. - A peer forgotten after three unreachable tries stays out for an hour instead of coming straight back with the next seeding or gossip. - IPv6 is tried again 30 min after "network unreachable". - A discovered peer that completed the handshake and then hit the per-connection deadline is reported as unhelpful, not unreachable. - Scanner asserts (debug) that it and its peers are on one network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Scanner::new takes an Arc<PeerSource> instead of a socket address since the peer pool. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
setavenger
force-pushed
the
snb-854-kernel-node-p2p
branch
from
November 1, 2026 15:53
4ab2cda to
fa4f8ee
Compare
setavenger
force-pushed
the
snb-855-peer-pool
branch
from
November 1, 2026 15:53
46f04ed to
f8bad29
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #84 (
snb-854-kernel-node-p2p); merge that first. Implements SNB-855.What and why
p2p_node_addrbecomes optional. With it set, friglet talks only to that node (blocks, headers, broadcast), with the same retries, timeouts and error messages as before. Left empty, friglet finds peers of the network through its DNS seeds and address gossip and asks them one after another, so a user without their own node can still scan. Regtest still requires a node. No Tor yet (SNB-857) and broadcast is still single-peer (SNB-856).blindbit-lib::net(new):PeerSource(OwnNode|Discovered(PeerPool)),Dialer(the TCP seam a SOCKS5 dialer slots into),Seeds(kernel-node's DNS seed lists,x9.first; none on regtest), sharedUSER_AGENT(unchanged/SwiftSync:0.1.0/). The pool keepsbitcoin-address-booknew/tried tables (Kyoto's sizes) and learns fromPeerEvents: tried promotion on handshake, 10 min rest when unreachable/unhelpful (forgotten after 3 unreachable), 2 min when behind, session ban after a bad or stripped block, IPv6 skipped after the first "network unreachable", and the peer that served the last block is asked first.BlockFetcher::new(Arc<PeerSource>). Discovered peers: up to 8 different peers per round, no waits,NETWORK|WITNESSrequired at the handshake, peers below the block height skipped beforegetdata,getaddrwhile fewer than 200 addresses are known (once per peer), a per-connection cap against trickling peers.FetchFailuregainsNoPeers/Behind;BlockFetchError.from: FetchedFromand the discovered-peer message summarises what the peers did ("asked 3 peers: 2 were unreachable, 1 sent a bad block and is ignored now. Check this computer's internet connection, or set p2p_node_addr to your own signet node.").blockchain.relayfee= median of fresh feefilters from at least 3 (up to 5) peers, sampled in parallel at Electrum start and when short, the lowest seen until the quorum is there (own node: its own, as before); broadcast/recheck go to one relay peer (moving on, up to 3, when a peer cannot be asked).Arc<PeerSource>built inmainafterresolve, seeding starts at daemon start.StatusInfo.p2p("your node 1.2.3.4:38333" / "random peers: 157 known, 1 ignored",#[serde(default)]).Config and UI
p2p_node_addr: empty/whitespace = unset (normalised inresolve); regtest without it: "regtest has no public peers: set p2p_node_addr to your regtest node". Existing TOML/env/CLI unchanged.FRIGLET_NETWORKor the file's network). Status tab: "Oracle / P2P" row split into "Oracle" and "Blocks from".blindbit-cli --p2p-node-addroptional;fetch_blockexample acceptsdnsas the peer.Deviations from the plan
PeerEventhas two more variants:Served(sets the preferred peer) andNoRoute(skips IPv6 for the session).wants_addrtakes the peer.FetchedFrom::OwnNode(PeerAddr)(notSocketAddr), andNetwork { tried, exhausted }, so the message can say the round ran out of peers.NoPeers(a small signet book would otherwise stall for up to 10 min); after 64 unlucky random draws, any usable known peer is taken.addrv2after the block, so a connection that asked for addresses waits up to 3 s for them on its own thread after handing the block over; the scan does not wait.RetryPolicygainsconnect_timeout;Scanner.p2p_retryis anOption(None = the source's default).blindbit-lib/tests/thread_soak.rs) so parallel tests' threads do not count.Verification
cargo build --workspace,cargo clippy --no-deps -p friglet -p friglet-ipc -p friglet-tray --all-targets -- -D warnings,cargo fmt --all -- --check: pass.cargo test --workspace: blindbit-lib 95 passed (new: 10 pool tests, 9 discovery tests on 127.0.0.x), thread_soak 1, friglet 81 (new: two-peer header test, relayfee median, three-peer relayfee sampling), friglet-ipc 28 + 1, friglet-tray 67 + 7; 0 failed. Network tests repeated 5x: stable.PeerSource;cargo test -p blindbit-lib --features serde: 105 passed, 0 failed.fetch_block dnson block 274010 (> 1 week old) and the tip: DNS seeds (54 addresses), serving peer logged, 0.36 s / 1.5 s; IPv6 peers failed with "network unreachable" and were skipped after the first. Own node: no DNS lookup, nogetaddr.p2p_node_addrand daemon with the own node each refetched the 5 blocks and restored them; the resulting graph transactions, anchors and heights are identical.p2p_node_addr:GetStatus→"p2p": "random peers: 157 known";blockchain.headers.subscribeanswered from discovered peers;blockchain.relayfee= 1e-6 BTC/kvB from four peers' feefilters (100, 1000, 100, 100 sat/kvB). Tray screenshots (Xvfb,FRIGLET_TRAY_SHOW_ON_START, captured with ffmpeg x11grab; no SNI tray host installed on that box, so no tray-icon shot): Status tab shows "Blocks from: random peers: 146 known"; Settings shows the optional node field and hint.fetch_blockexample; signet; 5 blocks × 10 rounds per binary, 854 and 855 interleaved; own node 152.53.151.148; one fetch per process). Own node, median 854 vs 855: 82.6 vs 82.0 ms (run 1, one 2.2 s outlier on 855), 84.2 vs 84.9 ms (run 2), 87.6 vs 86.0 ms (run 3, final code). Discovery cold time to first block (fresh process, DNS seeding included), 20 runs each: 20/20 served; final code median 528 ms, p90 5.7 s, max 8.3 s (earlier runs: max 10.3 s). The slow cases are IPv4 peers that drop the SYN, 5 s connect timeout each. Warm (daemon, sticky peer, debug build): 100–180 ms per block.Known limits