Repository navigation
feat(node): bound download-receipt log with size-based rotation (#802) - #807
Conversation
The append-only `download_receipts.jsonl` had no rotation, retention, or size cap, so on a long-running, high-throughput node it grew monotonically across restarts (`O_APPEND`) and eventually exhausted `data_dir`. Add size-based rotation with N retained backups to `JsonlReceiptLog`: - track the live-file size in-memory (seeded from the file length at open) and rotate before a write would exceed `max_file_bytes`; - shift numbered backups `.1..=.N`, drop the oldest beyond `retained_files`, reopen a fresh `0o600` file; `retained_files == 0` truncates in place; - best-effort: a failed rename/open restores the canonical path so the writable handle is never lost and paid delivery is never aborted; the in-memory counter resyncs from metadata after a write error. Expose limits via a new optional `[receipts]` config section (`max_file_bytes`, `retained_files`) with floor/ceiling validation (1 MiB–1 GiB, <=100 backups) and defaults (128 MiB, 4), bounding `data_dir` to roughly `(retained_files + 1) * max_file_bytes`. Config-additive: an absent section preserves prior behaviour with the defaults. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request implements size-based rotation for the download-receipt audit log to prevent unbounded disk growth, introducing a new [receipts] configuration section with customizable limits. The review feedback points out a key issue where modifications to this new configuration section during a SIGHUP reload are silently ignored instead of triggering a warning to the operator that a restart is required, and provides clear, actionable steps to resolve it.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Coverage reportTotal: 86.67% (was 86.62%, ▲ +0.05%) — 27791/32064 lines
History
|
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #802 by adding a bounded, size-based rotation/retention policy to the node’s append-only download-receipt audit log (download_receipts.jsonl). It introduces a new optional [receipts] config section, wires the resolved policy into the node runtime, and adds targeted tests to ensure rotation behavior is correct and permissions are preserved.
Changes:
- Added
RotationPolicyand rotation logic toJsonlReceiptLog, including retained numbered backups and a truncate-in-place mode whenretained_files == 0. - Introduced new
[receipts]config types + resolver validation and threaded the resolved policy into node runtime initialization. - Updated tests and documentation (CHANGELOG) to cover defaults, validation boundaries, and rotation scenarios.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| crates/node/src/receipt_log.rs | Implements size-based rotation/retention for the JSONL receipt log and adds unit tests for rotation behavior. |
| crates/node/src/runtime/mod.rs | Wires ResolvedReceipts into JsonlReceiptLog::open via a RotationPolicy. |
| crates/common/src/config/types.rs | Adds optional [receipts] config section (ReceiptsConfig). |
| crates/common/src/config/mod.rs | Adds resolver constants + validation logic for receipts rotation settings and unit tests. |
| crates/common/src/config/resolved.rs | Adds ResolvedReceipts and threads it into ResolvedConfig. |
| crates/node/src/runtime/reload.rs | Updates hand-built ResolvedConfig instances in tests to include ResolvedReceipts. |
| crates/node/tests/sighup_signal.rs | Updates test config seeding to include ResolvedReceipts. |
| crates/cli/tests/config_validate.rs | Updates test helper ResolvedConfig construction to include ResolvedReceipts. |
| CHANGELOG.md | Documents the new bounded rotation behavior and the [receipts] config section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- reload: warn when the restart-required [receipts] section changes on SIGHUP - receipt_log: prune now-stale backups when retained_files is lowered - receipt_log: log-and-continue on rotation failure instead of dropping the audit receipt (the held handle stays writable; the next append retries) - config: derive ResolvedReceipts::default() from the DEFAULT_RECEIPT_* consts so test configs cannot drift from production defaults Co-authored-by: Copilot <[email protected]>
|
Thanks for the reviews — all four inline comments are addressed in b6ffb36:
clippy, fmt, cargo doc (-D warnings), and |
- prune_backups_above now logs real (non-NotFound) errors via a download_receipt_prune_failed warn instead of silently treating them as end-of-run, so a leak past the disk bound is observable. - RotationPolicy gains From<&ResolvedReceipts> as the sole production constructor (validation now carries across the type boundary); the raw new() is gated to #[cfg(test)] pub(crate). runtime builds via From. - Document the max_file_bytes == 0 "rotation disabled" sentinel. - Add tests: rotation_failure_still_appends_and_stays_writable (best-effort fall-through + canonical-path handle survives) and rotates_after_filling_a_multi_line_file (multi-line rotation boundary). Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
|
Addressed the review feedback in 4021f0c:
One caveat: the reopen-failure rollback branch ( All 753 |
alpergundogdu
left a comment
There was a problem hiding this comment.
Review: approve
Cleanest of the current batch. The hard parts all check out: highest-to-lowest backup shift (no clobber, oldest dropped), best-effort handle preservation across mid-rotation failure (the handle never dangles — covered by the failure-injection test), counter seed/resync, and atomicity under concurrent spawn_blocking callers (single Mutex<LogState> held across the whole append). Anti-panic policy respected (unwrap_or/saturating_add/combinators only), 0o600 preserved on live + backups, config validation rejects floor/ceiling/cap with field-tagged errors, reload emits the "requires restart" warning.
Nits (non-blocking, follow-up at most)
receipt_log.rs:553-576—prune_backups_aboveissues a wastedremove_file(.{retained+1})(returns NotFound) on every rotation in steady state. Negligible given rotation rarity; could gate it to the lowered-retention case.receipt_log.rs:618-630— an oversized single line (>max_file_bytes) lands over-cap and can end up in a backup, so the(retained+1)*max_file_bytesdisk bound is genuinely "roughly." Worth a one-line doc caveat.receipt_log.rs:647-649— counter resync ignores a secondmetadata()failure, leavingwrittenstale by at most one line; self-corrects on the next successful write/rotation. A comment noting the divergence window would help.
LGTM to merge.
Summary
Fixes #802.
The append-only download-receipt audit log (
download_receipts.jsonl, ~one line per accepted voucher interval) had no rotation, retention, or size cap. On a long-running, high-throughput node it grew monotonically across restarts (O_APPEND) and eventually exhausteddata_dir— the lone unbounded-growth sink in its batch of work (VoucherActivity eviction, the session-ticket peer cap, and the withdrawn-cache all got explicit bounds).This PR adds size-based rotation with N retained backups to
JsonlReceiptLog, exposed via a new optional[receipts]config section.Changes
crates/node/src/receipt_log.rsRotationPolicy { max_file_bytes, retained_files }.max_file_bytes..1..=.N, drops the oldest beyondretained_files, and reopens a fresh0o600file.retained_files == 0truncates the live file in place (no backups).appenderrors as non-fatal — the audit log is not the incentive: no replay-protection window enforced on incoming voucher nonces, allowing a client to resubmit a previously accepted voucher after a node restart and receive a second byte-delivery for the same payment #527 replay guard). The in-memory counter resyncs from file metadata after a write error so a later rotation isn't decided on a stale count.Config (
crates/common/src/config/{types,resolved,mod}.rs)[receipts]section:max_file_bytes(default 128 MiB) andretained_files(default 4), validated to[1 MiB, 1 GiB]and<= 100.data_dirto roughly(retained_files + 1) * max_file_bytes.crates/node/src/runtime/mod.rsJsonlReceiptLog::open. The edit is confined to the existing receipt-log block to minimise overlap with in-flight PRs.Behaviour notes
written + line_len > max_file_bytes(not>= max) so the cap isn't delayed by one record.0o600.Testing
cargo clippy -p decdn-common -p decdn-node --all-targets— cleancargo fmt -- --check— cleancargo doc(pre-commit,-D warnings) — cleancargo nextest run— 750 node/common + 162 cli tests pass, including 10 new tests:.1newest, oldest dropped)retained_files == 0truncates in place0o600on the live file and backupsNotes
This branch was chosen to avoid conflicts with open PRs #806, #800, and #794 — the
common/config/*andnode/runtime/mod.rsedits land in different, additive regions.