Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
df7a8c4 to
f192b06
Compare
|
Fixing CI failure: Forgot to set |
luke-jr
left a comment
There was a problem hiding this comment.
Incomplete review. Basically, the original PR interface was way better.
| "These locks are used internally by indexes and can also be set manually via the setprunelock RPC.\n", | ||
| {}, | ||
| RPCResult{ | ||
| RPCResult::Type::ARR, "", "", |
There was a problem hiding this comment.
This was an Object for future extensibility. No reason to lose that.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
What is a "blockman epoch"? I don't think I have heard of that before.
There was a problem hiding this comment.
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.
f192b06 to
0032cee
Compare
Is this just about #34534 (comment) or did you mean something else? |
0032cee to
b7fc779
Compare
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. |
Done, replace that vague part of the description with a better motivation paragraph. |
sedited
left a comment
There was a problem hiding this comment.
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?
| ChainstateManager& chainman = EnsureAnyChainman(request.context); | ||
| UniValue locks_arr(UniValue::VARR); | ||
| { | ||
| const auto prune_locks = WITH_LOCK(::cs_main, return chainman.m_blockman.GetPruneLocks()); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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_map constructor now to ensure the copy happens before the lock scope ends and I have added a comment and removed the parenthesis.
| bool DeletePruneLock(const std::string& name) EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | ||
|
|
||
| //! Return the current set of prune locks. | ||
| const std::unordered_map<std::string, PruneLockInfo>& GetPruneLocks() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { return m_prune_locks; } |
There was a problem hiding this comment.
Is there a reason for introducing this helper? Existing validation code that iterates through the locks directly.
There was a problem hiding this comment.
m_prune_locks is private and the direct access to it in validation.cpp is only possible because ChainState is a friend class of BlockManager. Of course we could also just make it public but a getter method seemed nicer to me.
b7fc779 to
c7ac2d8
Compare
|
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 EDIT: Also, for certain wallets that really need a lot of control, there is always the option to manually prune as well. |
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 |
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
tACK d025cf1 Tested on Ubuntu 22.04.5 (x86_64, GCC 11.4), signet node with pruning, wallet loaded.
Two small points on the
|
optout21
left a comment
There was a problem hiding this comment.
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.
70c2230 to
20cb220
Compare
|
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
The functional test covers a lot of invalid ids and values through both
Right, the inconsistency could be confusing to some users. I opted for changing |
|
re-ACK 20cb220 Re-tested on Ubuntu 22.04.5, on a pruned signet node:
|
|
ACK 20cb220 |
|
@fjahr , thanks for considering my points. |
|
ACK 20cb220 Concluding 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. |
This is needed in RPCs that manage prune locks manually.
These allow for manual management of prune locks by users and follow the UX pattern of setban/listbanned. Co-authored-by: Luke Dashjr <[email protected]>
This allows to start a node with a prune lock already set in order to avoid racing with any unwanted pruning.
20cb220 to
dd6c67b
Compare
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: https://github.com/bitcoin/bitcoin/compare/20cb220b55f746a8b4538f640aee374604863c85..dd6c67b0e5f6ffe184d101281eb107fcf32a26f6 |
|
reACK dd6c67b Sorry for triggering another ack-cycle, I'm keen on this PR to land :)
|

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.