Skip to content

fix(key-wallet-manager): register accounts made by create_account - #1596

Draft
xdustinface wants to merge 5 commits into
devfrom
fix/create-account-registers-managed-account
Draft

xdustinface wants to merge 5 commits into
devfrom
fix/create-account-registers-managed-account

Conversation

@xdustinface

Copy link
Copy Markdown
Collaborator

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 registers the account through add_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. Wallet zeroizes its key material on drop, so the copy leaves no secrets behind.

add_managed_account did not support PlatformPayment accounts, so a second commit adds them through the same platform account conversion wallet creation uses.

Closes #853

`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.
@manki-review

manki-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

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.

@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

CI does not run on this PR while it is a draft. Someone with write access can start it here:

  • Run CI once on the current commit
  • Run CI on every push, starting now

Marking the PR ready for review also starts CI.

@manki-review

manki-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Review complete in 13m 13s

Planner (6s)
    feat · 98 lines · 2 agents
    judge effort: medium

Review (security · full): 7 findings
    ✅ Claude Opus 5.5 · high: 1 finding (2m 0s)
    ✅ GPT 6.2 Sol · high: 6 findings (2m 38s)
    ✅ Related checks, claim checks and fix checks: 9 of 9 done (1m 19s)
    ✅ Second reads: 1 of 1 done (46s)

Judge (8m 48s)
    graded 7 findings: 4 kept · 2 dropped · 1 merged
    dropped, as the finders filed them: 1 blocker · 1 warning
    refuter: 1 checked · 1 confirmed
    origin checks: 2 checked
    verdict reader: read the diff (25s)

Posted: 4 findings
    2 warnings · 2 suggestions

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 61% (resets 2026-12-04 20:00 UTC)
  • ChatGPT subscription: weekly 2% (resets 2026-12-10 07:41 UTC)

Judge decisions:

  • Kept: "add_managed_account_from_xpub still rejects PlatformPayment accounts that add_managed_account now accepts" (warning): "warning. This PR adds PlatformPayment support to add_managed_account (managed_accounts.rs:78-97). The sibling public method in the same file does not get it. add_managed_account_from_xpub calls owned_from_account (managed_accounts.rs:133), and the _ arm at line 37 turns PlatformPayment into a ManagedCoreKeysAccount. insert then fails at managed_account_collection.rs:360 with a message that tells the caller to use insert_funds_bearing_account. That is an incomplete fix in a file this PR changes. The call fails loudly and stores nothing wrong, so the damage is a public operation that cannot be done, plus a misleading error, not corrupted state.", trigger 4 and harm 5 of 10: "This only shows up when a caller registers a PlatformPayment account from an xpub, which is a realistic but uncommon path."
  • Dropped: "Platform payment registration activates unknown key classes" (ignore): "ignore. The DIP-17 rule at dip-0017.md:75 tells a wallet not to reject a whole account when it meets a key_class it does not know. It does not forbid a caller from explicitly creating an account for a key_class it chose. create_account registers exactly the key_class the caller passed. It uses the same conversion that wallet creation already uses (managed_account_collection.rs:489), and Wallet::add_account has already accepted that account. Doing what the caller asked violates no rule and produces no wrong result."
  • Kept: "The added test cases use fully qualified account types" (suggestion): "note. AGENTS.md forbids fully qualified paths used to avoid an import, and allows only a single qualifier. The added line integration_test.rs:113 writes key_wallet::account::StandardAccountType::BIP44Account, which goes past a single qualifier. The key_wallet::AccountType::... uses are borderline. The code runs correctly, so this is style only."
  • Kept: "The account generation docs still promise a bump for Platform additions" (suggestion): "note. Before this PR, every successful add_managed_account reached rewind_sync_checkpoint_for_new_account, which bumps the counter at mod.rs:606. The new Platform branch returns at managed_accounts.rs:97 without that bump. So the doc at mod.rs:610 ("Bumped on every account add") is now untrue for Platform accounts. Skipping the bump is intended, because Platform addresses are not matched against core blocks. The comment sits in an unchanged file away from the change, so the 'nearby comment' rule is not clearly broken. It is still a doc that misstates the code."
  • Dropped: "The wallet clone may leave a stale copy of inline private key material" (ignore): "ignore. The move at lib.rs:687 may leave key bytes in stack memory, but no outside input can read them. Anyone who can read process memory can already read the live wallet that the manager holds. On the failure path the clone updated is dropped and zeroized. The replaced wallet is dropped and zeroized on assignment. At most this is a hardening idea with no realistic exposure."
  • Kept: "Manager account creation may register an xpub already watched under another account" (warning): "warning. This PR makes create_account register managed state through add_managed_account (lib.rs:685). That check compares account types only (managed_accounts.rs:104). The open lead says the raw wallet's xpub check covers only Wallet.accounts. If so, two managed accounts can share one xpub. The code shown does not settle whether the wallet accepts that xpub, or whether a shared address would be credited twice. Both are listed as doubts.
    Refutation confirmed: 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 repo or in dashpay/platform passes one account's xpub to create_account under another index. Also, add_managed_account_from_xpub alone, without this PR's change, can already register a second account with an existing account's xpub (integration_test.rs:115-119 does exactly that). So it is not clear this PR causes the problem or that norma... Rule checked: Each managed account matches outputs against its own address pool and records its own UTXOs, and the wallet balance is the sum of the funding accounts' balances, so two accounts built from one xpub would each record and count the same output.
  • Premise "Wallet::add_account accepts a caller-supplied account_xpub that equals the xpub of an account registered only in ManagedWalletInfo through add_managed_account_from_xpub" confirmed. Wallet::add_account checks xpub reuse only against self.accounts, the raw wallet's own accounts. It never looks at accounts that exist only in ManagedWalletInfo, and add_managed_account_from_xpub creates an Account with no wallet and inserts it only into the managed collection.
  • Premise "A payment to an address derived from an xpub shared by two managed accounts is credited to both accounts in the balance that ManagedWalletInfo reports" confirmed. check_transaction checks each indexed account separately and pushes a match for every account whose addresses match. check_core_transaction_inner then records the transaction, and its UTXOs, in each matched account.
  • Premise "The wallet balance that ManagedWalletInfo reports counts the same output twice once two managed accounts share an xpub" confirmed. update_balance adds up each funding account's balance and never removes outpoints that two accounts share, so an output recorded by both accounts is counted twice.
    Pair refutation confirmed: 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 documented manager workflow that registers the same xpub in both slots. Rule checked: Deduplicating outputs within each account does not prevent double counting when the wallet sums those accounts’ balances.
  • Premise "Wallet::add_account accepts a caller-supplied account_xpub that equals the xpub of an account registered only in ManagedWalletInfo through add_managed_account_from_xpub" confirmed. For an unused account index, the supplied xpub is stored unchanged and checked only against raw wallet accounts; the managed-only registration inserts into a separate collection.
  • Premise "A payment to an address derived from an xpub shared by two managed accounts is credited to both accounts in the balance that ManagedWalletInfo reports" confirmed. When a fresh, unspent payment matches an address watched by both BIP44 slots, the checker keeps both indexed matches and inserts the same outpoint into each account’s UTXO map.
  • Premise "The wallet balance that ManagedWalletInfo reports counts the same output twice once two managed accounts share an xpub" confirmed. Once both funding accounts hold the output, the wallet sums their balances without deduplicating outpoints and returns that sum."

Timing:

  • Parse: 7.5s
  • Review agents: 257.7s
  • Judge: 527.8s
  • Total: 793.0s

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 2 warnings to address. Fix each one, reply in its thread with a reason Manki accepts, or tick 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-5 and gpt-6.2-sol, judged by claude-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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Warning · Correctness · Moderate

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`.
@manki-review

