fix(file_store): don't overwrite entries appended via another handle - #2332
Open
Brijesh-Thakkar wants to merge 2 commits into
Open
Brijesh-Thakkar wants to merge 2 commits into
Brijesh-Thakkar wants to merge 2 commits into
Conversation
Signed-off-by: Brijesh-Thakkar <brijeshthakkariitian5126@gmail.com>
`bincode` is deprecated. Migrate the file store's on-disk encoding to `postcard`, as part of the fix for bitcoindevkit#2308 (see also bitcoindevkit#2258). Each entry is now stored as a `postcard` `u64` varint length prefix followed by the `postcard`-encoded changeset. The length prefix frames entries, so a torn or corrupt entry can be told apart from a clean end of file, and a corrupt, huge length cannot trigger a huge allocation. Bytes left in a frame after decoding are rejected. Real I/O errors are reported as `StoreError::Io`, which `Store::append` now returns when scanning past entries written by another handle. BREAKING CHANGE: - The on-disk format changed. Files written by earlier versions cannot be read; use new magic bytes so old files fail with `StoreError::InvalidMagicBytes`. - `StoreError::Bincode(bincode::ErrorKind)` is replaced by `StoreError::Decode(postcard::Error)`. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Brijesh-Thakkar
force-pushed
the
fix/file-store-stale-handle-append
branch
from
September 30, 2026 17:38
7b6f7f8 to
956d277
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2308.
Store::appendwrites at the file handle's own cursor, and the file is not opened in append mode. That cursor is only synced onload,dumpand the handle's own appends. If another handle to the same file appends in the meantime, an append through the stale handle overwrites that entry. When the entries are the same size the file stays decodable, so the earlier changeset is lost silently.Before writing,
appendnow scans forward from the handle's cursor using the existingEntryIter, skipping valid entries that other handles added. The cursor ends up right after the last valid entry, and the new changeset is written there.Notes to the reviewers
EntryIterand writes where valid data ends. A test covers appending after a faileddumpand after a partial trailing entry.UnexpectedEof) ends the scan and the write starts there, as on master.set_lenrollback from Replace bincode by postcard #2258 are intentionally out of scope.EntryIter::dropignores a failed cursor-sync seek, so that one seek failure can go unnoticed.Changelog notice
Fixed
bdk_file_store:Store::appendno longer overwrites changesets that were appended through another handle to the same file.Checklists
All Submissions:
Bugfixes: