mirror of
https://github.com/bitcoin/bitcoin
synced 2026-12-04 11:53:39 +00:00
wallet: make descriptor SPKM mutex non-recursive #35444
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!35444
Loading…
Reference in a new issue
No description provided.
Delete branch "wallet-descriptor-spkm-mutex-19303-simple-index"
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?
Part of https://github.com/bitcoin/bitcoin/issues/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.
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:
WalletBatchwrite failures by achow101)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:
src/wallet/scriptpubkeyman.cpp:WalletLogPrintf("%s: Detected a used keypool item at index %d, ...", __func__, index)→ Remove__func__; function identification is redundant with-logsourcelocations.src/wallet/scriptpubkeyman.cpp:WalletLogPrintf("%s: Topping up keypool failed (locked wallet)", __func__)→ Remove__func__; function identification is redundant with-logsourcelocations.2026-10-30 00:40:51
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 thecs_desc_manlock removal inaddhdkey().I think removing the external lock here is fine now that
GetWalletDescriptor()andGetDescriptorString()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.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.Nice cleanup: this avoids updating index after a failed destination request.
Concept ACK.
Yes, I also think it is safe because
listdescriptorsholdswallet->cs_walletacross both calls. Any update that could change either the descriptor metadata or descriptor string also needscs_wallet, so it cannot run between those two reads.Done. Thanks.
Rebased.
🐙 This pull request conflicts with the target branch and needs rebase.
Ping for rebase @w0xlt
Rebased.
🐙 This pull request conflicts with the target branch and needs rebase.
🔵 Suggestion · Notification handling is duplicated across six public methods
Every current path notifies correctly, but a future mutator that omits the copied notification block could leave GUI or wallet address-availability state stale.
Location:
src/wallet/scriptpubkeyman.cpp:896(head).🔵 Suggestion · Lock annotations on three definitions conflict with their declarations
The definitions use
EXCLUSIVE_LOCKS_REQUIRED(!m_desc_mutex)while the declarations useLOCKS_EXCLUDED(m_desc_mutex), contrary to the developer notes.Location:
src/wallet/scriptpubkeyman.cpp:1294(head).🔵 Suggestion · Three fields lack lock annotations
m_max_cached_index,m_decryption_thoroughly_checkedandm_map_signing_providersare accessed underm_desc_mutex, but Clang cannot enforce that requirement.Location:
src/wallet/scriptpubkeyman.h:284(head).🔵 Suggestion · First-key-time notification runs while
m_desc_mutexis heldA future subscriber that re-enters the SPKM could self-deadlock with the new non-recursive mutex, although the current subscriber does not re-enter.
Location:
src/wallet/scriptpubkeyman.cpp:1753(head).🔵 Suggestion · The fuzz harness bypasses the wallet-level descriptor update path
The harness now calls the SPKM directly, so it no longer fuzzes the wallet's existing-descriptor update branch or its update-state follow-up work.
Location:
src/wallet/test/fuzz/scriptpubkeyman.cpp:119(head).Review coverage was incomplete.
Reviewed:
2cde6f953476· Full review report · Previous reportsconcept ACK
3d5e0777acin
dadc205c80wallet: stop locking descriptor SPKM externallyAfter removing this line, no one uses
TopUpWithDBanymore. Maybe could also remove the protected wrapper?in
2f2cc56578wallet: split descriptor SPKM locked internalsAfter removing this,
CanUpdateToWalletDescriptoris only used by a fuzz test, but not real code. Consider removing the function entirely.in
2f2cc56578wallet: split descriptor SPKM locked internalsThe 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.
Done. Thanks.
Done. Thanks.
Done. Thanks.
🚧 At least one of the CI tasks failed.
Task
OpenBSD Cross: https://github.com/bitcoin/bitcoin/actions/runs/37521939038/job/112469290765LLM reason (✨ experimental): CI failed during compilation:
scriptpubkeyman.cppreferences the undeclared identifiercs_desc_man.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.
in
04b7fc10b4wallet: make descriptor SPKM mutex non-recursiveCorrect me if I am wrong, but
SetupDescriptorGeneration,SetupDescriptorandUpdateWithSigningProviderrun before the new constructed SPKM is returned so they don't have any signal subscribers yet. This makes callingNotifyCanGetAddressesChangeduseless.Because of that all the change detection logic calling
CanGetAddresses_()is also unecessary.Done. Thanks.
🐙 This pull request conflicts with the target branch and needs rebase.
Rebased
ACK
b38237fa22Thanks for taking the suggestions.
Verified @polespinasa's feedback is properly addressed and code rebased.
Left a non-blocking comment.
One thing, non-blocking: in
b3f25031e5("wallet: make descriptor SPKM mutex non-recursive"), indesc_spkm_availability_notifications, the sub-test exercisingUpdateWalletDescriptor()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?🐙 This pull request conflicts with the target branch and needs rebase.
Good catch, thanks. It was dropped unintentionally while addressing https://github.com/bitcoin/bitcoin/pull/35444#discussion_r4205649576.
re-ACK
2cde6f9534Since 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 indesc_spkm_availability_notifications(thanks for addressing https://github.com/bitcoin/bitcoin/pull/35444#discussion_r4225874270).