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 +266 −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.

    LLM Linter (✨ experimental)

    Possible places where named args for integral literals may be used (e.g. func(x, /*named_arg=*/0) in C++, and func(x, named_arg=0) in Python):

    • node.setprunelock(“testlock”, “add”, 100) in test/functional/rpc_prunelock.py
    • node.setprunelock(“testlock”, “add”, 200) in test/functional/rpc_prunelock.py
    • node.setprunelock(“another”, “add”, 300) in test/functional/rpc_prunelock.py
    • assert_raises_rpc_error(-8, “Prune lock name must not be empty”, node.setprunelock, “”, “add”, 100) in test/functional/rpc_prunelock.py
    • assert_raises_rpc_error(-8, “Block height must not be negative”, node.setprunelock, “badlock”, “add”, -1) in test/functional/rpc_prunelock.py
    • node.setprunelock(“protect_early”, “add”, 2) in test/functional/rpc_prunelock.py
    • node.setprunelock(“ephemeral_lock”, “add”, 100) in test/functional/rpc_prunelock.py
    • node.setprunelock(“genesis”, “add”, 0) in test/functional/rpc_prunelock.py

    2026-02-08 15:29:01

  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. 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>
    418f549350
  9. test: Add manual prune lock RPC coverage f192b06a3b
  10. fjahr force-pushed on Feb 8, 2026
  11. 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.
  12. DrahtBot removed the label CI failed on Feb 8, 2026
  13. 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.
  14. 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"},
    
  15. luke-jr changes_requested
  16. luke-jr commented at 1:53 am on February 10, 2026: member
    Incomplete review. Basically, the original PR interface was way better.
  17. 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());
    

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-02-17 06:13 UTC

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