util: write JSON atomically in WriteJson

bitcoin/bitcoin: PR #35763

3 suggestions

Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive for their assessments.

Optional improvements

Link

[suggestion] · Failure test does not check preservation of the previous banlist

The test deletes the valid banlist before forcing failure, so it never checks that a failed update leaves the last good banlist readable.

Location: src/test/banman_tests.cpp:69 (head).

Details and suggested fix

The rename-error assertion catches a simple reversion to direct writes, but every current assertion could still pass if the writer incorrectly removed a regular destination before staging. Add a separate case before this block that retains the valid .json and creates a directory at banlist_atomic.json.tmp, making the temporary-file open fail. Attempt to write a different ban map, require Write to return false, then read into a fresh map and check that only the original 203.0.113.1/32 entry remains, with creation time 100 and ban-until 200. This directly checks preservation on staging failure. Keep the existing rename-failure and temporary-file reuse checks.


Link

[suggestion] · PR description claims a WriteJson rename absent from the patch

The PR title and description refer to WriteJson, but the helper and both callers still use common::WriteSettings.

Location: src/common/settings.h:48 (head).

Details and suggested fix

The description says common::WriteSettings was renamed to common::WriteJson, but the declaration, definition and both callers retain the old name; there is no WriteJson symbol in this tree. The commit messages also use WriteSettings. Update the PR title and description to describe atomic writes through WriteSettings, or complete the rename if it remains intended. This does not affect the replacement behavior.


Link

[suggestion] · Atomic banlist replacement changes operator-managed file layouts

Replacement changes symlink, file bind-mount and custom-permission behavior for banlist.json; documenting these upgrade effects would help, although no affected deployment was identified and the platform-specific failure was not experimentally observed.

Location: src/common/settings.cpp:153 (head).

Details and suggested fix

Previously, opening banlist.json followed a final symlink and retained the existing inode. Renaming banlist.json.tmp over it instead replaces the symlink with a regular file, leaving the link target unchanged. On Linux, replacing a file-level bind mount fails with EBUSY: dumps log an error and remain dirty for retries, but updates since the last successful write cannot persist while that layout remains. Newly created staging files also use mode 0600 under the POSIX 0077 umask rather than preserving the destination's custom mode. Add a short compatibility note to the commit message or release notes. These layouts have no documented support, and replacement already matches settings.json, peers.dat, anchors.dat and mempool.dat; retaining in-place writes would sacrifice the failure isolation added here.


Coverage details

Earlier concerns

Earlier reports raised these, with the titles and severities shown there. This review neither republished nor resolved them.