manki-review Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

✅ Review complete in 8m 11s

Planner (5s)
    refactor · 183 lines · 2 agents
    judge effort: medium

Review (security · full): 11 findings
    ✅ Claude Opus 5.5 · high: 1 finding (1m 39s)
    ✅ GPT 6.2 Sol · high: 10 findings (3m 9s)
    ✅ Related checks, claim checks, pattern checks and fix checks: 16 of 16 done (1m 23s)
    ✅ Second reads: 1 of 1 done (40s)

Judge (3m 29s)
    graded 11 findings: 6 kept · 5 dropped
    dropped, as the finders filed them: 2 blockers · 3 warnings
    refuter: 3 checked · 1 confirmed · 2 unsettled
    origin checks: 1 checked
    verdict reader: read the diff (44s)

Posted: 2 findings
    2 suggestions
    not posted: 1 on code an earlier round reviewed
    not finished checking: 2 possible problems
    left out: 1 suggestion on test files, which Manki posts only in the first round

Review metadata

Config:

  • Models: reviewer=claude-opus-5-5, judge=claude-opus-5-5
  • Triage: trivial=false, subtle=true, paired=true (planner, security-sensitive paths)
  • Team: Claude Opus 5.5 · high, GPT 6.2 Sol · high
  • Memory: enabled (central)

