feat(electrum)!: Update bdk_electrum to use merkle proofs#1489
feat(electrum)!: Update bdk_electrum to use merkle proofs#1489notmandatory merged 3 commits intobitcoindevkit:masterfrom
bdk_electrum to use merkle proofs#1489Conversation
303cd56 to
1e4ec2f
Compare
|
Since this doesn't touch the wallet APIs I moved it to the beta milestone. |
I'm okay with this! |
LLFourn
left a comment
There was a problem hiding this comment.
Thanks this simplifies a lot. Left a few comments around the anchors/merkle proof bit.
| .transaction_get_merkle(&txid, confirmation_height as usize) | ||
| { | ||
| let header = self.inner.block_header(merkle_res.block_height)?; | ||
| let is_confirmed_tx = electrum_client::utils::validate_merkle_proof( |
There was a problem hiding this comment.
Is it possible to use rust bitcoin's merkle proof validator for this? Why does electrum have its own validation logic?
There was a problem hiding this comment.
The validation logic being used right now was implemented as a utility in rust-electrum-client, which was needed for LDK's electrum integration:
bitcoindevkit/rust-electrum-client#122
Would using rust bitcoin be more advantageous in this scenario?
There was a problem hiding this comment.
I have no idea. I am just curious why @tnull added that when there is presumably this algorithm is implemented in rust-bitcoin.
There was a problem hiding this comment.
IIRC, Electrum's get_merkle/GetMerkleRes doesn't provide sufficient/slightly different data, so that we couldn't construct bitcoin::MerkleBlock/ PartialMerkleTree to use upstream's validation logic (which of course would have been our preferred way).
|
@LagginTimes oops, I didn't read all the comments before, looks like the wallet API will need to be updated so I've moved this back to the alpha milestone. |
180ee9f to
feba152
Compare
ValuedMammal
left a comment
There was a problem hiding this comment.
I did a first pass, mostly documentation nits. Sorry I was reviewing while you were pushing, so comments might be outdated
eb71012 to
756b8b1
Compare
|
@LagginTimes hey sorry I just merged some smaller PRs and now this one needs a rebase. |
44df255 to
ac3a388
Compare
Both `bdk_electrum` and `bdk_esplora` now report the exact block that the transaction is in, which removes the need for having the old `ConfirmationTimeHeightAnchor` and `ConfirmationHeightAnchor`. This PR introduces a new, simpler anchor type that can be modified to support additional data in the future.
|
I think we should not wait for complete tests before merging this PR. As long as the examples work fine it is good. This is for "beta" which does not need to be bug free. Also having this PR merged means we can work on the other anchor changes (which I need to create a ticket for). |
|
Also, the anchor changes that I am suggesting is going to conflict with |
| if unused_spk_count > stop_gap { | ||
| return Ok(scanned_spks); | ||
| unused_spk_count = unused_spk_count.saturating_add(1); | ||
| if unused_spk_count >= stop_gap { |
| // Prune `new_blocks` to only include blocks that are actually new. | ||
| .filter(|(height, _)| Some(*height) > agreement_height) | ||
| .map(|(height, hash)| BlockId { height, hash }) | ||
| .filter(|(height, _)| Some(*<&u32>::clone(height)) > agreement_height) |
There was a problem hiding this comment.
nit, feel free to ignore
| .filter(|(height, _)| Some(*<&u32>::clone(height)) > agreement_height) | |
| .filter(|(&height, _)| Some(height) > agreement_height) |
| } | ||
|
|
||
| #[test] | ||
| pub fn test_update_tx_graph_without_keychain() -> anyhow::Result<()> { |
There was a problem hiding this comment.
📌 If I recall, the name of this test is a relic from before the sync and full_scan concepts were developed. I might now call it sync_should_update_chain_and_tx_graph or similar, but not terribly important at the moment.
notmandatory
left a comment
There was a problem hiding this comment.
ACK 1a62488
Thanks for also adding the extra esplora tests for electrum!
Fixes #980.
Description
This PR is the first step in reworking
bdk_electrumto use merkle proofs. When we fetch a transaction, we now also obtain the merkle proof and block header for verification. We then insert an anchor only after validation that the transaction exists in a confirmed block. The loop logic that previously existed infull_scanto account for re-orgs has also been removed as part of this rework.This is a breaking change because
graph_updates now provide the fullConfirmationTimeHeightAnchortype. This removes the need for theElectrumFullScanResultandElectrumSyncResultstructs that existed only to provide the option for converting the anchor type fromConfirmationHeightAnchorintoConfirmationTimeHeightAnchor.Notes to the reviewers
Changelog notice
ConfirmationTimeHeightAnchorandConfirmationHeightAnchorhave been removed.ConfirmationBlockTimehas been introduced as a new anchor type.bdk_electrum'sfull_scanandsyncnow returngraph_updates withConfirmationBlockTime.Checklists
All Submissions:
cargo fmtandcargo clippybefore committingNew Features: