mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 10:50:37 +00:00
rpc: Manual prune lock management (Take 2) #34534
No reviewers
Labels
No labels
Android
Backport
Block storage
Brainstorming
Bug
Build system
CI failed
Consensus
Data corruption
Descriptors
Docs
DrahtBot Guix build requested
Feature
Fuzzing
GUI
Good First Review
IPC
Insufficient Review
Kernel
Linux/Unix
Mempool
Mining
Needs Backport (31.x)
Needs Backport (32.x)
Needs Benchmark
Needs Conceptual Review
Needs backport (30.x)
Needs rebase
Needs release note
Net
P2P
PSBT
Privacy
Private Broadcast
Questions and Help
RPC/REST/ZMQ
Refactoring
Resource usage
Review club
Scripts and tools
Settings
TX fees and policy
Tests
Tracking Issue
UTXO Db and Indexes
Up for grabs
Upstream
Utils/log/libs
Validation
Waiting for author
Wallet
Windows
good first issue
interfaces
macOS
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
bitcoin/bitcoin!34534
Loading…
Reference in a new issue
No description provided.
Delete branch "2026-02-prunelocks-rpc-v2"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is a refreshed version of #19463, which was closed due to inactivity.
Motivation: On pruned nodes, if a wallet is not loaded while the node is running, blocks necessary for rescanning when the wallet is loaded may be pruned. This PR allows users and external wallet software to manually manage prune locks via RPC, so they can protect blocks needed for future rescans and also clean up locks that are no longer relevant (e.g. after permanently unloading a wallet from a node). This is useful both for Bitcoin Core's own wallet and for external wallets that use Bitcoin Core as a backend. 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.
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/listbannedexactly. The locks are prefixed to distinguish them from the systems locks and prevent naming colissions. They are not persisted across restarts.The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.
External sites
Reviews
See the guideline and AI policy for information on the review process.
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:
loadtxoutsetRPC with a startup arg by l0rinc)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.
Concept ACK
🚧 At least one of the CI tasks failed.
Task
Windows native, fuzz, VS 2022: https://github.com/bitcoin/bitcoin/actions/runs/21799390662/job/62892243983LLM reason (✨ experimental): Fuzz test failed because the RPC command "listprunelocks" is not registered as safe or unsafe for fuzzing in rpc.cpp.
Hints
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.
Fixing CI failure: Forgot to set
RPC_COMMANDS_[NOT_]SAFE_FOR_FUZZINGfor the new RPCs.Incomplete review. Basically, the original PR interface was way better.
This was an Object for future extensibility. No reason to lose that.
You could get it as copy and don't keep lock while iterating, performance wise.
Done
Done
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 (getpruneinfoor 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.@luke-jr
Is this just about https://github.com/bitcoin/bitcoin/pull/34534#discussion_r2785381112 or did you mean something else?
Addressed feedback from @luke-jr and @bvbfan , thanks for the review!
listprunelockscould 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)What is a "blockman epoch"? I don't think I have heard of that before.
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.
Do you remember at least who mentioned these users/use cases?
This looks potentially interesting, but I don't think we should be implementing RPCs when we don't know anyone that would actually be using them? Since the previous PR has been open since 2020 already without users chiming in, it seems like there's no real demand for this?
This is generally useful in the wallet and for any wallets that leverage Bitcoin Core. The fundamental issue is that if the wallet is not loaded while the node is running, blocks necessary for rescanning when the wallet is loaded may be pruned away. The wallet definitely should be using prune locks, but it's also necessary to have a way to for users to remove prune locks that are no longer relevant, e.g. if they unload a wallet that they don't plan to load on that node again. External wallets that use Bitcoin Core should also find this useful as they can then set prune locks that match the scan state of the external wallet.
Thanks for the explanation @achow101 . Concept ACK. Enabling wallets to build on top of a pruned node via RPC seems enough of a use case to move this forward. @fjahr I think this might be useful to include in PR description to give it more motivation?
Done, replace that vague part of the description with a better motivation paragraph.
One thing that is still not clear to me is how this is actually useful to external applications if the locks are not persisted. I could see how this might be interesting for our own wallets, by setting prune locks for wallets even though they are not loaded yet. But for outside users this seems like a limitation that is difficult to deal with. If you want to add a wallet on startup, wouldn't that require racing to set a lock again if you restart? What is the exact scenario here?
Is there a reason for introducing this helper? Existing validation code that iterates through the locks directly.
Don't we either have to hold this lock while iterating through the prune locks, or copy them? I think my preference would be to just take a copy here.
Hm, it certainly seems like I addressed this comment without thinking about it enough because the surrounding parentesis were unnecessary as well. I am now using a explicit
unordered_mapconstructor now to ensure the copy happens before the lock scope ends and I have added a comment and removed the parenthesis.Addressed latest @sedited feedback, thank you!
First, I think we can agree that it's useful for long-running nodes and the internal wallet, right? So for the following I am still unsure if it should be included here or part of follow-up PR.
For a node that is relaunched only every few weeks for usage of (cold-ish) wallet the persisted lock sounds useful. But I am not sure if just making the locks persistent is actually the best UI for this use-case. The pattern would probably be that the user, before shutdown, sets a prune lock to the last scan height (potentially the tip) and then shuts down. Then on restart the prune lock is respected. But then maybe it would actually be more convenient if there was a startup option
-prunelockedor so where the node can be started with the current tip locked. It could get a height parameter too if an earlier height should be locked. I haven't spent much time thinking if this covers all the use-cases but so far I tend to think the startup option covers what I have in mind and comes with a few upsides: If the node crashes and the user couldn't set the lock before, with persistence they might be still screwed but with the startup option they are safe. And since we could avoid persistence this should be much easier to implement and have less code to maintain.EDIT: Also, for certain wallets that really need a lot of control, there is always the option to manually prune as well.
m_prune_locksis private and the direct access to it invalidation.cppis only possible becauseChainStateis a friend class ofBlockManager. Of course we could also just make it public but a getter method seemed nicer to me.The case is still not quite clear to me to be honest. Would the wallet start tracking prune locks for unloaded wallets? Afaict it doesn't currently hold a lock during rescan - that does indeed seem like something useful. I can also see how deleting / cleaning up existing locks could be useful, though it also feels like bit of a footgun. I'm having a hard time thinking of a scenario where you can robustly race a node pruning and important an existing wallet / descriptor. The startup option does seem better to me too.
Thanks, I have added a minimal implementation of the startup option because so far seems like a clearly useful feature to me if outside wallets want to use prune locks in any capacity. But conceptual feedback still very welcome!
I think so? I could see something like this become more common in the future when more users switch on pruning to avoid having to get a larger disk. I would expect there are wallet options that market themselves being compatible with (possibly aggressive) pruning on the node and that this option will become more common in the future. But of course it would be a stronger statement to hear from an implementer directly that they would use such a feature. I just looked at the sparrow docs as a start and they are rather "hands-off" so far and just warn about potential issues: https://sparrowwallet.com/docs/connect-node.html#pruned-nodes
Rebased
Rebased
ACK 9465be6fd01138246337ec91745d08a65f7bea66
Nit: Why not duplicate the description from setprunelock to describe their mechanics? The description here feels a bit incomplete, since it does not just prevent pruning at a single height.
Fair, I will address it the next time I touch this.
Thanks for the review ping, I was not aware of this PR.
I started looking and it looks interesting - also helpful if it can be leveraged by the wallet (or by external ones).
Can't there be a case wherein this new argument causes the -prune= option to not be respected? If this has already been discussed before, please point me to that conversation.
Yes, unless I am misunderstanding your question that is the whole idea behind prune locks, to temporarily protect certain block ranges from pruning if there is some work left to do. I added that functionality here a few years ago with the initial goal to let indexes catch up without the necessary blocks disappearing suddenly if they are running on a pruned node. The basic discussion can be found there. This PR only allows to configure these prune locks via RPC which may be interesting for external wallets for example. Does that answer your question?
Sorry for the delay in getting back here, I should be able to get to it this week.
Overall, I feel this PR needs to market itself a bit. Either in the release notes or maybe a new section in the docs/ directory. I worry that this feature would be underutilised or, worse, unused because of lack of awareness. The motivation in the PR description and the use cases discussed in the PR comments previously can be listed there.
From https://github.com/bitcoin/bitcoin/pull/34534#issuecomment-4092098083:
Also, a functional test for wallet exercising prune locks that solves the above scenario would be nice. Using prune locks temporarily instead of manually importing via importprunedfunds RPC (which requires the the proof via another RPC - gettxoutproof) seems like a more natural choice to me (can be a part of the motivation/marketing).
Ok, can add a sentence here that this option will cause the -prune option to not be respected - just to be explicit.
The changes in this file require a release note because of new RPCs being added.
Along with the new startup option.
There isn't a check that forbids locking blocks that'd be generated in the future. Is it intentional?
The following test change passes:
Is this correct? The following diff passes where this value is halved along with the corresponding heights in the pruneblockchain RPCs.
Based it off of this conditional:
github.com/bitcoin/bitcoin@142e86a65c/src/kernel/chainparams.cpp (L603)prune_height_locked is -1 because the lock prevents the pruning from happening.
I don't see much point in asserting that prune_height_unlocked is greater than prune_height_locked.
Good idea, done!
Hm, for me the proposed diff fails because the blocks are not enough to get actual pruning. I am not sure why it would pass for you and not for me, it's possible that there is some dependency on filesystems but I usually try to tweak these values to the minimum that works reliably locally.
Changed this to check for -1 and >0 more explicitly now.
Right, added the necessary release notes!
Right, that's a good observation, I didn't think about this explicitly so far but I don't see harm in allowing this and it may even be useful for some use-cases. So I tend to say I would keep allowing it and I have added a note in the docs on it. But if you (or other reviewers) strongly prefer these values to be rejected I can be convinced to do that as well.
Addressed feedback by @rkrux , thanks a lot!
I added release notes per your inline comment
I added this in a separate commit. I folded it into the existing test file since generating all those blocks is pretty expensive and I didn't see this justifying a new functional test file. Let me know what you think.
Re-ACK 9fa4953f01cab3ab8669b316224b4eeb8433a8d8
Maybe mention here that the lock may be viewed by
listprunelockand removed bysetprunelock.Well, now that you say it.... the
setprunelockremoval part wasn't actually possible because of the forcedrpc:prefix which the init option didn't use. I changed this and renamed the prefix touser:since it's not strictly used by RPCs anymore. Otherwise, removing the lock would have required a restart.I'm not sure I find the motivation compelling. Would the same functionality be achieved via the
pruneblockchainRPC and a-prune=1setting? This way a user can have all their wallets sync, and then callpruneblockchain. Keeping the node running would not prune on its own.Partly yes, but I think it would be much more complex and difficult to implement managing that behavior on the side of an external wallet. With
-prune=1nothing is pruned unlesspruneblockchainis called and to achieve some kind of constant disk usage threshold it needs to be called regularly. In order to decide when to prune the wallet would need to monitor disk usage constantly and then decide with which height to callpruneblockchain. It basically means the wallet has the burden to reimplement our automatic pruning logic, just to get that extra bit of control that the pull here provides. It gets even trickier if there are multiple consumers of RPC that need that pruning control, like a wallet and an external index, with management RPCs they both can set their locks as they need and it should be simple to implement that.3 additional verified findings in the Review report.
Earlier concerns neither republished nor resolved: 1 suggestion. See the Run archive linked from the Review report for their assessments.
🟠 Minor ·
-prunelockis installed after IPC submissions can trigger pruningWith
-ipcbindand automatic pruning, an early trusted mining submission can prune protected data before startup locks are installed; no current client exercising this window or resulting incident was identified.Location:
src/init.cpp:2076(head).🟠 Minor · Future-height user locks collapse after an unrelated tip disconnect
Although the help documents rollback, a future-height reservation becomes a fixed near-tip lock after one disconnect and can make automatic pruning exceed its target until the lock is updated or removed.
Location:
src/rpc/blockchain.cpp:1003(head).🔵 Suggestion ·
setprunelockhelp omits how to retain protection across restartsRPC locks disappear before startup pruning, so restoring them after reconnecting can be too late; the RPC help does not direct users to configure
-prunelockbeforehand.Location:
src/rpc/blockchain.cpp:1001(head).🔵 Suggestion · The startup-lock test checks log order without exercising destructive pruning
The startup check cannot distinguish effective protection from correctly logged registration, because its
-prune=1restart cannot delete files.Location:
test/functional/rpc_prunelock.py:235(head).🔵 Suggestion · User-lock reorg rollback has no regression assertion
The help promises that user locks move down to the fork height and stay there, but the tests never disconnect a block while a user lock is present.
Location:
test/functional/rpc_prunelock.py:138(head).🔵 Suggestion ·
-debug=prunemessages omit the lock namespaceWhen internal and user locks share an id, pruning diagnostics identify only the name, obscuring which lock limited pruning or moved during a reorg.
Location:
src/validation.cpp:2804(head).Review coverage was incomplete.
Reviewed:
dd6c67b0e5f6· Review report · Previous reportspermalink
Re-ACK
67960317cdThe lock is registered here, but the startup prune at L1962–1972 already ran in Step 10. So restarting with
-prune=550 -prunelockheight=Hwhile block-file usage is above the target can delete the blocks the lock should keep, then sets the lock. Index prune locks don't have this problem because they're registered in Step 8, before the prune.The test diff below shows it on
67960317cd: it runs with-prune=550 -fastprune -prunelockheight=<tip+1>until usage is over the target, then restarts with the same args. Thegetblockon the locked height fails withBlock not available (pruned data), and debug.log showsremoved 63 blk/rev pairsbeforeInitial prune lock set at height 2101. Moving the registration before Step 10 (after chainstate load so the tip is available for=0) makes the test pass for me.The PR's own
rpc_prunelock.pydoesn't catch this because it uses-prune=1, which never prunes automatically.diff
🚧 At least one of the CI tasks failed.
Task
iwyu: https://github.com/bitcoin/bitcoin/actions/runs/41248829209/job/124677834304LLM reason (✨ experimental): CI failed because IWYU reordered/added includes in
src/rpc/blockchain.cpp, leaving a diff that the lint check rejects.Hints
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.
Good catch, thanks. Moved the lock add before the initial prune and added a minimal test that checks the debug log for it. Your suggested test seemed a bit too heavy for my taste.
Also rebased and fixed a silent merge conflict.
Concept ACK
The release notes also don't mention the 0 case meaning tip here.
Hmm I think setting an explicit 0 value should set to genesis block, same as the RPC. What is the rationale for making 0 use tip? Using no-value to mean tip could make sense though.
This comment doesn't seem to add any value here IMO.
Same with this comment. It doesn't seem necessary.
nit
I think this second note can be struck. It describes an implementation detail that should have no effect on usage. To me it seems it doesn't give the user any useful information.
The test framework has
has_blockfilewhich could be used instead of this.Concept ACK.
A concrete use case for this: an Electrum server (
electrs) backed by a pruned node. External indexers have only come up in passing here, so here is a data point.I prototyped a patched
electrson top of this PR and completed indexing on a pruned signet node (-prune=550). It uses the prune lock like this:user:electrs) at the first block not indexed yet, then remove theinitlock-prunelockheight=<n>(at or below the indexed height) keeps the needed blocks until electrs reconnects and sets its lock againFor this use case the startup option is enough, and locks don't need to be persisted. It does rely on the lock being in place before the startup prune (thanks for the fix in response to https://github.com/bitcoin/bitcoin/pull/34534#issuecomment-6524831809). The setup is resilient for either of the processes being stopped for a period.
Out of scope here, but for context: there is a constraint in how the two processes are started (electrs has to be started before bitcoind starts to prune); relaxing this may require some new mechanism. Also, serving transactions from blocks that were pruned before indexing will need more work (an indexer-side concern).
I'll review the code later.
Concept ACK. Manual prune locks are needed to support external indexers on a pruned node. Some comments with that use case in mind:
Initial lock. Its purpose is to keep the blocks an external app needs from being pruned while the app is not connected (not started yet, restarting, etc.). Rather than a general init lock, it could be the initial placement of the app's own lock, which the app then takes over. A height isn't needed either: the app controls the height, and until it connects the safest default is "don't prune anything".
Suggestion: replace
-prunelockheight=<n>with-prunelock=<id>, where<id>is the same id the app uses withsetprunelock. When the app connects, itssetprunelockcall simply updates this lock, with no separate init lock to clean up. This way the app can safely remove or update "its" lock (with the same id).The option goes in the node's config file and stays there as long as the app is in use. It could be extended later with
[:<height>], though I don't see a strict need for that now. The trade-off is that no pruning happens until the app connects, so disk usage can go above the -prune target for that time. (I briefly discussed this idea with the author offline.)Persistence. I agree that locks don't need to be persisted. If bitcoind starts with
-prunelock=<id> and the app soon connects and callssetprunelock, the setup is robust. The app knows its own persisted state, and the node only has to make sure nothing is pruned while the app is away. Persisting locks would allow more fine-tuned pruning in some cases. For example: the indexer has reached height 800, blocks are pruned up to 600, and the node restarts before the indexer does. Without a persisted lock, the node cannot prune until the indexer reconnects, so disk usage grows. With one, it could prune roughly 600–799. But persistence adds complexity, such as having to remove stale persisted locks by hand.0 meaning "tip" in
-prunelockheight. In this PR,-prunelockheight=0locks at the startup tip, whilesetprunelock <id> add 0(also the default when height is omitted) locks at height 0, which means nothing is pruned. The same value has opposite meanings, and code that treats the lowest height as "keep everything" would use it the wrong way.The natural values are 0 for "keep everything" and "infinity" for "no lock" (
height_first alreadydefaults to max int). I'd use a separate value for "lock at the current tip", such as -1 or a named value like "tip". -1 has its own pitfalls (a negative number where heights are otherwise non-negative, and the current check that rejects negative heights). So I'd suggest named value "tip" in the RPC commands and max int in the internal representation for tip.Addressed now in the latest push since @andrewtoth had a similar comment
Done
Removed
Ah, nice, replaced the helper with
has_blockfile.Removed
Removed
With the latest push we now have
-prunelock=<id>which doesn't take a height and always locks at height 0, so this comment should be obsolete.Same reason as above, since there is no height parameter with the latest version this comment is obsolete.
Addressed the feedback from @andrewtoth and @optout21, thanks for the reviews!
The main change is that
-prunelockheight=<n>is replaced by-prunelock=<id>in response to @optout21 's explicit use case description. The option creates a lock with the given id at height 0 before the startup prune, so nothing is pruned until the lock is updated or removed withsetprunelockusing the same id. It can be specified multiple times. This removes the "handover" of theinitlock to the lock of the specific app, and it also works if more than one app needs a lock.Since it doesn't seem strictly necessary for the discussed use cases to have the explicit height or tip functionality, this is left out for now to keep things simple.
So here we are rejecting lock names with
:in the config args. However, we don't reject them via RPC.Is this to support a future change to lock by height?
If so we should also enforce this restriction via RPC, so users who choose names with
:aren't blocked from using them as a startup config arg after the fact.We should also have a more useful error message, describing why it's invalid.
Otherwise we should remove this restriction.
🚧 At least one of the CI tasks failed.
Task
test ancestor commits: https://github.com/bitcoin/bitcoin/actions/runs/45074726945/job/137369313684LLM reason (✨ experimental): CI failed during linking because
libbitcoinkernel.sohas an undefinedSanitizeString(std::string_view, int)symbol.Hints
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.
Yes, that was the idea. But the inconsistency between init option and RPC is indeed problematic. The best solution to me seemed to remove the ambiguity by just adding the option to add height to the init option now so that both ways to set the lock and work the same way. As a default to both now the height can be omitted and then genesis is the height default, which means that the init option can still be used as discussed based on the feedback from @optout21 . If there are duplicate init options (multiple in config file or config file and command line) then the lowest height is used. I also made parsing and error messages much more explicit.
tACK
d025cf1dc7Tested on Ubuntu 22.04.5 (x86_64, GCC 11.4), signet node with pruning, wallet loaded.
rpc_prunelock.pypasses, and the unit tests pass (378/378).pruneblockchain 331500did not advancepruneheight(329114) and block 330000 stayed available. Aftersetprunelock <id> remove, the same call pruned to 330933 andgetblock 330000returned "Block not available (pruned data)". Note that the lock applies per blk file, so blocks a bit below the lock height can also be kept. That looks expected.listprunelocksshows theuser:prefix. Manual locks are gone after a restart, as documented.-prunelock=a:331500 -prunelock=a:331200 -prunelock=bgivesaat 331200 (the lowest height) andbat 0.remove, unknown command, negative height,-prunelockwithout-prune, and an invalid-prunelockvalue.Two small points on the
setprunelockhelp:heightargument saysdefault=0and also "(only required for "add")".addwithout a height is accepted and sets the lock at 0, so the height is not really required. Maybe "(only used for "add")"?setprunelock <id> remove 123is accepted and the height is silently ignored. That's not a problem, but it could be rejected, or the help could mention it.Reviewed (
d025cf1). Comments:A side effect worth exploring: during any reorg, all prune locks above
tip-1are set totip-1. Maybe this should not apply on manual blocks. The lowering is done inChainstate::DisconnectTip().No unit tests for the parsing helpers
IsValidPruneLockIdandParsePruneLockArg.listprunelocksreturnsuser:testlock, butsetprunelockonly acceptstestlock. Passinguser:testlockfails because:isn't allowed. Should be more consistent.The order of the result is undefined. Maybe it could be sorted deterministically after it has been obtained.
Maybe a check for pruned node should be here, as in e.g.
pruneblockchain.Not sure if it's that important but it was easy to switch from
std::unordered_maptostd::mapso I did that.Yeah,
setprunelocknow fails if the node is not in prune mode.Thanks for the review @optout21!
I think this should still apply to manual locks too. An external indexer could run behind the chain just like the internal indexes and needs the blocks from the fork point on to handle the reorg. But you are right that this could be surprising behavior, so I add some mention of this in the
setprunelockhelp.The functional test covers a lot of invalid ids and values through both
setprunelockand-prunelockwhich should provide good coverage of these helpers, so I left this as is.Right, the inconsistency could be confusing to some users. I opted for changing
listprunelocksso it returns the id without the prefix and has a newtypefield (userorinternal), so a listed id could be passed tosetprunelock.re-ACK
20cb220b55Re-tested on Ubuntu 22.04.5, on a pruned signet node:
rpc_prunelock.pyand the unit tests pass (378/378).setprunelocknow fails with "Cannot set a prune lock because node is not in prune mode."listprunelocksreturns ids without theuser:prefix, with the newtypefield, sorted by id. An id from the list can be passed directly tosetprunelock <id> remove.pruneblockchain 332150kept block 331900.ACK
20cb220b55@fjahr , thanks for considering my points.
On the reorg issue: I agree. If there is a reorg, the external indexer will likely reindex the reorged height again as well.
ACK
20cb220b55Concluding my previous reviews with an ack, looks good!
A new comment/suggestion: Internally, the "user:" prefix is used to mark external locks. This is internal now -- added automatically by add, removed automatically when listed. The magic string prefix could be replaced by a bool flag or enum (but has to be part of the key, a composite key). This scheme would be less error prone, but also less flexible. Or, if the "user:" prefix is indeed internal, at least replace it with the more visible "USER:" or "EXT:" form.
I agree that this would be cleaner and clearer and decided to implement this in another push. Sorry for invalidating the ACKs one more time but I hope the rest of the reviewers agree that this is better. I went with an enum to allow for new types like the wallet to be added later. Or if indexes are moved outside of the node at some point they may get a different category.
The change is roughly neutral in terms of LOC added/removed so I think the change overall get easier to review but those that need to re-review see a bit of churn, again sorry about that:
github.com/bitcoin/[email protected]reACK
dd6c67b0e5Sorry for triggering another ack-cycle, I'm keen on this PR to land :)
The enum is more pleasing than the string prefix operations (comparison, removal, etc.). Thanks for taking it!
git range-diff 20cb220...dd6c67bgit range-diff 1b2c63d..20cb220 9601d8c..dd6c67breACK
dd6c67b0e5