Skip to content

feat: add redb as an alternative to sqlite #206

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

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

110CodingP
Copy link

@110CodingP 110CodingP commented Jul 11, 2025

Description

We currently only support sqlite persistence. This PR adds an alternative redb persistence by leveraging Summer Of Bitcoin work on bdk_redb.

Notes to the reviewers

The CI does not pass since bdk_redb has a MSRV of 1.85.0 which is in turn due to redb. Also bdk_redb is yet to published as a crate so currently we use the GitHub version of the same.

The following script tests a simple scenario of creating a wallet with bitcoind-rpc as chain source , sending funds to an address controlled by the wallet and creating a transaction using the wallet:

rm -rf ~/.bitcoin/regtest
rm -rf ~/.bdk-bitcoin

bitcoin-cli -rpcuser=alice -rpcpassword=password createwallet alice

export NETWORK=regtest

export EXT_DESCRIPTOR=$(bitcoin-cli -rpcwallet=alice -rpcuser=alice -rpcpassword=password listdescriptors true | jq -r '.descriptors | .[0] | .desc')

export INT_DESCRIPTOR=$(bitcoin-cli -rpcwallet=alice -rpcuser=alice -rpcpassword=password listdescriptors true | jq -r '.descriptors | .[1] | .desc')
 
 
export DATABASE_TYPE=redb
export CLIENT_TYPE=rpc
export SERVER_URL=127.0.0.1:18443

addr=$(bdk-cli wallet -w alice -a alice:password new_address | jq -r '.address')

bitcoin-cli -rpcuser=alice -rpcpassword=password -rpcwallet=alice generatetoaddress 102 $addr

bdk-cli wallet -w alice -a alice:password full_scan
bdk-cli wallet -w alice -a alice:password balance

recipient=$(bitcoin-cli  -rpcwallet=alice getrawchangeaddress)
psbt=$(bdk-cli wallet -w alice -a alice:password create_tx --to "$recipient:5000" | jq -r '.psbt')

signed_psbt=$(bdk-cli wallet -w alice -a alice:password sign $psbt | jq -r '.psbt')
bdk-cli wallet -w alice -a alice:password broadcast --psbt $signed_psbt

unset $addr

addr=$(bdk-cli wallet -w alice -a alice:password new_address | jq -r '.address')
bitcoin-cli -rpcuser=alice -rpcpassword=password -rpcwallet=alice generatetoaddress 1 $addr

bdk-cli wallet -w alice -a alice:password sync
bdk-cli wallet -w alice -a alice:password balance

the conf is as follows:

regtest=1

[regtest]
server=1
rpcuser=alice
rpcpassword=password 

Also removed sqlite from default features since we now have an alternative.

Changelog notice

Checklists

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 (test is in the PR description)
  • I've added docs for the new feature
  • I've updated CHANGELOG.md

Copy link
Collaborator

@tvpeter tvpeter left a comment

Choose a reason for hiding this comment

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

I have not tested but I left a few comments.

I think it is a good idea to leave sqlite as the default db. Users can compile with no default features if they want to use redb. But when you open the PR, I will test it properly to have a better opinion.

In the meantime, a good job so far.

@notmandatory notmandatory added the summer-of-bitcoin Summer of Bitcoin Project label Jul 14, 2025
@notmandatory notmandatory moved this to In Progress in BDK-CLI Jul 14, 2025
@coveralls
Copy link

coveralls commented Jul 14, 2025

Pull Request Test Coverage Report for Build 16288030656

Details

  • 0 of 47 (0.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.2%) to 2.838%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/persister.rs 0 14 0.0%
src/handlers.rs 0 33 0.0%
Totals Coverage Status
Change from base Build 15731603419: 0.2%
Covered Lines: 25
Relevant Lines: 881

💛 - Coveralls

@110CodingP
Copy link
Author

I think it is a good idea to leave sqlite as the default db. Users can compile with no default features if they want to use redb. But when you open the PR, I will test it properly to have a better opinion.

Made sqlite a default feature again.

wallet is a default feature :)
And add individual database errors instead. This
makes error handling cleaner as suggested by tvpeter.
Since the user does not need to know about how commands are being
handled.
Since bdk_redb can handle multiple wallets in a single db file, we donot
need to make separate folders for each wallet. Also changed default
wallet name from wallet1 to wallet in case of redb for compatibility
with sqlite.
Since bdk_redb is now published on Crates.io
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
summer-of-bitcoin Summer of Bitcoin Project
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

4 participants