Account limits:

  • Claude subscription: weekly 66% (resets 2026-12-04 20:00 UTC)
  • ChatGPT subscription: weekly 2% (resets 2026-12-10 07:41 UTC)

Judge decisions:

  • Not finished: "The sync height rewind from create_account emits no event, so a saved checkpoint stays above the new account's history" (warning): "warning. create_account now calls add_managed_account (key-wallet-manager/src/lib.rs:685), which lowers synced_height in memory through rewind_sync_checkpoint_for_new_account without emitting an event. Whether a persistence consumer then keeps a stale, higher checkpoint depends on how consumers persist sync progress, which the code shown does not settle, so the blocker test 4 is open.
    Refutation unsettled: create_account lowers synced_height in memory and sends no event, and the documented way to save the cursor is SyncHeightAdvanced. But no persister in this repo or in the consumer repos calls WalletManager::create_account, and the platform consumer handles add_managed_account rewinds itself by owing the lowered cursor to its next backfill round. Whether a restart leaves a stale higher cursor next to a saved new account depends on how a consumer saves and reloads, which no readable code shows. Rule checked: A consumer that records the scan cursor only from WalletEvents never sees a cursor lowered without an event, and SyncHeightAdvanced fires only when the height increases.
  • Premise "A persistence consumer of WalletManager restores synced_height only from WalletEvents such as SyncHeightAdvanced and ChainTruncated, and create_account at key-wallet-manager/src/lib.rs:669 emits none" confirmed. create_account reaches rewind_sync_checkpoint_for_new_account, which lowers synced_height and sends no event. The documented way to save the cursor is SyncHeightAdvanced, which fires only on an increase, and the platform consumer states that an account add's rewind never reaches its persister.
  • Premise "After a restart the restored synced_height is above the new account's history, so the filter sync never scans those heights for the new account's scripts" unsettled. A stale cursor after restart requires a consumer to save the new account but keep the old cursor, and to restart before the first backfill batch commits. No persister in this repo calls create_account, and the platform consumer owes the lowered cursor to its next backfill round, so this rests on consumer code outside reach.
    Pair refutation unsettled: The managed-account registration lowers the in-memory checkpoint without a manager event, and filter startup uses the wallet checkpoint for recovery. Platform’s event adapter can replace a pending higher watermark with a lower advance from a newer rewind epoch, but no checked caller establishes that it saves a new core account through create_account and reloads it with the old checkpoint. Rule checked: An in-memory checkpoint rewind affects restart recovery only if the lower checkpoint is saved or reconstructed on load.
  • Premise "A persistence consumer of WalletManager restores synced_height only from WalletEvents such as SyncHeightAdvanced and ChainTruncated, and create_account at key-wallet-manager/src/lib.rs:669 emits none" unsettled. create_account emits no event, but no event-only save-and-reload path for that call was established; Platform also writes checkpoint changes directly for DashPay backfill.
  • Premise "After a restart the restored synced_height is above the new account's history, so the filter sync never scans those heights for the new account's scripts" unsettled. Filter startup uses the wallet’s checkpoint, but no checked restart path loads the new account together with a checkpoint above its history."
  • Not listed, on code an earlier round reviewed: "Cloning and moving the wallet defeats the guarantee that temporary key material is erased" (suggestion): "note. wallet.clone() at key-wallet-manager/src/lib.rs:681 and the move at line 687 can leave the moved-from bytes of updated on the stack, since Drop zeroizes only the final location (key-wallet/src/wallet/mod.rs:235). The PR description's claim that the copy leaves no secrets behind is therefore not strictly true. No attacker gains access through this, and wallets are already moved by value elsewhere, for example insert_wallet. This is a hardening point, not a reachable exposure."
  • Dropped: "An account request can exhaust memory by cloning the caller's entire account collection" (ignore): "ignore. The wallet is one the caller built and inserted itself through insert_wallet (key-wallet-manager/src/accessors.rs:64). A transient second copy of its own accounts gives the caller no capability it lacked, because building the wallet already cost the same memory. A wallet's account set is also small."
  • Dropped: "A custom wallet info can fail registration after changing managed state" (ignore): "ignore. The finding rests on a hypothetical third-party add_managed_account implementation that mutates state and then returns an error. The in-repo implementation returns errors only before inserting (managed_accounts.rs:283-305). A custom implementation that breaks its own all-or-nothing behaviour is that implementation's defect, not one this PR causes."
  • Kept: "An imported core account can miss transactions older than the wallet's birth height" (suggestion): "warning. create_account now registers the account, and the rewind floors at birth_height - 1 (key-wallet/src/wallet/managed_wallet_info/mod.rs:601). An imported xpub with older history is therefore never scanned below that height. The birth height is the wallet's documented scan floor, so even when the premise holds this fails blocker test 3 as a design limit of the existing rewind rather than serious damage the change itself causes. It is held at a warning.
    Refutation confirmed: 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 caller imports an xpub with history older than the wallet's birth height is up to whoever uses the API. Every caller in this repository passes None or a type derived from the wallet itself. The PR also did not change the rewind floor: before this PR, create_account did not register the account with the info at all, so whether this coun... Rule checked: A rescan triggered by adding an account starts at the wallet's own birth_height - 1, so nothing below that height is ever matched against the new account's scripts.
  • Premise "A caller of create_account passes an account_xpub for an account with transactions below the wallet's metadata.birth_height, which Wallet::add_account accepts unchecked at key-wallet/src/wallet/accounts.rs:40" confirmed. In the code, the public create_account takes an Option<ExtendedPubKey>, and Wallet::add_account builds the account from a supplied xpub with no check of its history against metadata.birth_height. The only floor is the wallet's own birth_height - 1 at mod.rs:601. Whether someone actually imports such an xpub is user behaviour the code cannot show.
    Pair refutation unsettled: 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 the gap, but the callers and tests checked do not establish that an imported account has transactions in that range. Rule checked: A filter rescan cannot discover transactions in blocks below its starting height.
  • Premise "A caller of create_account passes an account_xpub for an account with transactions below the wallet's metadata.birth_height, which Wallet::add_account accepts unchecked at key-wallet/src/wallet/accounts.rs:40" unsettled. The supplied xpub is accepted without a transaction-height check, but the checked manager tests pass None to create_account and do not demonstrate an import with pre-birth history."
  • Dropped: "Platform registration treats unknown key classes as usable payment accounts" (ignore): "ignore. The new branch registers exactly the key class the caller explicitly asks for, which is the same thing the existing wallet conversion does (managed_account_collection.rs:487). DIP-17's rule to ignore unknown classes is about discovery. Registering an account the caller requested is not a wrong result this PR causes."
  • Dropped: "Wallet and standalone registration disagree on whether an xpub must match the wallet network" (ignore): "ignore. The missing xpub network check sits in the unchanged Wallet::add_account (key-wallet/src/wallet/accounts.rs:40). Derived addresses use account.network (managed_account_collection.rs:571), so they are encoded for the wallet's network. The finding names an inconsistency between two APIs but no wrong result."
  • Dropped: "The regression test checks the generation but not the sync rewind" (suggestion): "note. Reverting the registration in create_account or adding a rewind to the Platform branch both fail the test through the generation asserts (integration_test.rs:94, 121). The uncovered assignment at mod.rs:602 is not a line this PR changes. Asserting synced_height as well would make the test stronger."
  • Kept: "The new registration helper repeats its implementation and cites a fixed issue" (suggestion): "note. The helper is added code, and line 311 cites #649 against the AGENTS.md rule on history in code. Lines 300, 303 and 308 narrate what the code does. The comments were moved from the old functions, but the PR adds them in the new helper."
  • Dropped: "The wallet README's account examples call a method on the wrong type" (ignore): "ignore. key-wallet/README.md is not changed by this PR, and its broken examples do not depend on anything the PR changes."
  • Not finished: "Two standalone Platform registrations may watch the same addresses under different account labels" (warning): "warning. The new xpub path into the Platform branch checks only the account and class pair (managed_accounts.rs:283), not xpub reuse, unlike Wallet::add_account (accounts.rs:65-77). This is the same missing check as P2, now for Platform accounts. Whether overlapping pools produce a double-counted balance is not shown.
    Refutation unsettled: 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 consumer's sync maps each address to a single (wallet, account, index) tag in a BiBTreeMap and credits only the account it looks up by index. No code shows a credit being counted twice or a signing error, so the harm remains unproven. Rule checked: Each ManagedPlatformAccount keeps its own balance, which changes only when outside code calls set_address_credit_balance on it. Any credit counted twice has to come from a caller that writes the same address into both accounts, or from code that adds up the totals of all accounts.
  • Premise "Platform balance code credits an address derived from an xpub shared by two ManagedPlatformAccounts to both accounts" unsettled. Platform balances are written only by consumer code (key-wallet has no caller of set_address_credit_balance). The consumer's sync adds addresses only from wallet.accounts.platform_payment_accounts, keeps them in a BiBTreeMap keyed by a single (wallet, account, index) tag, and credits one account looked up by index. So an address found during sync is not written to two accounts.
  • Premise "The Platform balance that ManagedWalletInfo reports counts the same credit twice once two Platform accounts share an xpub" unsettled. ManagedWalletInfo reports no Platform balance at all. Searching key-wallet for credit_balance or address_balances outside managed_platform_account.rs finds nothing, and the helpers only return the separate per-account objects.
    Pair refutation unsettled: Standalone registration checks the account/class pair and passes the supplied xpub to the pool unchanged. The Platform sync provider builds its account list from the raw wallet, not from standalone registrations, so the overlap alone does not establish a balance or signing failure in normal use. Rule checked: An account label does not change the addresses derived from the same account xpub at the same child indices, but overlapping pools do not by themselves double-count a balance.
  • Premise "Platform balance code credits an address derived from an xpub shared by two ManagedPlatformAccounts to both accounts" unsettled. A sync callback credits only the account named by its tag, and restore applies balances already stored under each account index; neither path shows a standalone overlap generating credits for both accounts.
  • Premise "The Platform balance that ManagedWalletInfo reports counts the same credit twice once two Platform accounts share an xpub" disproved. ManagedWalletInfo reports a Core balance, not a wallet-wide sum of Platform credits; the Platform credit getter returns only the balance of its own account."

Timing:

  • Parse: 5.3s
  • Review agents: 277.1s
  • Judge: 208.6s
  • Total: 491.0s

Last reviewed 1277966 · head 1277966 · up to date

  • Pause automatic reviews
  • Review again
  • Deeper review
  • Review this draft
  • Review every push

@manki-review manki-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ 1 warning to address. Fix it, reply in its thread with a reason Manki accepts, or tick 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.

.add_account(account_type, account_xpub)
.map_err(|e| WalletError::AccountCreation(e.to_string()))?;
info.add_managed_account(&updated, account_type)
.map_err(|e| WalletError::AccountCreation(e.to_string()))?;
*wallet = updated;

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.

account_type: AccountType,
account_xpub: Option<ExtendedPubKey>,
) -> Result<(), WalletError> {
let (wallet, info) = self
.get_wallet_mut_and_info_mut(wallet_id)

Uses the supplied key directly through Account::new.

// Create the account based on whether we have an xpub or need to derive
let account = if let Some(xpub) = account_xpub {
// Use the provided extended public key
Account::new(Some(wallet_id), account_type, xpub, self.network)?
} else {

Accepts a standalone account xpub and sends it to the same insertion helper.

// Create an Account with no wallet ID (standalone managed account)
let account = Account::new(None, account_type, account_xpub, self.network)?;
self.insert_managed_account(&account)
}

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_account emits no event, so a saved checkpoint stays above the new account's history · key-wallet-manager/src/lib.rs:685
    create_account lowers synced_height in 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-5 and gpt-6.2-sol, judged by claude-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.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✨ 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.

rust-dashcore/AGENTS.md

Lines 67 to 72 in 1277966

- Default to no comment. Write one only for a *why* the code cannot show: a hidden constraint, a subtle invariant, a workaround, behavior that would surprise a reader. Never narrate *what* the code does.
- No history in code: no previous implementations, fixed bugs, issue or PR numbers, callers, or the current task. That belongs in the commit message and the PR.
- One line is normal, three is the ceiling. Before writing a block, try a clearer name or a smaller function instead. Make each point once, not on the struct, the field and the test.
- A doc comment starts with what the item does or returns ("Returns ...", "Whether ..."). The reason follows in its own sentence.
- Short sentences, one idea each, plain subject-verb-object order. Use real identifiers, not private shorthand or vague pronouns.

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…

// Wrap as the right managed-account variant for the account type.
let managed_account = owned_from_account(account)?;
// Check if managed account already exists
if self.accounts.contains_managed_account_type(managed_account.managed_account_type()) {
return Err(already_exists());
}

// 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.

  • Create an issue for this
  • Dismiss this finding

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

key-wallet-manager: WalletManager::create_account never registers the account with ManagedWalletInfo

1 participant