Repository navigation
fix(key-wallet-manager): register accounts made by create_account - #1596
xdustinface wants to merge 5 commits into
Conversation
`WalletManager::create_account` added the account to the `Wallet` but never registered it with the wallet's `ManagedWalletInfo`. The new account had no managed state, so its addresses were never watched and its history was never scanned, without any error. `create_account` now also calls `add_managed_account` on the wallet's info, which rewinds the sync checkpoint and bumps the account generation so the new account's history gets scanned. `Wallet` has no way to remove an account, so the account is first added to a copy of the wallet and the copy replaces the wallet only once the info has registered it. A failed registration leaves both unchanged. A wallet without its info is reported as `WalletNotFound` before anything is changed. Fixes #853
`add_managed_account` wrapped every account type as a core account, and the managed collection refuses to store a `PlatformPayment` account that way. So `WalletManager::create_account` could not create a Platform payment account at all. `add_managed_account` now builds a `PlatformPayment` account with the collection's existing platform conversion and stores it with `insert_platform_account`, as wallet creation does. It refuses an account the info already holds. It does not rewind the sync checkpoint for it, because platform payment addresses are never matched against core blocks.
|
This pull request is a draft, so Manki does not review it automatically. Marking it ready for review starts automatic reviews. Until then, someone with write access to this repository can tick a box below: Review this draft reviews the current commit once, Deeper review does so with more effort, and Review every push reviews it now and again after each push. |
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
CI does not run on this PR while it is a draft. Someone with write access can start it here:
Marking the PR ready for review also starts CI. |
|
✅ Review complete in 13m 13s Planner (6s) Review (security · full): 7 findings Judge (8m 48s) Posted: 4 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
|
There was a problem hiding this comment.
Create an issue for this to track it for later. The PR is also a draft, so mark it ready for review too. If no approval follows, comment /manki check.
About this review
- Reviewed
2169844, round 1 - 98 changed lines read in 13m 13s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 3.5M in (2.9M from cache) · 67k out · about $4.00 at API prices
- Runner: self-hosted · started after 5m 13s · peak memory 3.4 GiB of 30.0 GiB
- How Manki reviews
| .add_account(account_type, account_xpub) | ||
| .map_err(|e| WalletError::AccountCreation(e.to_string()))?; | ||
|
|
||
| info.add_managed_account(&updated, account_type) |
There was a problem hiding this comment.
Manager account creation may register an xpub already watched under another account
Manki could not confirm this, so please check it.
What goes wrong: A caller can register a managed-only Core account from an xpub and then pass the same xpub to create_account under a different index. The raw-wallet check cannot see the first account and the managed check compares account types rather than xpubs.
How this was checked: 1 place read, not confirmed
Not settled
Manki tried to disprove this by reading the code and could not decide. The code would credit one output to both accounts if two managed accounts shared an xpub. The finding names no realistic trigger, though: no caller in this rep… See key-wallet/src/wallet/accounts.rs lines 65 and 67, key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs lines 130 and 144, key-wallet/src/transaction_checking/account_checker.rs lines 461, 467, and 482, key-wallet/src/transaction_checking/wallet_checker.rs lines 544 and 552, and key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs lines 513, 515, and 517.
Second check, on another model
Not settled. The raw-wallet check cannot see a managed-only registration, and a payment that matches both managed slots is credited twice. I did not verify a caller or docu… See key-wallet/src/account/mod.rs:107, key-wallet/src/wallet/accounts.rs lines 38, 58, and 66, key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs lines 130 and 144, key-wallet/src/transaction_checking/account_checker.rs lines 481 and 578, key-wallet/src/transaction_checking/wallet_checker.rs lines 544 and 552, key-wallet/src/managed_account/managed_core_funds_account.rs lines 477, 500, and 371, and key-wallet/src/wallet/managed_wallet_info/wallet_info_interface.rs lines 501, 513, 515, and 517.
- Create an issue for this
…ement` The account creation lines added for `create_account` named `AccountType` and `StandardAccountType` by their full paths. Import them once at the top of the test file instead.
…rom_xpub` `add_managed_account` stored a `PlatformPayment` account in the platform collection, but `add_managed_account_from_xpub` still wrapped it as a core account and refused it. Both methods now hand the account to one private `insert_managed_account`, which holds the platform branch, the duplicate check and the checkpoint rewind for core accounts.
The `account_generation` docs said every account addition bumps it. A `PlatformPayment` account does not, because its addresses are not part of the core block scan. Say so on the field, on `ManagedWalletInfo::account_generation`, on `WalletInfoInterface::account_generation` and on `WalletInterface::wallet_account_generation`.
|
✅ Review complete in 8m 11s Planner (5s) Review (security · full): 11 findings Judge (3m 29s) Posted: 2 findings Review metadataConfig:
Account limits:
Judge decisions:
Timing:
Last reviewed
|
There was a problem hiding this comment.
Create an issue for this to track it for later. The PR is also a draft, so mark it ready for review too. If no approval follows, comment /manki check.
Still open from earlier reviews:
key-wallet-manager/src/lib.rs:685: Manager account creation may register an xpub already watched under another account (view thread)
1 suggestion · not blocking
✨ An imported core account can miss transactions older than the wallet's birth height
Suggestion, not blocking · Correctness · Larger change · key-wallet-manager/src/lib.rs:685
Why: create_account accepts an existing account xpub, but registration rewinds only to the containing wallet's birth height. Adding a previously used account to a newer wallet can leave its older deposits and unspent outputs undiscovered, even after sync catches up. The direct managed xpub API has the same limitation for core accounts.
rust-dashcore/key-wallet-manager/src/lib.rs
Lines 683 to 687 in 1277966
How to fix it
Make core-account registration track a scan floor for the new account rather than assuming the wallet's birth height covers it. Let callers supply a known lower bound for imported accounts and use the earliest scannable height when the account's history is unknown.
Checked in the code
Accepts an Option<ExtendedPubKey> and passes it to account creation at line 683.
rust-dashcore/key-wallet-manager/src/lib.rs
Lines 672 to 676 in 1277966
Uses the supplied key directly through Account::new.
rust-dashcore/key-wallet/src/wallet/accounts.rs
Lines 37 to 41 in 1277966
Accepts a standalone account xpub and sends it to the same insertion helper.
key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs:312: Callsrewind_sync_checkpoint_for_new_account()without an account-specific height.key-wallet/src/wallet/managed_wallet_info/mod.rs:591: Says the sync backfill starts at wallet birth, and line 601 implementsself.metadata.birth_height.saturating_sub(1).key-wallet-manager/src/lib.rs:683:.add_account(account_type, account_xpub)key-wallet/src/wallet/managed_wallet_info/mod.rs:601:let floor = self.metadata.birth_height.saturating_sub(1);
Double-checked
Manki tried to disprove this by reading the code and could not. The rewind does stop at birth_height - 1 (mod.rs:601-602), and add_account takes any xpub you pass without checking it (accounts.rs:38-40). Whether a real… See key-wallet/src/wallet/accounts.rs lines 38 and 40.
Second check, on another model
Not settled. Both core-account import paths use the wallet's existing birth height for backfill, so a single-wallet rescan skips blocks below that height. The code shows th…
- Create an issue for this
Checked and left out: 2 findings
Not finished checking · 2 possible problems
- The sync height rewind from
create_accountemits no event, so a saved checkpoint stays above the new account's history ·key-wallet-manager/src/lib.rs:685
create_accountlowerssynced_heightin memory and sends no event, and the documented way to save the cursor is SyncHeightAdvanced. - Two standalone Platform registrations may watch the same addresses under different account labels ·
key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs:283
Two Platform accounts can be registered with the same xpub, so their address pools overlap. But nothing in key-wallet adds up Platform balances.
The progress comment has the full log under "Judge decisions", in its "Review metadata" fold.
About this review
- Reviewed
1277966, round 2 - 183 changed lines read in 8m 11s
- Found by
claude-opus-5-5andgpt-6.2-sol, judged byclaude-opus-5-5 - Tokens: 5.8M in (4.8M from cache) · 88k out · about $6.58 at API prices
- Runner: self-hosted · started after 9s · peak memory 4.5 GiB of 30.0 GiB
- How Manki reviews
| // Insert into the collection | ||
| self.accounts.insert(managed_account)?; | ||
| // A newly added account has no filter coverage, so the sync certificate | ||
| // must be invalidated or pruning could reopen #649 for its coins. |
There was a problem hiding this comment.
✨ Suggestion, not blocking · Style · Quick fix
The new registration helper repeats its implementation and cites a fixed issue
Why: The helper carries the old issue number into the new code. Its other inline comments repeat the conversion, duplicate check, and insertion already visible in the code.
How to fix it and 6 places read · breaks a repository rule
How to fix it
Keep the explanation that a new core account invalidates filter coverage. Remove the issue number and the comments that only restate the following operation.
Repository rule
This PR breaks a required rule of AGENTS.md: No history in code: no previous implementations, fixed bugs, issue or PR numbers, callers, or the current task.
Checked in the code
On the commented line: Says must be invalidated or pruning could reopen #649 for its coins.
- Says
Never narrate *what* the code does. - Says
No history in code: no previous implementations, fixed bugs, issue or PR numbers, callers, or the current task.
Lines 67 to 72 in 1277966
key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs:303, and key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs:308 narrate the conversion…
rust-dashcore/key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs
Lines 299 to 306 in 1277966
rust-dashcore/key-wallet/src/wallet/managed_wallet_info/managed_accounts.rs
Lines 307 to 311 in 1277966
- Create an issue for this
- Dismiss this finding
WalletManager::create_accountadded the account to theWalletbut never registered it with the wallet'sManagedWalletInfo. The new account had no managed state, so its addresses were never watched and its history was never scanned, without any error.create_accountnow also registers the account throughadd_managed_account, which rewinds the sync checkpoint for a core account so its history gets scanned. The change is all or nothing: the account is added to a copy of the wallet, and the copy replaces the wallet only once the info has registered it, so a failed registration leaves the wallet unchanged.Walletzeroizes its key material on drop, so the copy leaves no secrets behind.add_managed_accountdid not supportPlatformPaymentaccounts, so a second commit adds them through the same platform account conversion wallet creation uses.Closes #853