Skip to content

Conversation

110CodingP
Copy link
Contributor

@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 17216612833

Details

  • 0 of 49 (0.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.1%) to 2.831%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/persister.rs 0 14 0.0%
src/handlers.rs 0 35 0.0%
Totals Coverage Status
Change from base Build 17216365664: -0.1%
Covered Lines: 25
Relevant Lines: 883

💛 - Coveralls

@110CodingP
Copy link
Contributor 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.

@110CodingP 110CodingP requested a review from tvpeter July 21, 2025 13:27
@110CodingP 110CodingP marked this pull request as ready for review July 25, 2025 03:48
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.

Great job, @110CodingP!
Your implementation looks great. I've left a few comments. Once you make the updates, I will test it.

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.

tACK 26d7e8b

Weldone @110CodingP, I have tested and everything seems to work fine.
Kindly squash your commits into two or three at most, then I will approve.
Thank you.

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.

tACK a5ecee6

Since the user does not need to know about how commands are being
handled.
@110CodingP
Copy link
Contributor Author

Rebased!

Copy link
Member

@notmandatory notmandatory left a comment

Choose a reason for hiding this comment

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

utACK 83e6dd6

Will be handy having this in bdk-cli for testing and as an example for how to use redb with bdk_wallet.

@tvpeter tvpeter merged commit 67011b3 into bitcoindevkit:master Aug 26, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from In Progress to Done in BDK-CLI Aug 26, 2025
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: Done

Development

Successfully merging this pull request may close these issues.

4 participants