bitcoindevkit / bdk

A modern, lightweight, descriptor-based wallet library written in Rust!
Other
844 stars 306 forks source link

Update `bdk_electrum` to use electrum's merkle proof API #980

Closed evanlinjin closed 2 months ago

evanlinjin commented 1 year ago

Describe the enhancement

As mentioned by @LLFourn in https://github.com/bitcoindevkit/bdk/pull/976#discussion_r1193920143:

... I think electrum really intends for you to use the merkle proof API. Best solution is to do that and attach confirmation time of each block to LocalChain.

Additional context

LagginTimes commented 3 months ago

After discussion with @evanlinjin, it has been decided that I will attempt to pick this up.

evanlinjin commented 3 months ago

We've started a rough document here of the plan: https://hackmd.io/@bdk/electrum_spv

tnull commented 3 months ago

FYI, since I needed it for LDK's electrum integration, I added a utility to validate merkle proofs to rust-electrum-client a while back: https://github.com/bitcoindevkit/rust-electrum-client/pull/122

Just mentioning it as they could potentially be useful.

LLFourn commented 3 months ago

Just chiming in that I think this should be a priority. It will need very careful engineering to make efficient. I think perhaps we should have CheckPoint in the BdkElectrumClient to keep track of re-orgs. This would allow us to cache merkle proofs and block headers (because we know they haven't changed). Despite this I predict the code would actually get simpler. No more weird loop and restarting in case of re-orgs.

To start off with we don't need to actually return the proofs. They can just be used to make our algorithm actually sound and robust.

notmandatory commented 3 months ago

Since this doesn't touch the wallet APIs I moved it to the beta milestone.

LLFourn commented 3 months ago

@notmandatory my suggestions on #1489 means it would touch the wallet API. Please take a look.

notmandatory commented 3 months ago

Moving this and #1489 back to the 1.0.0-alpha milestone.