Skip to content

Conversation

achow101
Copy link
Member

@achow101 achow101 commented Aug 25, 2020

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.

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.
When salvaging a wallet, avoid deserializing any records that we don't
care about, i.e. filter for keys only before the deserialization.
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 0bbe26a. 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

@laanwj
Copy link
Member

laanwj commented Aug 29, 2020

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?

@achow101
Copy link
Member Author

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.

@laanwj
Copy link
Member

laanwj commented Sep 1, 2020

@achow101 Thanks! Clear to me now.

Copy link
Member

@laanwj laanwj left a comment

Choose a reason for hiding this comment

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

Code review ACK 0bbe26a

@fanquake fanquake merged commit 68f0ab2 into bitcoin:master Sep 3, 2020
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Sep 3, 2020
…salvaging

0bbe26a wallet: filter for keys only before record deser in salvage (Andrew Chow)
544e12a walletdb: Add KeyFilterFn to ReadKeyValue (Andrew Chow)

Pull request description:

  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.

ACKs for top commit:
  ryanofsky:
    Code review ACK 0bbe26a. 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 bitcoin#19078, so I think we're covered
  laanwj:
    Code review ACK 0bbe26a

Tree-SHA512: 8e3ee283a22a79273915711c4fb751f3c9b02ce94e6bf08dc468f1cfdf9fac35c693bbfd2435ce43c3a06c601b9b0a67e209621f6814bedfe3bc7a7ccc37bb01
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 22, 2021
Summary:
PR description:
> 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.

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

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

This is a backport of [[bitcoin/bitcoin#19805 | core#19805]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10176
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants