blockstorage: Remove cs_LastBlockFile recursive mutex #35359

pull sedited wants to merge 1 commits into bitcoin:master from sedited:rmLastBlockFileMutex changing 5 files +29 −34
  1. sedited commented at 12:44 PM on May 22, 2026: contributor

    The cs_LastBlockFile mutex is redundant: all critical sections are already covered by cs_main. This is demonstrated in this patch by replacing all instances of locking cs_LastBlockFile with pairs of AssertLockHeld(::cs_main) and EXCLUSIVE_LOCKS_REQUIRED(::cs_main) annotations. No additional ::cs_main LOCK(...)s are introduced (besides for test-only code).

    It is also not clear for which sections cs_LastBlockFile is responsible for. It is annotated for m_blockfile_cursors, but sporadically and inconsistently also covers m_blockfile_info (e.g. in LoadBlockIndexDB).

    Since it has no semantic meaning, and seems confusing to developers, remove it.

    An alternative to this patch would be expanding the scope of what cs_LastBlockFile covers and turning it into a non-recursive mutex. I prepared such a patch some time ago, but found it unsatisfactory. It was not clear to me if the lock was now covering too much or too little, and its purpose remained unclear. If this patch is accepted, I would expect the project to eventually implement a separate, narrowly-scoped block storage lock to allow for a more parallelizable block processing routine.

  2. blockstorage: Remove cs_LastBlockFile recursive mutex
    The cs_LastBlockFile mutex is redundant: all critical sections are
    already covered by cs_main. This is demonstrated in this patch by
    replacing all instances of locking cs_LastBlockFile with pairs of
    `AssertLockHeld(::cs_main)` and `EXCLUSIVE_LOCKS_REQUIRED(::cs_main)`
    annotations. No additional `::cs_main` LOCK(...)s are introduced.
    
    It is also not clear for which sections `cs_LastBlockFile` is
    responsible for. It is annotated for `m_blockfile_cursors`, but
    sporadically and inconsistently also covers `m_blockfile_info`.
    
    Since it has no semantic meaning, and seems confusing to developers,
    remove it.
    9dc6185d0f
  3. DrahtBot added the label Block storage on May 22, 2026
  4. DrahtBot commented at 12:44 PM on May 22, 2026: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    <!--006a51241073e994b41acfe9ec718e94-->

    Code Coverage & Benchmarks

    For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/35359.

    <!--021abf342d371248e50ceaed478a90ca-->

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK w0xlt
    Approach ACK stickies-v

    If your review is incorrectly listed, please copy-paste <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  5. sedited marked this as ready for review on May 22, 2026
  6. stickies-v commented at 1:36 PM on May 22, 2026: contributor

    Approach ACK. While directionally we aim to minimize cs_main usage, we should only introduce a new (well-scoped) mutex when it actually avoids acquiring cs_main, which cs_LastBlockFile seems to not at all do. Thus, making the code less confusing is a win.

    PR seems pretty straightforward to review with solid assurances that the changes are safe.

  7. w0xlt commented at 2:00 PM on May 22, 2026: contributor

    Concept ACK.


github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-05-22 20:51 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me