Review report

core: PR #35444

5 suggestions

Optional improvements

Link

[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).

Details and suggested fix

Previously, IncIndex, DecIndex and SetRangeEnd compared CanGetAddresses() before and after mutation and emitted NotifyCanGetAddressesChanged themselves. They now only mutate, so notification handling is repeated in GetNewDestination, GetReservedDestination, ReturnDestination, TopUp, MarkUnusedAddresses and UpdateWalletDescriptor. Moving the notification after m_desc_mutex is released is necessary, and every current path on an existing SPKM goes through one of these blocks. However, a later public method that calls TopUp_, TopUpWithDB_, IncIndex or UpdateFrom without the block would omit the notification, with no annotation or runtime check to catch it. Consider centralizing the lock, before-and-after snapshots, notification and exception handling in one private helper, with each public method passing its body. Confirm that Clang's thread-safety analysis accepts the annotated callable.


Link

[suggestion] · Lock annotations on three definitions conflict with their declarations

The definitions use EXCLUSIVE_LOCKS_REQUIRED(!m_desc_mutex) while the declarations use LOCKS_EXCLUDED(m_desc_mutex), contrary to the developer notes.

Location: src/wallet/scriptpubkeyman.cpp:1294 (head).

Details and suggested fix

SetupDescriptorGeneration, SetupDescriptor and UpdateWithSigningProvider are declared in scriptpubkeyman.h with LOCKS_EXCLUDED(m_desc_mutex), but their definitions add EXCLUSIVE_LOCKS_REQUIRED(!m_desc_mutex). The developer notes say annotations on separately declared functions should appear only on the declaration, because annotations on the definition can hide missing diagnostics at call sites between the two. The commit message also says LOCKS_EXCLUDED is kept for these factory-only methods, so the definitions state a second contract. Remove the annotations from the definitions and keep one contract in the header. Either retain LOCKS_EXCLUDED as documented or use the negative capability annotation used by the other self-locking methods. The unconditional LOCK(m_desc_mutex) in each body already provides the runtime check.


Link

[suggestion] · Three fields lack lock annotations

m_max_cached_index, m_decryption_thoroughly_checked and m_map_signing_providers are accessed under m_desc_mutex, but Clang cannot enforce that requirement.

Location: src/wallet/scriptpubkeyman.h:284 (head).

Details and suggested fix

This PR adds LOCK(m_desc_mutex) to GetEndRange(), which reads m_max_cached_index. The rescan loop's FastWalletRescanFilter::UpdateIfNeeded calls it without cs_wallet, so before this change that read was unprotected. The field's other accesses are under the lock, as are all accesses to m_decryption_thoroughly_checked and m_map_signing_providers. Without GUARDED_BY(m_desc_mutex) on these fields, a future unlocked access could compile without a warning. Add that annotation to all three fields; the default member initializers are exempt from the analysis.


Link

[suggestion] · First-key-time notification runs while m_desc_mutex is held

A 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).

Details and suggested fix

UpdateWalletDescriptor calls NotifyFirstKeyTimeChanged inside the LOCK(m_desc_mutex) scope. A subscriber that calls back into the same SPKM, for example through GetTimeFirstKey() or GetWalletDescriptor(), worked with the old RecursiveMutex but would self-deadlock, or abort under DEBUG_LOCKORDER, with the new non-recursive Mutex. The current subscriber, CWallet::MaybeUpdateBirthTime, only updates an atomic, so this does not hang today. Copy creation_time to a local while holding the lock and emit the signal after unlocking, only when no exception was captured. This preserves the current success-only behavior and applies the same rule as NotifyCanGetAddressesChanged.


Link

[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).

Details and suggested fix

Previously, the scriptpubkeyman fuzz target updated a matching descriptor through CreateDescriptor and CWallet::AddWalletDescriptor, the path used by importdescriptors and other production callers to reach UpdateWalletDescriptor. It now calls spk_manager->UpdateWalletDescriptor directly. This still covers SPKM validation, but skips AddWalletDescriptor's existing-SPKM lookup and error propagation, as well as the label/address-book, WriteDescriptor() and MarkDirty() work on updated state. The initial CreateDescriptor call still reaches that follow-up code, so the coverage loss is limited to the update path. Use the public HasWalletDescriptor to check whether the descriptor exists, then call CreateDescriptor(...) and assign the returned manager when non-null. This restores coverage of the wallet update path, including its range validation and error return.


Coverage details