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. LLM Linter (✨ experimental)Possible internal implementation names in log messages:
2026-10-30 00:40:51 |
pablomartin4btc
left a comment
There was a problem hiding this comment.
Concept ACK.
I reviewed the commits individually. The split between public self-locking methods and lock-held helpers makes sense to me, and the external lock removals seem correct now that descriptor accessors return/ use state under their own lock. I left one question around listdescriptors, where two descriptor reads are now done through separate self-locking calls instead of under one caller-held lock, and a minor readability suggestion regarding the cs_desc_man lock removal in addhdkey().
| return op_dest; | ||
| LOCK(m_desc_mutex); | ||
| auto dest{GetNewDestination_(type)}; | ||
| if (dest) index = m_wallet_descriptor.next_index - 1; |
There was a problem hiding this comment.
Nice cleanup: this avoids updating index after a failed destination request.
| @@ -544,7 +544,6 @@ RPCMethod listdescriptors() | |||
| if (!desc_spk_man) { | |||
| throw JSONRPCError(RPC_WALLET_ERROR, "Unexpected ScriptPubKey manager type."); | |||
| } | |||
| LOCK(desc_spk_man->cs_desc_man); | |||
There was a problem hiding this comment.
I think removing the external lock here is fine now that GetWalletDescriptor() and GetDescriptorString() are self-locking. One subtle difference is that the descriptor metadata and descriptor string are now read under two separate locks instead of one caller-held lock. I don’t see an issue because descriptor state should not normally change concurrently here, but I wanted to double-check that no atomicity across these two reads was intended.
There was a problem hiding this comment.
Yes, I also think it is safe because listdescriptors holds wallet->cs_wallet across both calls. Any update that could change either the descriptor metadata or descriptor string also needs cs_wallet, so it cannot run between those two reads.
| @@ -905,7 +904,6 @@ RPCMethod addhdkey() | |||
|
|
|||
| UniValue response(UniValue::VOBJ); | |||
| const DescriptorScriptPubKeyMan& desc_spkm = spkm->get(); | |||
| LOCK(desc_spkm.cs_desc_man); | |||
| std::set<CPubKey> pubkeys; | |||
| std::set<CExtPubKey> extpubs; | |||
| desc_spkm.GetWalletDescriptor().descriptor->GetPubKeys(pubkeys, extpubs); | |||
There was a problem hiding this comment.
Very minor readability nit: would it be clearer to first store the result of GetWalletDescriptor() in a local variable and then call GetPubKeys() on it? That would make it more obvious that the operation is performed on a copied descriptor returned by the accessor, rather than directly on internal SPKM state.
| desc_spkm.GetWalletDescriptor().descriptor->GetPubKeys(pubkeys, extpubs); | |
| auto wallet_descriptor = desc_spkm.GetWalletDescriptor(); // locks internally, returns copy | |
| wallet_descriptor.descriptor->GetPubKeys(pubkeys, extpubs); // operates on the copy |
6f3f81c to
f762354
Compare
|
Rebased. |
f762354 to
2bd9f4d
Compare
|
Ping for rebase @w0xlt |
2bd9f4d to
4bb39d5
Compare
4bb39d5 to
56ca23f
Compare
56ca23f to
b6d5866
Compare
|
Rebased. |
| index = m_wallet_descriptor.GetNext() - 1; | ||
| return op_dest; | ||
| auto dest{GetNewDestination_(type)}; | ||
| if (dest) index = m_wallet_descriptor.GetNext() - 1; |
There was a problem hiding this comment.
in 2f2cc56 wallet: split descriptor SPKM locked internals
The commit message claims there is no behavior change in this commit, but this is indeed a behavior change as now it only writes the index on success, before it was writing it in success and in case of failure.
| } | ||
|
|
||
| // TopUp | ||
| spkm->TopUpWithDB(batch); |
There was a problem hiding this comment.
in dadc205 wallet: stop locking descriptor SPKM externally
After removing this line, no one uses TopUpWithDB anymore. Maybe could also remove the protected wrapper?
| { | ||
| LOCK(cs_desc_man); | ||
| std::string error; | ||
| if (!CanUpdateToWalletDescriptor(descriptor, error)) { |
There was a problem hiding this comment.
in 2f2cc56 wallet: split descriptor SPKM locked internals
After removing this, CanUpdateToWalletDescriptor is only used by a fuzz test, but not real code. Consider removing the function entirely.
3d5e077 to
f3bad2b
Compare
|
🚧 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. |
f3bad2b to
5426d8d
Compare
| } | ||
| changed = before != CanGetAddresses_(); | ||
| } | ||
| if (changed) NotifyCanGetAddressesChanged(); |
There was a problem hiding this comment.
in 04b7fc1 wallet: make descriptor SPKM mutex non-recursive
Correct me if I am wrong, but SetupDescriptorGeneration, SetupDescriptor and UpdateWithSigningProvider run before the new constructed SPKM is returned so they don't have any signal subscribers yet. This makes calling NotifyCanGetAddressesChanged useless.
Because of that all the change detection logic calling CanGetAddresses_() is also unecessary.
5426d8d to
2811f44
Compare
2811f44 to
b38237f
Compare
|
Rebased |
pablomartin4btc
left a comment
There was a problem hiding this comment.
ACK b38237f
Thanks for taking the suggestions.
Verified @polespinasa's feedback is properly addressed and code rebased.
Left a non-blocking comment.
| BOOST_CHECK(!spkm->GetReservedDestination(OutputType::BECH32, /*internal=*/false, index)); | ||
| BOOST_CHECK_EQUAL(index, -1); | ||
| check_notifications({}); | ||
| } |
There was a problem hiding this comment.
One thing, non-blocking: in b3f2503 ("wallet: make descriptor SPKM mutex non-recursive"), in desc_spkm_availability_notifications, the sub-test exercising UpdateWalletDescriptor() throwing mid-top-up and still firing a notification before rethrowing (failed_descriptor.SetEnd(5) / HasReason("Could not top up scriptPubKeys") / check_notifications({true})) is gone — was dropping this coverage intentional?
There was a problem hiding this comment.
Good catch, thanks. It was dropped unintentionally while addressing #35444 (comment).
Prepare DescriptorScriptPubKeyMan for making cs_desc_man non-recursive by separating public lock-taking entry points from helpers that require cs_desc_man to already be held. This removes recursive calls from the core descriptor paths. The public mutex remains recursive and externally accessible in this commit, so existing call sites continue to build while locked helpers centralize the shared logic used by keypool top-up, descriptor updates, address generation, and descriptor matching. Remove the public CanUpdateToWalletDescriptor wrapper, which is only used by the fuzz harness. Have the harness call UpdateWalletDescriptor under cs_wallet so updates exercise the same validation as production callers. GetReservedDestination() now sets the output index only when destination creation succeeds, leaving it unchanged on failure. Existing wallet callers already ignore this output on failure, so their behavior is unchanged.
Move the remaining descriptor SPKM callers to self-locking public methods instead of taking cs_desc_man directly. This removes direct locks from wallet, RPC, and fuzz code and lets DescriptorScriptPubKeyMan own synchronization for its descriptor state. External signer wallet creation also stops mutating m_wallet_descriptor under a direct external lock. It now calls SetupDescriptor, which performs the same descriptor write and top-up sequence behind the SPKM API. Remove the now-unused protected TopUpWithDB wrapper. Internal callers continue to use the lock-held TopUpWithDB_ helper. The mutex remains recursive and public in this commit, so this is a call-site cleanup that sets up the final non-recursive conversion without changing wallet behavior.
Make cs_desc_man private and replace RecursiveMutex with Mutex. Annotate self-locking entry points with negative lock requirements and retain LOCKS_EXCLUDED on factory-only setup methods. Move address-availability notifications to outer operations on existing SPKMs. Compare availability before and after each operation under the mutex, then notify after unlocking so synchronous callbacks can query the wallet safely. Notify only for a net change and rethrow captured exceptions after notification. Factory initialization takes the mutex without change tracking or notifications, since newly constructed SPKMs have no signal subscribers. Add a watch-only hardened-descriptor regression test covering synchronous callback re-entry, address consumption and return, range extension, unchanged availability, and partial failures.
Now that DescriptorScriptPubKeyMan::cs_desc_man is a non-recursive, private Mutex, rename it to m_desc_mutex to match the member-mutex naming convention adopted by the other RecursiveMutex->Mutex conversions. No behavior change. -BEGIN VERIFY SCRIPT- sed -i 's/cs_desc_man/m_desc_mutex/g' $(git grep -l cs_desc_man -- '*.cpp' '*.h') -END VERIFY SCRIPT-
b38237f to
2cde6f9
Compare
pablomartin4btc
left a comment
There was a problem hiding this comment.
re-ACK 2cde6f9
Since my last review: rebased (I've verified that range-diff shows only the trailing-newline log fixes required after #36397), plus the restored UpdateWalletDescriptor() failing-top-up sub-test in desc_spkm_availability_notifications (thanks for addressing #35444 (comment)).

Part of #19303
This PR makes
DescriptorScriptPubKeyManuse a non-recursive private mutex by moving locking responsibility into its public methods and using lock-held internal helpers for shared logic.The change removes external locking of
DescriptorScriptPubKeyMan::cs_desc_man, splits recursive internal call paths such as keypool top-up and descriptor updates, and then renames the mutex tom_desc_mutex.No wallet database format, RPC behavior, keypool semantics, or external signer behavior is intended to change.