Skip to main content

Module chain_subscribe

Module chain_subscribe 

Source
Expand description

Chain subscription: replay-from-sequence plus live events (ADR-103 D).

ChainManager::subscribe returns a ChainSubscription. It yields the retained events from from_seq, then live events, with no gap and no duplicate between the two:

  1. under the chain lock, subscribe creates the live receiver and records the snapshot end (the chain’s next sequence); every append publishes to the hub under that same lock, so they cannot interleave;
  2. the replay is then paged in short lock holds (REPLAY_PAGE events, at most REPLAY_SCAN scanned per hold) over [from_seq, end);
  3. live events below end are dropped (belt and braces).

A deep from_seq therefore never clones the chain under the lock, and a from_seq older than the replay window is refused with a typed error.

Live delivery uses a bounded tokio::sync::broadcast. send never blocks, so a stalled subscriber cannot slow an append; it falls behind, the oldest items are overwritten, and its next read yields ChainItem::Lagged carrying resume_from, the sequence to resubscribe from to recover. The subscription holds only a Weak reference to the manager and ends when the manager is dropped.

Structs§

ChainFilter
Which events a subscription yields.
ChainSubscription
A replay-then-live stream of chain events.

Enums§

ChainItem
One item of a subscription.
SubscribeError
Why a subscription was refused.

Constants§

CHAIN_SUBSCRIBE_CAPACITY
Live buffer per subscriber (events). A subscriber slower than this many events behind sees ChainItem::Lagged.
DEFAULT_MAX_REPLAY_WINDOW
Default replay window: the furthest back (in events behind the head) a subscriber may start. Adjust with ChainManager::set_max_replay_window.