wallet: Avoid deserializing unused records when salvaging #19805

pull achow101 wants to merge 2 commits into bitcoin:master from achow101:avoid-salvage-deser changing 3 files +18 −6
  1. achow101 commented at 5:28 pm on August 25, 2020: member

    When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

    This PR adds a KeyFilterFn function callback to ReadKeyValue that salvage uses to filter for only the records that it wants. Of course doing it this way also lets us do other filters in the future from other places should we so desire.

  2. walletdb: Add KeyFilterFn to ReadKeyValue
    Add a KeyFilterFn callback to ReadKeyValue which allows the caller to
    specify which types to actually deserialize. A KeyFilterFn takes the
    type as the parameter and returns a bool indicating whether
    deserialization should continue.
    544e12a4e8
  3. wallet: filter for keys only before record deser in salvage
    When salvaging a wallet, avoid deserializing any records that we don't
    care about, i.e. filter for keys only before the deserialization.
    0bbe26a1af
  4. ryanofsky approved
  5. ryanofsky commented at 6:11 pm on August 25, 2020: member
    Code review ACK 0bbe26a1af2aab2287b18048f80b3f70e63e0044. Looks great! This should make the recovery code more robust. Normally it’d be good to have a test case for the problem this fixes, but Marco already wrote one in #19078, so I think we’re covered
  6. DrahtBot added the label Wallet on Aug 25, 2020
  7. laanwj commented at 3:05 pm on August 29, 2020: member

    When salvaging a wallet, the only things that matter are the private keys. It is not necessary to attempt to deserialize any other records, especially if those records are corrupted too.

    What about scripts, can’t they be critical as well to spend utxos?

  8. achow101 commented at 6:17 pm on August 29, 2020: member

    What about scripts, can’t they be critical as well to spend utxos?

    There are basically two types of scripts that we store: 1) watchonly imports, and 2) the segwit scripts for our keys. For watchonly imports, I don’t really think that these are necessary to keep as presumably there is some place else that has those scripts. For segwit scripts for our keys, those are automatically added to the wallet’s in-memory mapScripts on loading so we don’t need to keep them. IIRC the only reason those scripts were written to disk after keys were removed from the keypool was to allow for downgrading to a non-segwit version.

  9. laanwj commented at 10:26 am on September 1, 2020: member
    @achow101 Thanks! Clear to me now.
  10. laanwj approved
  11. laanwj commented at 10:27 am on September 1, 2020: member
    Code review ACK 0bbe26a1af2aab2287b18048f80b3f70e63e0044
  12. fanquake merged this on Sep 3, 2020
  13. fanquake closed this on Sep 3, 2020

  14. sidhujag referenced this in commit 709fc98a8f on Sep 3, 2020
  15. Fabcien referenced this in commit f9d3967c19 on Sep 22, 2021
  16. DrahtBot locked this on Feb 15, 2022

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-07-03 10:13 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me