pub fn spawn_receipt_writer(
log: Arc<dyn ReceiptLog>,
metrics: Arc<Metrics>,
) -> (Arc<dyn ReceiptSink>, StopHandle)Expand description
Spawn the single background task that owns the on-disk ReceiptLog and
drains the receipt queue, returning the ReceiptSink the delivery path
enqueues through plus the StopHandle that stops the task at graceful
shutdown.
Decouples the audit write from the paid-delivery hot path (#803): the
voucher-accept path does only a non-blocking ReceiptSink::record (a
bounded try_send) as each voucher is accepted, while this task performs
the actual append on the blocking pool. A slow or full disk can only fill
the queue (and drop audit records, counted) — it can never delay delivery
or serialize delivery on the receipt-log mutex. The writer is the only
caller of ReceiptLog::append, so the log’s internal mutex sees no
cross-stream contention.
On its stop signal (StopHandle::cancel, fired after the router has
drained, so no further receipts are produced) the task flushes whatever is
already enqueued and exits; complete StopHandle::shutdown within the
shutdown deadline to preserve the audit tail. The StopHandle owns the stop
token beside the task handle, so the join cannot hang on sinks that outlive
shutdown — crate::handlers::client::ClientHandler holds one for the
whole runtime.