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

no_std support #205

Closed
3 tasks
justinmoon opened this issue Dec 1, 2020 · 10 comments
Closed
3 tasks

no_std support #205

justinmoon opened this issue Dec 1, 2020 · 10 comments
Labels
discussion There's still a discussion ongoing
Milestone

Comments

@justinmoon
Copy link
Contributor

justinmoon commented Dec 1, 2020

Hardware wallets should be able to use BDK.

This will need to happen in a few steps:

I have an ugly prototype for rust-bitcoin using bare-io to polyfill std::io stuff that's missing from no_std. Going to make a draft PR shortly and get some feedback.

@justinmoon justinmoon reopened this Dec 1, 2020
@mcroad
Copy link
Contributor

mcroad commented Oct 13, 2021

rust-bitcoin/rust-bitcoin#603 added no_std support

@mcroad
Copy link
Contributor

mcroad commented Apr 14, 2022

Small update

To the BDK team

There are 2 main approaches to implementing no_std support. One, using the no-std-compat crate, and the other is using core directly.

Using no-std-compat is the simpler approach as it would leave most of the code unchanged. no-std-compat will continue using the std library in std environments but replaces std and polyfills any necessary features in no_std environments using core under the hood.

The second approach is to use the core crate directly. This apprach would modify most files as imports would be taken from core instead of std. This is what rust-bitcoin did and rust-miniscript will do. See https://github.com/rust-bitcoin/rust-miniscript/pull/277/files for an example of what it might look like.

The main downside that from using no-std-compat is taking on one more dependency with the upside being that the code would remain looking like regular std code. Using core directly keeps dependencies as is, but slightly increases code complexity and maintenance burden.

@notmandatory
Copy link
Member

notmandatory commented Apr 14, 2022

Thanks for the no_std update! one thing the team is working on, started in #535 is to decouple the bdk Wallet from the Blockchain and Database modules, this will make it possible to have a Wallet with less dependencies and maybe older MSRV and should make it easier to support no_std with something like core. Plus to support a full wallet we'll need at least a Database that supports no_std even if it's only in memory.

@afilini
Copy link
Member

afilini commented Apr 15, 2022

I would first give it a shot with the core approach and see what happens. If it turns out to be too messy we can try with something else, but ideally I would avoid extra dependencies and I would try to stay aligned with the rest of the rust-bitcoin environment.

Plus to support a full wallet we'll need at least a Database that supports no_std even if it's only in memory.

I'm assuming most hardware devices won't have permanent storage for UTXOs, so it's probably fine to release with just the MemoryDatabase initially.

@LLFourn
Copy link
Contributor

LLFourn commented Apr 19, 2022

I am writing about this for the blog post which should drop this week but here's my current vision on how this would work with bdk_core:

  1. I'll introduce something called DescriptorTracker which will be something that has a descriptor and a bunch of in-memory stores of addresses, transactions, txouts and so on.
  2. You update the descriptor tracker with data from blockchain (which it checkpoints based on block height/header)
  3. You can then write out its state to persistent storage. In particular write out checkpoints, transactions and address index. The persistent storage doesn't index stuff like spks, txouts etc, rather this can be re-indexed when re-loaded into a DescriptorTracker.

So bdk_core app developer (which uses rust's core lib) would only really have the job of storing lists of transactions which could just be dumped to a file. So think MemoryDatabase except with better indexing and it is designed to be written out to different persistent storage options. Hopefully that makes sense. If it doesn't I'll try and do better in the blog post.

@notmandatory
Copy link
Member

I like this approach, makes sense to me.

sanket1729 added a commit to rust-bitcoin/rust-miniscript that referenced this issue Jun 5, 2022
ac16e05 Add no_std support (mcroad)

Pull request description:

  Closes #201. Related to bitcoindevkit/bdk#205

  Not ready.

  - [x] `no_std` example
  - [x] updated readme with instructions
  - [x] tests pass
  - [x] rust-bitcoin/rust-bitcoin#637 includes `secp256k1/alloc` feature in `bitcoin/no-std`. Released on `0.28.0`
  - [x] rust-bitcoin/rust-bitcoin#690 Rust `1.47` set as `no_std` MSRV. Released in `0.28.1`.

  Maintains backward compatibility. To use it in a `no_std` context set `default-features = false` and enable the `no-std` feature.

  ~~To the maintainers: I added the `no-std-compat` crate. It wraps `core` and `hashbrown` and makes them look like `std`. This is a different than what `rust-bitcoin` did. They use `core` and `hashbrown` directly. I believe using `no-std-compat` makes the code more readable. I'd like to hear your thoughts on this.~~ Now using `hashbrown` and `core` directly.

ACKs for top commit:
  sanket1729:
    ACK ac16e05

Tree-SHA512: 5c26cb50374b7844acbcc5a7607f5710ce19ec0aff4caed1346ed4a2fb708a909205a7d87cc27a773624f43b2a99a71c3ba4bb1cdf2dfec0584833df00b9f032
@mcroad
Copy link
Contributor

mcroad commented Jun 6, 2022

rust-bitcoin resolved the MSRV issue in 0.28.1 and rust-miniscript no_std support added in rust-bitcoin/rust-miniscript#277. Will begin working on the BDK no_std PR Soon™.

@notmandatory
Copy link
Member

notmandatory commented Jan 6, 2023

Here's another request from @BitcoinComfy for no_std support and to be able to create a static build for thumbv4t-none-eabi and run on a feature phone.

twitter thread: https://twitter.com/BitcoinComfy/status/1611332656570191873

@mcroad
Copy link
Contributor

mcroad commented Jan 15, 2023

Making slow progress on this. I immediately noticed just how big BDK is, especially for embedded devices.

Safe to say no_std will be on hold until bdk_core integration is complete.

@LLFourn
Copy link
Contributor

LLFourn commented Jan 18, 2023

FWIW I have made it no_std in #793

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion There's still a discussion ongoing
Projects
Archived in project
Archived in project
Development

No branches or pull requests

6 participants