decred / dcrwallet

A secure Decred wallet daemon written in Go (golang).
https://decred.org
ISC License
211 stars 153 forks source link

restore: Add birthday option. #2346

Closed JoeGruffins closed 1 month ago

JoeGruffins commented 2 months ago

When a new wallet is created, initial sync will look for relevant transactions starting from the genesis block. For new wallets this is not necessary at all, and for restored wallets, if the user knew when the wallet was made, or that info was stored in their mnemonic, they only need to search for transactions from the day when the wallet was created.

There are four apps at least that could also benefit from a birthday. Cryptopower, Cake, and dex use an internal dcrwallet, dex can also use the rpc wallet, and decrediton uses the wallet over grpc. All wold benefit from setting an birthday before initial sync, or disabling initial sync and letting them rescan from height later.

Related discussion https://github.com/decred/decrediton/issues/3940

JoeGruffins commented 2 months ago

I can work on this if that's alright. @jrick do you have a strong preference on where/how to set this? Setting a date would be best I think, I think we can look at block headers to get to closely before the date and set that as the restore from value https://github.com/decred/dcrwallet/blob/3b708125c307ef795615703648df3c2a08386649/wallet/rescan.go#L386-L400 ?

Do we want to also save the birthday as a new value? I guess you could use it whenever the user did a rescan without specifying height as the default? Or would this not be great if the user imported a new script or something? You can set rescan height there too though already.

matheusd commented 2 months ago

Related: #320

jrick commented 2 months ago

I would save the birthday date to a new field in the db. It shouldn't take long to bisect the block headers to find a close enough starting height.

The rescan point is related but not the same, it is the last block that we have marked transactions synced through, so when we perform a rescan on future startups, we are only scanning blocks not considered before. We can't confuse that with the birthday, which is where the initial rescan point needs to be calculated from.

The rescan rpcs, which today all begin at the genesis block if a height is not provided, should resolve a starting height based on the birthday (when a height is not provided).

jrick commented 2 months ago

If you are going to add a new prompt to the wallet creation setup, i would insert it before this xpub import i recently added so it is asked immediately after the restored seed prompt: https://github.com/decred/dcrwallet/commit/25b8ae6366f4364e07a062107367598f61913c95. we have't released a version with this feature yet, so i'm not as concerned about breaking it from scripted input.