Skip to content

Add IndexedChain trait and implement for Esplora & Electrum #490

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

Closed
wants to merge 0 commits into from

Conversation

johncantrell97
Copy link
Contributor

@johncantrell97 johncantrell97 commented Nov 30, 2021

Description

This PR introduces the trait IndexedChain that Blockchains can implement if they have access to chain data. There are lots of methods that could be added to this trait (the entire esplora/electrum apis) but I started with the data I needed to provide LDK with the chain data it needs to function.

I have implemented the trait for Esplora and Electrum blockchains.

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

@johncantrell97 johncantrell97 force-pushed the master branch 2 times, most recently from 2d0d749 to 34ef964 Compare December 1, 2021 01:23
Copy link
Contributor

@LLFourn LLFourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ACK

One thing I'd like to change.

In addition this should come with tests in a similar manner to how existing blockchain tests work (except use a different macro to generate tests specifically for this trait).

@@ -48,6 +48,63 @@ pub struct ElectrumBlockchain {
stop_gap: usize,
}

impl IndexedChain for ElectrumBlockchain {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since each of these queries requires a different underlying index I think it makes sense to have a different trait for each index e.g. GetBlockHeader, GetPositionInBlock etc.

Copy link
Contributor

@rajarshimaitra rajarshimaitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept ack on breaking down the Blockchain into multiple traits. I think this will be eventually needed to make the lib more versatile.

Code changes looks good to me. If the difference between vanilla Blockchain and the other types are based on the capabilities (indexes) of different backends, then it might make sense to have such per capability traits as @LLFourn suggested.

But for now, I think its a good start.

Just one doc request.

pub block_height: Option<u32>,
}

/// A trait Blockchains can implement if they support querying chain data
Copy link
Contributor

@rajarshimaitra rajarshimaitra Dec 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "support querying chain data" do you mean availability of certain indexing in those blockchain? In that case it might make sense to elaborate the doc a little to explain what are those special requirements. Also how IndexedChain is different from regular backends with the Blockchain trait.

In general a little explainer doc for this new trait would be very nice.

@johncantrell97 johncantrell97 force-pushed the master branch 2 times, most recently from 66e9aa8 to 261e333 Compare December 4, 2021 21:11
@notmandatory
Copy link
Member

Now that #501 is in you'll need to rebase on master to fix the CI issue.

@LLFourn LLFourn self-assigned this Jan 27, 2022
@LLFourn LLFourn mentioned this pull request Jan 27, 2022
4 tasks
@notmandatory notmandatory removed this from the Release 0.17.0 Feature Freeze milestone Feb 8, 2022
notmandatory added a commit to notmandatory/bdk that referenced this pull request Mar 9, 2022
0cc4700 Fix typo in CHANGELOG and doc in wallet/mod.rs (Steve Myers)
660faab Fix typo in CHANGELOG (LLFourn)
45767fc Remove max_addresses sync param (LLFourn)
fbb50ad apply doc suggestions from @notmandatory (Lloyd Fournier)
035307e [rpc] Filter out unrelated transactions (LLFourn)
c0e75fc Split get_tx into its own trait (LLFourn)
dcd90f8 Restore but depreciate new_offline (LLFourn)
410a513 Add SyncOptions as the second argument to Wallet::sync (LLFourn)
326bfe8 Remove Blockchain from wallet (LLFourn)

Pull request description:

  While trying to finish bitcoindevkit#490 I thought that it'd be better to try the idea of getting rid of a lot of the async macros and just having tow different traits for sync and async stuff. While trying to do that I felt that this needed to be done first.

  The goal of this change is to decouple the wallet from the blockchain trait. A wallet is something that keeps track of UTXOs and transactions (and can sign things). The only reason it should need to talk to the blockchain is if doing a `sync`. So we remove all superfluous calls to the blockchain and precisely define the requirements for the blockchain to be used to sync with two new traits: `WalletSync` and `GetHeight`.

  1. Stop requesting height when wallet is created
  2. `new_offline` is just `new` now.
  3. a `WalletSync + GetHeight` is now the first argument to `sync`.
  4. `SyncOptions` replaces the existing options to `sync` and allows for less friction when making breaking changes in the fuutre (no more noop_progress!).
  5. We `Box` the `Progress` now to avoid type parameters
  6. broadcast has been removed from `Wallet`. You just use the blockchain directly to broadcast now.

  ### Notes to the reviewers

  This needs bitcoindevkit#502 before it can be merged but can reviewed now.
  Be on the look up for stale documentation from this change.
  Our doc build looks broken because of ureq or something.

  ### Checklists

  #### All Submissions:

  * [x] I've signed all my commits
  * [x] I followed the [contribution guidelines](https://github.com/bitcoindevkit/bdk/blob/master/CONTRIBUTING.md)
  * [x] I ran `cargo fmt` and `cargo clippy` before committing
  * [x] I've updated `CHANGELOG.md`

Top commit has no ACKs.

Tree-SHA512: a8f3e21e45359be642b1f30d4ac1ba74785439e1b770dbeab0a5a4b8aab1eef4bb6b855aea4382e289257bc890fa713ca832a8b6c9655f7a59e96d412b4da3e6
@jlopp
Copy link

jlopp commented Apr 14, 2022

Concept ACK - would love to see this functionality get merged.

@notmandatory notmandatory mentioned this pull request Apr 14, 2022
3 tasks
@LLFourn
Copy link
Contributor

LLFourn commented Apr 19, 2022

FWIW my plan is not to merge this PR or something similar but rather to reduce the surface area that the main BDK lib has with blockchain interactions. I have got feedback that people really want a fully featured rust interface to esplora's http api though. The question to me is do we really need traits in BDK that define this behaviour? It seems like a small thing to leave up to the application developer if they indeed want to have blockchain data polymorphism.

@tnull tnull mentioned this pull request Aug 4, 2022
6 tasks
klochowicz added a commit to klochowicz/bdk-ldk that referenced this pull request Nov 7, 2022
- stop depending on bdk fork (it's not longer required, migrate code from PR
bitcoindevkit/bdk#490 directly into this repository)
- clean up code (some variable renames, remove unnecessary trait bounds)

Note: esplora-related code was not migrated for now, can be added at any later point.
klochowicz added a commit to klochowicz/bdk-ldk that referenced this pull request Nov 7, 2022
- stop depending on bdk fork (it's not longer required, migrate code from PR
bitcoindevkit/bdk#490 directly into this repository)
- clean up code (some variable renames, remove unnecessary trait bounds)
- add a simple test that verifies that LightningWallet can be initialised

Note: esplora-related code was not migrated for now, can be added at any later point.
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 this pull request may close these issues.

5 participants