#31888 contrib: Support re-writing linearize-data dumps

full analysis

https://github.com/bitcoin/bitcoin/pull/31888 · midnightmagic · +6/-1 in 1 files, 1 commits · labels: Scripts and tools

Goal

  • Let linearize-data rerun safely without truncating existing dumps to zero bytes
  • Prevent disruptions to processes reading linearize output while it runs
  • Ensure obsolete trailing block data is removed after chain reorganizations

Updates `contrib/linearize/linearize-data.py` to open output block files with `xb+`/`rb+` rather than `wb` to avoid truncating existing files to zero length when rerun. It also calls `os.ftruncate` when rolling to a new file or month to ensure pre-existing trailing data from chain reorganizations is removed.

Problem: Running `linearize-data.py` repeatedly destroys and truncates existing output files to zero bytes during writes, disrupting processes reading the output. In addition, in the event of chain reorganizations producing shorter files, obsolete trailing block data could remain in reopened files.

Category: Tools and scripts (#15 of 22)

P4 · bug fix

  • P4 because linearize-data is a niche offline contrib script rather than essential tooling
  • Only affects operators who repeatedly rerun block data linearization in place

P4 because linearize-data is a niche offline script under contrib rather than essential operator tooling like signet or seed generation. The issue only affects users repeatedly rerunning data linearization in place.

Membership: Modifies contrib/linearize/linearize-data.py, an offline contrib script.

Factors: security/stability 0, bug 1, performance 0, user value 1, leverage 0

Reviewability: Stale: Author silent

  • Author agreed to update the commit message and description but has been silent

The author has been inactive for over 190 days after agreeing to update the PR description and commit message.

Author status: silent since 2026-03-05

Open concerns:

  • Author agreed to update the commit message and PR description to clearly explain the rerun use case, but has not yet pushed the update

Resolved concerns:

  • Lint formatting failure in commit message addressed in earlier push
  • Clarification of the rationale for changing file open modes

Agreement: Strong

  • Strong support with no remaining objections
  • Helps downstream users rerunning dumps without hurting existing workflows (sedited)
  • Initial question about the file open mode rationale was clarified (theStack)

Strong approval from sedited; earlier requests for explanation resolved with ACK.

sedited approved the patch after context was provided, noting it benefits downstream users who rerun the script without regressing existing behavior. No active objections remain.

  • sedited approved (ACK e9dc16194b): 'I don't think this hurts existing users and if it can make things easier for the few upstream users this script has, that seems like a good thing.'
  • theStack asked for context on what problem the open mode change solves, which was clarified by the author and another commenter

Review verdicts (DrahtBot): 1

Files

7 lines under test/bench/ci.

  • contrib/linearize/linearize-data.py +6/-1

Card

This PR modifies contrib/linearize/linearize-data.py to open files in rb+/xb+ mode and truncate them explicitly, preventing existing files from being blanked to zero bytes on rerun and removing leftover data after reorgs. The fix benefits downstream users and scripts that rerun linearization continuously against an active node. One reviewer approved the code, but the author has been silent for over six months without pushing the agreed-upon documentation updates.

Data

dossier JSON · extract JSON · model openrouter/google/gemini-3.8-flash, generated 2026-09-17T16:15, confidence high, input hash 6aa689bfc1113ade