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:
- under the chain lock,
subscribecreates 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; - the replay is then paged in short lock holds (
REPLAY_PAGEevents, at mostREPLAY_SCANscanned per hold) over[from_seq, end); - live events below
endare 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§
- Chain
Filter - Which events a subscription yields.
- Chain
Subscription - A replay-then-live stream of chain events.
Enums§
- Chain
Item - One item of a subscription.
- Subscribe
Error - 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.