Skip to content

key-wallet: InstantSend backfill skips marking addresses used #1347

Closed

Description

@xdustinface

Problem

The InstantSend branch of check_core_transaction (key-wallet/src/transaction_checking/wallet_checker.rs, the if !is_new { if context.is_instant_send() { ... } } block, around line 325 to 365 on dev) backfills a record with record_transaction_with_observed_spends for an account that matches the transaction but holds no record yet. It then runs attribute_late_inputs and returns. It never marks the addresses the transaction pays as used, and never runs maintain_gap_limit for that account. Every other recording path does both after recording.

When it happens

An account can match only at the InstantSend lock when its address pool grew between the mempool sighting and the lock. Example: the transaction pays a visible BIP32 address and BIP44 receive index 2*gap. Only BIP32 records it from the mempool. Two later payments, to BIP44 index 1 and then index gap, extend the BIP44 window over index 2*gap. When the InstantSend lock arrives, BIP44 backfills a record and credits the coin.

Consequence

The far address stays is_used() == false, and the window does not extend past it. Until the transaction's block arrives (the confirm path runs the marking), the wallet can hand that address out as unused, and it misses payments to the addresses the extension would have derived. The block delivery heals it, so this is a window of wrong state, not permanent loss.

A throwaway test reproduced it: after the backfill, is_used() on the far address is false and index 2*gap+1 is not derived. The same transaction delivered as new gives is_used() == true.

Fix

Call the same marking and gap extension the other paths use before the branch returns, right before self.attribute_late_inputs(tx, &mut result). With the helper use_involved_addresses that #1326 extracts, that is self.use_involved_addresses(wallet, &result.affected_accounts, &mut result.new_addresses);. In the throwaway test that one line made the test pass, and the full key-wallet --lib suite passed (785 tests, default features). Add the reproduction above as a regression test.

Activity

  1. added 2 commits that reference this issue on Nov 19, 2026
    212a014
    3a869e4
  2. added 3 commits that reference this issue on Nov 23, 2026
    04cbe4d
    80d5a36
    2145ec5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions