feat(lurker): PSS mailbox mode — offline delivery via bounded backlog sweep - #55
Open
flotob wants to merge 1 commit into
Open
feat(lurker): PSS mailbox mode — offline delivery via bounded backlog sweep#55flotob wants to merge 1 commit into
flotob wants to merge 1 commit into
Conversation
…ffline delivery Builds on the bin-selection fix (#54, Viktor Trón's correction): now that PSS pullers pull the correct trojan bins (L..L+3 in the geometric regime), those bins can be swept from the past instead of only tailed live — turning PSS reception from a live socket into a mailbox. WebSocket `GET /pss/subscribe/{topic}?history=true` (and the `LurkerSubscribe { history }` control command + `WatchState::history` it threads to) makes a fresh puller start a bounded window behind the peer's cursor rather than just PULL_BACKLOG behind it, so messages sent while the receiver was offline are recovered before live traffic. The lookback (HISTORY_BACKLOG, in binIDs) is bounded ON PURPOSE: per-bin occupancy on a depth-d storer is ~2^(22-(k-d+1)), so at the current 2-byte mining prefix (L=16) the trojan bins hold hundreds of thousands of chunks — an unbounded start=1 sweep would be a self-inflicted DoS. The window caps it at a few thousand recent chunks per bin. Crucially, it becomes a COMPLETE backlog sweep for free under the deeper (L=24) mining convention Viktor advocates: there the whole trojan-bin backlog is ~1-2K chunks, so cursor-HISTORY_BACKLOG underflows to the floor and the mailbox recovers everything. Raising the mining convention upgrades the mailbox from 'recent' to 'all' with no code change. Semantics unchanged where they should be: resume (epoch-matched handover) always continues exactly where the predecessor stopped — mailbox never rewinds a live puller; GSOC has no mailbox (a SOC has a latest value, not a message backlog) — always live; history is union-OR'd across subscribers on the shared lurker. A sweep exceeding SEEN_CAP may re-deliver its oldest chunks, within the documented at-least-once/may-duplicate contract. Tests: start_bin_id both regimes + resume override + sparse-bin underflow-to-floor; WatchState::merge_from history union; WS ?history=true wiring smoke.
flotob
force-pushed
the
fix/pss-bin-selection
branch
from
July 22, 2026 20:00
341e696 to
573a54c
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.
PSS as a mailbox, not just a socket
Today a PSS subscription only tails live traffic: pullers start just behind the storer's cursor, so a message sent while the receiver was offline is gone. This adds mailbox mode —
GET /pss/subscribe/{topic}?history=true— which sweeps a bounded backlog on subscribe, recovering messages sent before the client connected. PSS goes from a live socket to offline delivery.This is the capability Viktor Trón's correction (#54) unlocks: once pullers pull the correct trojan bins, those bins can be swept from the past.
The design, and why the sweep is bounded
start_bin_idgains a mailbox branch: a fresh puller startsHISTORY_BACKLOG(4096) binIDs behind the cursor instead ofPULL_BACKLOG(8).The bound is load-bearing, and it's the same trie arithmetic from #54. Per-bin occupancy on a depth-
dstorer is ~2^(22-(k-d+1)), so at the current 2-byte mining prefix (L=16) the trojan bins hold hundreds of thousands of chunks — an unboundedstart=1sweep would be self-inflicted DoS. The window caps it at a few thousand recent chunks per bin.The elegant part: the window becomes a complete backlog sweep for free under Viktor's L=24 convention. There the whole trojan-bin backlog is ~1–2K chunks — inside the window — so
cursor - HISTORY_BACKLOGunderflows to the floor and the mailbox recovers everything. Raising the mining convention upgrades the mailbox from "recent" to "all" with zero code change. (This is a strong argument for L=24, and ties into the SWIP amendment.)Semantics kept honest
SEEN_CAPmay re-deliver its oldest chunks — within the documented at-least-once / may-duplicate contract.Verified on mainnet
The scenario this feature exists for, on a funded depth-20 batch:
?history=true.Log proof it was the sweep, not slow live delivery — bin 11's cursor was
2930504, the history puller started at2926409= cursor − 4096. A live subscriber starts atcursor − 8=2930497, above all four pre-sent messages, and would never see them. The 4096-binID lookback is exactly what reached back to them.(This run's covering peers sat at
b_p = 9–11 < L, so bin selection was the exact-bin regime and the sweep hit bins 9–11 — the mailbox mechanism is bin-agnostic; it sweeps whatever bins #54 selects for the regime.)Verification
start_bin_idboth regimes + resume-override + sparse-bin underflow-to-floor;WatchState::merge_fromhistory union;?history=trueWS wiring smoke.-D warnings0, fmt clean, full workspace green (34 suites; 113 in ant-p2p).🤖 Generated with Claude Code