rpc: Manual prune lock management (Take 2) #34534

pull fjahr wants to merge 3 commits into bitcoin:master from fjahr:2026-02-prunelocks-rpc-v2 changing 7 files +271 −1
  1. fjahr commented at 2:01 pm on February 8, 2026: contributor

    This is a refreshed version of #19463, which was closed after inactivity but there was some mentions of users/external applications at the last CoreDev that would be interested in using this. Unfortunately, I can not recall who was mentioned as a potential user but I would appreciate if someone could ping them to take a look if this is still relevant to them.

    This PR leverages the existing prune locks system we already have. The interface of the RPCs of the old PR has been slightly updated, it now matches the pattern used by setban/listbanned exactly. The locks are prefixed to distinguish them from the systems locks and prevent naming colissions. They are not persisted across restarts.

    Usage of temporary prune locking may also be helpful in other functional test scenarios but I didn’t spend time to check where might apply.

  2. blockstorage: Add prune locks helper methods
    These are helpful for RPC methods to manage prune locks manually.
    22709b0adf
  3. DrahtBot added the label RPC/REST/ZMQ on Feb 8, 2026
  4. DrahtBot commented at 2:01 pm on February 8, 2026: contributor

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

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    Concept ACK sedited

    If your review is incorrectly listed, please copy-paste <!–meta-tag:bot-skip–> into the comment that the bot should ignore.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #34049 (rpc: Disallow captures in RPCMethodImpl by ajtowns)

    If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

  5. sedited commented at 2:15 pm on February 8, 2026: contributor
    Concept ACK
  6. DrahtBot added the label CI failed on Feb 8, 2026
  7. DrahtBot commented at 3:19 pm on February 8, 2026: contributor

    🚧 At least one of the CI tasks failed. Task Windows native, fuzz, VS 2022: https://github.com/bitcoin/bitcoin/actions/runs/21799390662/job/62892243983 LLM reason (✨ experimental): Fuzz test failed because the RPC command “listprunelocks” is not registered as safe or unsafe for fuzzing in rpc.cpp.

    Try to run the tests locally, according to the documentation. However, a CI failure may still happen due to a number of reasons, for example:

    • Possibly due to a silent merge conflict (the changes in this pull request being incompatible with the current code in the target branch). If so, make sure to rebase on the latest commit of the target branch.

    • A sanitizer issue, which can only be found by compiling with the sanitizer and running the affected test.

    • An intermittent issue.

    Leave a comment here, if you need help tracking down a confusing failure.

  8. fjahr force-pushed on Feb 8, 2026
  9. fjahr commented at 3:29 pm on February 8, 2026: contributor
    Fixing CI failure: Forgot to set RPC_COMMANDS_[NOT_]SAFE_FOR_FUZZING for the new RPCs.
  10. DrahtBot removed the label CI failed on Feb 8, 2026
  11. in src/rpc/blockchain.cpp:886 in f192b06a3b
    881+        "Returns a list of all active prune locks.\n"
    882+        "Prune locks prevent block data at specific heights from being pruned.\n"
    883+        "These locks are used internally by indexes and can also be set manually via the setprunelock RPC.\n",
    884+        {},
    885+        RPCResult{
    886+            RPCResult::Type::ARR, "", "",
    


    luke-jr commented at 1:51 am on February 10, 2026:
    This was an Object for future extensibility. No reason to lose that.

    fjahr commented at 1:54 pm on February 18, 2026:
    The RPC is called listprunelocks, I don’t see how it could be extended to return anything else aside from a list of locks without that other thing feeling out of place. Can you give some specific ideas that you have? At least I would want to give the RPC a different name then (getpruneinfo or so) but potentially these ideas should rather be in a separate RPC. I prefer consistency and so I really like that we could be consistenty with the banning RPC.

    maflcko commented at 2:28 pm on February 18, 2026:
    listprunelocks could return a “blockman epoch” in the future, if there was need to further distinguish rpc results. (Yes, this is made up, but with an array, this is impossible, with an object, this is trivial and harmless)

    fjahr commented at 2:35 pm on February 18, 2026:
    What is a “blockman epoch”? I don’t think I have heard of that before.

    fjahr commented at 3:40 pm on February 19, 2026:
    I guess TIL per this comment that the JSON object thing is in the dev notes, fair enough, I have changed it to return an object.
  12. in src/rpc/blockchain.cpp:890 in f192b06a3b
    885+        RPCResult{
    886+            RPCResult::Type::ARR, "", "",
    887+            {
    888+                {RPCResult::Type::OBJ, "", "",
    889+                {
    890+                    {RPCResult::Type::STR, "name", "The identifier of the prune lock"},
    


    luke-jr commented at 1:51 am on February 10, 2026:
    0                    {RPCResult::Type::STR, "id", "The identifier of the prune lock"},
    

    fjahr commented at 1:54 pm on February 18, 2026:
    Done
  13. luke-jr changes_requested
  14. luke-jr commented at 1:53 am on February 10, 2026: member
    Incomplete review. Basically, the original PR interface was way better.
  15. in src/rpc/blockchain.cpp:905 in f192b06a3b
    900+{
    901+    ChainstateManager& chainman = EnsureAnyChainman(request.context);
    902+    UniValue locks_arr(UniValue::VARR);
    903+    {
    904+        LOCK(::cs_main);
    905+        const auto& prune_locks = chainman.m_blockman.GetPruneLocks();
    


    bvbfan commented at 6:56 am on February 10, 2026:

    You could get it as copy and don’t keep lock while iterating, performance wise.

    0const auto prune_locks = WITH_LOCK(::cs_main, return chainman.m_blockman.GetPruneLocks());
    

    fjahr commented at 1:54 pm on February 18, 2026:
    Done
  16. fjahr force-pushed on Feb 18, 2026
  17. fjahr commented at 1:55 pm on February 18, 2026: contributor

    @luke-jr

    Basically, the original PR interface was way better.

    Is this just about #34534 (review) or did you mean something else?

  18. fjahr commented at 1:55 pm on February 18, 2026: contributor
    Addressed feedback from @luke-jr and @bvbfan , thanks for the review!
  19. rpc: Add setprunelock and listprunelocks
    These allow for manual management of prune locks by users and follow the UX pattern of setban/listbanned.
    
    Co-authored-by: Luke Dashjr <luke-jr+git@utopios.org>
    1f9cfa1a88
  20. test: Add manual prune lock RPC coverage b7fc779c01
  21. fjahr force-pushed on Feb 19, 2026

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-03-15 09:13 UTC

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