Skip to content

sea-orm integration + rust-lightning persitence layer - #95

Open
dcorral wants to merge 1 commit into
RGB-Tools:masterfrom
dcorral:rust-lightning-tx-persistence
Open

sea-orm integration + rust-lightning persitence layer#95
dcorral wants to merge 1 commit into
RGB-Tools:masterfrom
dcorral:rust-lightning-tx-persistence

Conversation

@dcorral

@dcorral dcorral commented Feb 17, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces file-based persistence with SQLite database using sea-orm ORM.

Changes

New database tables:

  • mnemonic - encrypted mnemonic storage
  • kv_store - LDK persistence (channel manager, payments, swaps, network graph, scorer)
  • config - configuration key/value pairs (indexer_url, proxy_url, etc.)
  • revoked_token - revoked auth token IDs
  • channel_peer - channel peer pubkey/address mapping

Migrated to database:

  • Mnemonic (was encrypted file)
  • All LDK KVStore data (channel manager, inbound/outbound payments, swaps, scorer)
  • Config parameters (synced to files for rust-lightning compatibility)
  • Revoked tokens (was flat file)
  • Channel peer data (was flat file)
  • PSBTs (temporary storage during channel funding)
  • Output spender transactions

Architecture:

  • Single shared DatabaseConnection via Arc
  • SeaOrmKvStore implements rust-lightning's KVStoreSync trait
  • Migrations run automatically on startup
  • Config stored in DB as source of truth, synced to files for rust-lightning compatibility

rust-lightning submodule (961313cb061470):

  • RGB data persistence moved from filesystem to KVStoreSync trait across 8 files
  • rgb_utils/mod.rs: replaced file I/O (read_rgb_transfer_info, write_rgb_transfer_info, parse_rgb_payment_info, get_rgb_channel_info_path) with KVStore namespace-based read/write operations using RGB_PRIMARY_NS + secondary namespaces (channel_info, payment_info_inbound, payment_info_outbound, transfer_info, etc.)
  • ChannelContext, ChannelManager, OutboundPayments, KeysManager: added rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync> field, threaded through constructors and deserialization
  • color_commitment, color_htlc, color_closing: now take &dyn KVStoreSync instead of reading files directly
  • is_channel_rgb, get_rgb_channel_info, rename_rgb_files, filter_first_hops, is_payment_rgb: switched from path-based lookups to KVStore reads
  • Removed filesystem fallback — KVStore is now the sole persistence backend for RGB data

IMPORTANT!
This PR depends on RGB-Tools/rust-lightning#17 and .submodule must be updated to point to the right RGB-Tools fork before merging

@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch 3 times, most recently from 60ab584 to 8aceb21 Compare February 17, 2026 11:38
@zoedberg

Copy link
Copy Markdown
Member

@dcorral could you please rebase this PR?

@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from 8aceb21 to f71fb32 Compare March 24, 2026 12:35
@dcorral

dcorral commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

@zoedberg done!

@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch 11 times, most recently from 84b0895 to b67a1ff Compare March 30, 2026 20:44

@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! In addition to the requested changes please

  • commit the src/database/entities/prelude.rs file that gets generated by sea-orm-cli
  • add the migration cargo lock file to the .gitignore file and remove the file
  • do not make changes to src/database/entities/mod.rs since its autogenerated by sea-orm-cli
  • I know you took inspiration from rgb-lib when creating aliases like ChannelPeerActMod, but I saw this is not the best/recommended approach so please drop the aliases (see rgb-multisig-hub to see what is the best way to use the DB utility objects)
  • as requested in the rust-lightning PR, please keep only essential comments

P.S this is not a final review, will do another one after these requests have been addressed

Comment thread src/utils.rs Outdated
Comment thread src/runtime.rs Outdated
Comment thread src/utils.rs Outdated
Comment thread migration/src/m20250127_000001_init_db.rs Outdated
Comment thread migration/src/m20250127_000001_init_db.rs Outdated
Comment thread migration/src/m20250127_000001_init_db.rs Outdated
Comment thread migration/src/m20250127_000001_init_db.rs Outdated
Comment thread src/ldk.rs Outdated
Comment thread src/database/mod.rs Outdated
@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch 3 times, most recently from 8bdceb4 to a92fa60 Compare May 19, 2026 08:10
@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch 2 times, most recently from f956780 to 4c7960b Compare May 25, 2026 10:52
@Arshia-r-m

Copy link
Copy Markdown
Contributor

Hi every one, what's the status of this PR?
I think this can help us a lot since on the nodes we maintain we face a lot of file corruptions which I believe can be enhanced with this!

@zoedberg

zoedberg commented Jul 2, 2026

Copy link
Copy Markdown
Member

I agree the changes in this PR are important and would like to understand if this has been paused intentionally. From what I see, the feedback I provided before hasn't been addressed yet, and there are also some merge conflicts. @dcorral please let us know

@dcorral

dcorral commented Jul 2, 2026

Copy link
Copy Markdown
Contributor Author

Yes I needed to postpone the work on this PR, anyway I believe I'll have some time starting next week to address the requested changes and push this work forward.

@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from 4c7960b to f9b9f02 Compare July 7, 2026 12:14
@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from f9b9f02 to 2e31b86 Compare July 7, 2026 12:43
@dcorral
dcorral requested a review from zoedberg July 8, 2026 10:31
Comment thread src/ldk.rs Outdated
Comment thread src/ldk.rs Outdated
Comment thread src/utils.rs
Comment thread src/disk.rs Outdated
Comment thread src/utils.rs Outdated
Comment thread src/ldk.rs Outdated
@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from e30737f to 4613b16 Compare July 14, 2026 11:21
txalkan pushed a commit to txalkan/rgb-lightning-node that referenced this pull request Jul 15, 2026
* Add remote external signer logic

* Update deps

* Fix clippy

* Review fixes

* Fix review comments

* Fix clippy

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

It seems we are almost done, please rebase this on the updated master tip. If it's ok for you in the next iteration if I find something that needs to be addressed I will do it on top of your commit

@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from 4613b16 to b64cd7f Compare July 23, 2026 11:35
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.78947% with 112 lines in your changes missing coverage. Please review.
✅ Project coverage is 88.24%. Comparing base (463b244) to head (a85e97b).

Files with missing lines Patch % Lines
src/kv_store.rs 92.79% 40 Missing ⚠️
src/ldk.rs 88.44% 38 Missing ⚠️
src/routes.rs 92.05% 12 Missing ⚠️
src/auth.rs 58.33% 5 Missing ⚠️
src/utils.rs 94.20% 4 Missing ⚠️
src/error.rs 0.00% 3 Missing ⚠️
src/backup.rs 92.85% 2 Missing ⚠️
src/database/entities/channel_peer.rs 85.71% 2 Missing ⚠️
src/database/entities/config.rs 90.47% 2 Missing ⚠️
src/database/entities/kv_store.rs 86.66% 2 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master      #95      +/-   ##
==========================================
+ Coverage   87.78%   88.24%   +0.46%     
==========================================
  Files          13       18       +5     
  Lines        7613     8227     +614     
==========================================
+ Hits         6683     7260     +577     
- Misses        930      967      +37     
Flag Coverage Δ
rust 88.24% <90.78%> (+0.46%) ⬆️

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.

@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from 6e98c77 to f7bb4cf Compare July 24, 2026 11:29
@dcorral
dcorral force-pushed the rust-lightning-tx-persistence branch from f7bb4cf to a85e97b Compare July 24, 2026 15:38
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.

3 participants