bdk icon indicating copy to clipboard operation
bdk copied to clipboard

Add birthday to the wallet database

Open kcalvinalvin opened this issue 1 year ago • 7 comments

Describe the enhancement
Add a method wallet_birthday or birthday that returns the unix time of when the wallet was created.

Use case
If we know the birthday of a wallet, we can avoid scanning blocks that happened before the wallet was created. If there's no birthday, we must scan the entire chain to be sure that we don't miss txs.

kcalvinalvin avatar Feb 02 '24 06:02 kcalvinalvin

For this purpose, wouldn't it make sense to use the last-seen tip height rather than a UNIX timestamp?

tnull avatar Feb 02 '24 08:02 tnull

For this purpose, wouldn't it make sense to use the last-seen tip height rather than a UNIX timestamp?

Height + Hash would be better. I'm not too familiar with the bdk internals so I suggested unix time since you can immediately calculate that and store it on start. For blocks, you'd have to wait until you receive a block from the block source so I thought unix time would be a lot simpler codewise but if height + hash is not hard, that'd be preferred.

kcalvinalvin avatar Feb 02 '24 08:02 kcalvinalvin

Height + Hash would be better. I'm not too familiar with the bdk internals so I suggested unix time since you can immediately calculate that and store it on start. For blocks, you'd have to wait until you receive a block from the block source so I thought unix time would be a lot simpler codewise but if height + hash is not hard, that'd be preferred.

Yeah, fair enough. Although I want to note that UNIX time isn't necessarily easily accessibly either, e.g., in no_std or WASM environments. You can't just assume that SystemTime::now() is always available unfortunately.

tnull avatar Feb 02 '24 09:02 tnull

Height + Hash would be better. I'm not too familiar with the bdk internals so I suggested unix time since you can immediately calculate that and store it on start. For blocks, you'd have to wait until you receive a block from the block source so I thought unix time would be a lot simpler codewise but if height + hash is not hard, that'd be preferred.

Yeah, fair enough. Although I want to note that UNIX time isn't necessarily easily accessibly either, e.g., in no_std or WASM environments. You can't just assume that SystemTime::now() is always available unfortunately.

Oh huh. TIL

kcalvinalvin avatar Feb 02 '24 10:02 kcalvinalvin

I think this would make sense in KeychainTxOutIndex. Needs #1101. After that you can store a height/hash in there when the descriptor is created.

LLFourn avatar Feb 04 '24 22:02 LLFourn

I think this is a good to have. However, it is not critical for 1.0.0. I'll push it back.

However, if someone is super motivated to do this, I won't stop them. This should be pretty straightforward to implement/review.

evanlinjin avatar Feb 05 '24 10:02 evanlinjin

Just wonder. Are the wallets with different birthdays in the same network equal?

It is good to check the Genesis hash and the overlapped lifetime of the index and let these wallets equal(assume they sync to the same tip and network). But is there any concern about the equality of wallets with different birthdays?

yanganto avatar Feb 05 '24 17:02 yanganto