You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
key-wallet: InstantSend backfill skips marking addresses used #1347
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
fix(key-wallet): mark addresses used on an InstantSend backfill
fix(key-wallet): mark addresses used on an InstantSend backfill
fix(key-wallet): mark addresses used on an InstantSend backfill (#1447)
fix(key-wallet): mark addresses used on an InstantSend backfill (#1447)
fix(key-wallet): mark addresses used on an InstantSend backfill (#1447)