wallet: publish descriptor top-ups after commit#144
Conversation
93e14a5 to
2baaa57
Compare
PR ReviewFindings
Consensus Impact
No consensus validation, on-chain serialization, or signature algorithm changes are present. However, Review ScopeReviewed issue #139 as the contract, both commits, all ten changed files, the complete diff against Deep Checks PerformedTraced standalone and caller-owned top-ups through commit, abort, scope-exit, multi-top-up reverse rollback, and object destruction. Checked restoration of descriptor ranges/cache, ECDSA and PQC key maps, signature counters, and deferred P2MR state. I also traced wallet-to-descriptor lock ordering and attempted to disprove the fallback concern through current callers; setup paths commonly retain Issue FitThe patch correctly guards The two findings leave callback lifetime and “ownership only after persistence” incomplete. The qbit-Specific ChecksReviewed P2MR private-key persistence for plaintext and encrypted wallets, PQC signature-counter rollback, deferred keypool flags, cache/range restoration, provider fallback, and wallet/descriptor/database lock order. AuxPoW, ASERT, validation, P2P/PHOTON, release signing, and on-disk schema are unchanged. Validation ReviewedThe PR reports release/debug builds, focused wallet and P2MR suites, Docker lint, and
Residual RiskI did not perform a fresh local build. The concurrent-reader test has no scheduling barrier, so it does not deterministically prove the commit-to-publication handoff or the pre-commit invisibility invariant. No performance evidence covers the new all-manager scan on ordinary cache misses. |
Summary
Fixes #139.
Descriptor top-up now stages newly derived scripts and publishes wallet ownership/cache updates only after the backing database transaction commits. Standalone top-ups retain the descriptor lock through commit, then release descriptor/database state before acquiring the wallet lock for publication. Top-ups running inside caller-owned transactions register commit and abort listeners so successful transactions publish once while aborts restore descriptor, keypool, cache, and PQC state.
CWallet::m_cached_spksis now explicitly guarded bycs_wallet, and cache misses fall back to querying script managers during the narrow commit-to-publication handoff. Transaction listeners also abort on commit failure or scope exit and unwind in reverse order.The mock wallet database now models active transactions and rollback, enabling regression coverage for commit failure, external transaction publication order, multi-top-up abort ordering, and concurrent cache readers.
Testing
Commands and configurations:
cmake --build build --target test_bitcoin -j4cmake --build build-debug --target test_bitcoin -j4build/bin/test_qbit --run_test='wallet_tests,walletdb_tests,wallet_p2mr_change_keypool_tests,wallet_p2mr_deferred_keypool_tests,wallet_p2mr_descriptor_tests' --log_level=messagebuild-debug/bin/test_qbit --run_test='wallet_tests/DescriptorTopUp*' --log_level=messagebuild-debug/bin/test_qbit --run_test='wallet_p2mr_change_keypool_tests,wallet_p2mr_deferred_keypool_tests' --log_level=messageci/lint_imagefile: all checks passed.git diff --checkTarget Branch
mainor a maintainer-requested release branch such as0.1.x.Target:
1.x.x.Risk / Review Notes
Notes:
cs_walletduring derivation and persistence.Docs / Process Impact
Choose exactly one:
libbitcoinpqc Subtree Checklist (if
src/libbitcoinpqcchanged)Not applicable;
src/libbitcoinpqcis unchanged.Qbit-Org/qbit-libbitcoinpqc.contrib/devtools/update-libbitcoinpqc-subtree.sh.test/lint/libbitcoinpqc-subtree-check.shpasses locally.contrib/devtools/update-libbitcoinpqc-subtree.shis intentional and matchesdoc/subtrees/libbitcoinpqc.md.Need help on this PR? Tag
/codesmithwith what you need. Autofix is disabled.Note
Medium Risk
Changes wallet lock ordering, in-memory vs durable publication, and transaction listener lifetimes; incorrect rollback or cache-miss fallback could miss or mis-attribute outputs, though consensus and on-disk schema are unchanged.
Overview
Descriptor keypool top-ups now stage new scripts and wallet-visible updates until the backing DB transaction succeeds, instead of updating
TopUpCallbackand notifications while writes may still roll back.TopUpChangecaptures new scriptPubKeys plus a rollback closure; standalone top-ups commit undercs_desc_man, then callPublishTopUpoutside that lock. Top-ups inside a caller-ownedWalletBatchregister commit/abort listeners so publication runs once on commit and descriptor/keypool/PQC state is restored on abort (including after commit failure).m_cached_spksis explicitlyGUARDED_BY(cs_wallet);TopUpCallbackand cache helpers takecs_wallet.IsMine,GetScriptPubKeyMans, andGetSolvingProviderfall back to script managers on cache miss during the narrow post-commit handoff.SetCachenarrows the descriptor lock scope before publishing.WalletBatchdestructor aborts active transactions; commit failure attempts abort; abort listeners run in reverse order. Migration/descriptor import paths abort when commit fails.Mockable wallet DB implements real txn snapshots for tests; new wallet tests cover commit failure rollback, deferred publication in external txns, and concurrent cache readers. Functional test pins mock time for stable
getblockchaininfoCLI comparison.Reviewed by Cursor Bugbot for commit 07b614e. Bugbot is set up for automated code reviews on this repo. Configure here.