Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

restore: Add birthday option. #2346

Closed
JoeGruffins opened this issue Apr 17, 2024 · 4 comments · Fixed by #2347
Closed

restore: Add birthday option. #2346

JoeGruffins opened this issue Apr 17, 2024 · 4 comments · Fixed by #2347

Comments

@JoeGruffins
Copy link
Member

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 decred/decrediton#3940

@JoeGruffins
Copy link
Member Author

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

dcrwallet/wallet/rescan.go

Lines 386 to 400 in 3b70812

// RescanPoint returns the block hash at which a rescan should begin
// (inclusive), or nil when no rescan is necessary.
func (w *Wallet) RescanPoint(ctx context.Context) (*chainhash.Hash, error) {
const op errors.Op = "wallet.RescanPoint"
var rp *chainhash.Hash
err := walletdb.View(ctx, w.db, func(dbtx walletdb.ReadTx) error {
var err error
rp, err = w.rescanPoint(dbtx)
return err
})
if err != nil {
return nil, errors.E(op, err)
}
return rp, nil
}
?

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
Copy link
Member

Related: #320

@jrick
Copy link
Member

jrick commented Apr 17, 2024

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
Copy link
Member

jrick commented Apr 17, 2024

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: 25b8ae6. we have't released a version with this feature yet, so i'm not as concerned about breaking it from scripted input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants