Skip to content

Store BDK wallet data in rgb-lib database - #104

Open
markuslevonyak wants to merge 1 commit into
RGB-Tools:masterfrom
markuslevonyak:bdk-data-in-rgb-lib-db
Open

Store BDK wallet data in rgb-lib database#104
markuslevonyak wants to merge 1 commit into
RGB-Tools:masterfrom
markuslevonyak:bdk-data-in-rgb-lib-db

Conversation

@markuslevonyak

@markuslevonyak markuslevonyak commented Aug 20, 2026

Copy link
Copy Markdown

Store the BDK wallet data (its ChangeSet) in rgb-lib's own database instead of a separate bdk_db file, removing the file_store feature.

Motivation

Follow-up to #87: bdk_file_store is a development/testing database not meant for production, and its format breaks across BDK major upgrades. A rescan cannot recover from that, since revealed-but-unpaid invoice addresses have no chain history. #87 (switching to bdk_sqlite) was closed in favor of integrating BDK persistence into rgb-lib's existing database layer: one database technology, no coupling between sea-orm's and BDK's SQLite stacks, room for future non-SQLite backends.

Design

  • Relational, mirroring BDK's schema one-to-one (table names singularized, versioning via rgb-lib's migrator): BDK's own persister needs rusqlite, and a serialized-blob approach would be fragile across upgrades. Keeping the schema identical makes future BDK bumps a mechanical diff against upstream's rusqlite_impl.rs.
  • Persistence rides rgb-lib's DB transaction: the pool has a single connection and BDK persists happen while a DbTxn is open (sync, broadcast, address reveal), so with single-writer SQLite a separate connection would deadlock. Bonus: BDK and RGB state now commit or roll back atomically.
  • Signing and watch-only wallets share one store: BDK persists only the public descriptor (keys live in the in-memory signers), so both produce the identical ChangeSet. The separate bdk_db_watch_only file was a pre-1.0-BDK workaround.

Migration

None: the old bdk_db file is ignored and chain data is rebuilt on the next sync. This one-time break is unavoidable; the new store is what prevents it from recurring.

@codecov

codecov Bot commented Aug 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.81208% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.25%. Comparing base (fd1aca2) to head (83da955).

Files with missing lines Patch % Lines
src/database/bdk.rs 96.48% 18 Missing ⚠️
src/wallet/core.rs 96.77% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #104      +/-   ##
==========================================
+ Coverage   96.24%   96.25%   +0.01%     
==========================================
  Files          24       26       +2     
  Lines       13418    13909     +491     
==========================================
+ Hits        12914    13388     +474     
- Misses        504      521      +17     
Flag Coverage Δ
rust 96.25% <96.81%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@zoedberg zoedberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot for this PR, excellent work!

This is a partial review, will report some stuff here and for some other I will just do a commit on top. Please also lint the code (job is failing)

Comment thread src/wallet/core.rs Outdated
bitcoin_network: BitcoinNetwork,
) -> Result<BdkWallet, Error> {
let chain_net: ChainNet = bitcoin_network.into();
let mut load_params = BdkWallet::load()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let mut load_params = BdkWallet::load()
let mut wallet_params = BdkWallet::load()

let's avoid unnecessary changes to keep the diff small and the blame intact

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right. Done.

@markuslevonyak
markuslevonyak force-pushed the bdk-data-in-rgb-lib-db branch from 83da955 to a6013ea Compare August 20, 2026 10:31
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.

2 participants