Conversation
bfd1282 to
ae01706
Compare
|
|
with the rest I do agree, let's do it! but the only thing I have no idea yet is "PSBT Files". I don't really understand the purpose of this files yet, so this we need to figure out and ask in RLN chat |
24a6dad to
d4f2c0d
Compare
*AI generated reportRLN Filesystem Persistence AuditGoalConsolidate all critical node state into a single SQLite database file ( Current State SummaryAlready in Database (rln_db)
Still on FilesystemEverything else. See detailed breakdown below. Filesystem Data Analysis1. LDK Core State (
|
| File/Directory | Description | Can Migrate? | Recommendation |
|---|---|---|---|
manager |
ChannelManager serialized state | No | LDK reads directly via ChannelManagerReadArgs |
network_graph |
Lightning network routing graph | No | LDK reads directly on startup |
scorer |
Probabilistic payment routing scorer | No | LDK reads directly on startup |
monitors/* |
Per-channel monitor state | No | ChainMonitor reads directly |
monitor_updates/* |
Incremental monitor updates | No | MonitorUpdatingPersister reads directly |
archived_monitors/* |
Archived channel monitors | No | LDK reads directly |
Verdict: These cannot be migrated. LDK's persistence layer (FilesystemStore, MonitorUpdatingPersister) expects files on disk. Changing this would require modifying rust-lightning itself.
2. RLN Application State (.ldk/ directory)
These are written via FilesystemStore::write() but read by RLN code, not LDK internals.
| File | Description | Can Migrate? | Recommendation |
|---|---|---|---|
inbound_payments |
Payment hash to payment info map | Yes | Migrate to DB |
outbound_payments |
Payment ID to payment info map | Yes | Migrate to DB |
channel_ids |
Temporary to final channel ID map | Yes | Migrate to DB |
maker_swaps |
Maker swap data | Yes | Migrate to DB |
taker_swaps |
Taker swap data | Yes | Migrate to DB |
output_spender_txes |
Output spending transaction data | Yes | Migrate to DB |
Verdict: These can be migrated. They're read/written via src/disk.rs functions that you control.
Migration approach: Create new tables for each, serialize/deserialize using the same TLV format, or store as JSON/binary blobs.
3. RGB Channel & Payment State (.ldk/ directory)
These are read/written by rust-lightning's RGB extensions (rgb_utils/mod.rs).
| File Pattern | Description | Can Migrate? | Recommendation |
|---|---|---|---|
{channel_id} |
RGB channel info (contract, amounts) | No | rust-lightning reads directly |
{channel_id}.pending |
Pending RGB channel state | No | rust-lightning reads directly |
{payment_hash}.inbound |
Inbound RGB payment info | No | rust-lightning reads directly |
{payment_hash}.outbound |
Outbound RGB payment info | No | rust-lightning reads directly |
consignment_* |
RGB consignment files | No | rust-lightning reads directly |
*_transfer_info |
RGB transfer information | No | rust-lightning reads directly |
psbt_* |
Partially signed transactions | Temporary | Cleaned up after use |
Verdict: These cannot be migrated without modifying rust-lightning. The rgb_utils/mod.rs module reads these files directly:
// rust-lightning/lightning/src/rgb_utils/mod.rs
let serialized_info = fs::read_to_string(rgb_channel_info_path).expect("valid rgb info file");4. RGB Configuration Files (root storage directory)
These are currently in a hybrid state: database is source of truth, but files are synced for rust-lightning compatibility.
| File | Description | In DB? | File Required? | Recommendation |
|---|---|---|---|---|
indexer_url |
Electrum indexer URL | Yes | Yes | Keep sync (rust-lightning reads) |
proxy_endpoint |
RGB proxy URL | Yes | Yes | Keep sync (rust-lightning reads) |
bitcoin_network |
Network (mainnet/testnet/regtest) | Yes | Yes | Keep sync (rust-lightning reads) |
wallet_fingerprint |
BIP32 wallet fingerprint | Yes | Yes | Keep sync (rust-lightning reads) |
wallet_account_xpub_colored |
xpub for colored assets | Yes | Yes | Keep sync (rust-lightning reads) |
wallet_account_xpub_vanilla |
xpub for BTC | Yes | Yes | Keep sync (rust-lightning reads) |
wallet_master_fingerprint |
Master key fingerprint | Yes | Yes | Keep sync (rust-lightning reads) |
Verdict: Already correctly implemented. The database is the source of truth, and sync_rgb_config_to_files() keeps files in sync for rust-lightning.
rust-lightning reads these directly:
// rust-lightning/lightning/src/rgb_utils/mod.rs:129
fn _get_rgb_wallet_dir(ldk_data_dir: &Path) -> PathBuf {
let fingerprint = _read_file_in_parent(ldk_data_dir, WALLET_FINGERPRINT_FNAME);
_get_file_in_parent(ldk_data_dir, &fingerprint)
}5. Logs
| File | Description | Can Migrate? | Recommendation |
|---|---|---|---|
.ldk/logs/logs.txt |
LDK debug logs | No | Keep on filesystem |
logs/rln.log.* |
RLN application logs (rotating) | No | Keep on filesystem |
Verdict: Logs should remain on filesystem. They're append-only, can grow large, and don't need to be backed up with node state.
6. RGB-Lib Wallet Data (managed by rgb-lib)
| Path | Description | Can Migrate? | Recommendation |
|---|---|---|---|
{wallet_fingerprint}/ |
RGB wallet directory | No | Managed by rgb-lib |
| RGB-lib SQLite DB | Asset contracts, transfers, UTXOs | No | Separate DB, managed by rgb-lib |
Verdict: This is managed entirely by rgb-lib. You'd need rgb-lib changes to consolidate this.
Migration Priority
High Priority (Should Migrate)
These are RLN-specific data that you fully control:
inbound_payments- Payment trackingoutbound_payments- Payment trackingchannel_ids- Channel ID mappingmaker_swaps- Swap statetaker_swaps- Swap stateoutput_spender_txes- Transaction tracking
Suggested schema:
-- Option 1: Dedicated tables with proper columns
CREATE TABLE inbound_payments (
payment_hash BLOB PRIMARY KEY,
preimage BLOB,
secret BLOB,
status INTEGER,
amt_msat INTEGER,
created_at INTEGER,
updated_at INTEGER,
payee_pubkey BLOB
);
-- Option 2: Simple blob storage (preserves TLV format)
CREATE TABLE ldk_state (
key TEXT PRIMARY KEY,
value BLOB
);Cannot Migrate (rust-lightning constraints)
These require files on disk because rust-lightning reads them directly:
- LDK core:
manager,network_graph,scorer,monitors/* - RGB state:
{channel_id},{payment_hash}.*,consignment_* - RGB config files (but already synced from DB)
Should Not Migrate
- Logs (append-only, large, not critical state)
Backup Strategy
Given the constraints, a complete backup requires:
Option A: Database + LDK Directory
Backup contents:
├── rln_db # SQLite database (mnemonic, config, peers, payments, swaps)
└── .ldk/ # LDK state directory
├── manager
├── network_graph
├── scorer
├── monitors/
├── {channel_id} files
└── {payment_hash}.* files
Option B: Database + Selective File Backup
After migrating payments/swaps to DB:
Backup contents:
├── rln_db # Complete application state
└── .ldk/ # Only LDK-required files
├── manager # Critical
├── monitors/ # Critical
├── {channel_id} # Critical (RGB)
└── {payment_hash}.* # Critical (RGB)
Files that can be regenerated (no backup needed):
network_graph- Re-downloaded from networkscorer- Rebuilt over time- RGB config files - Synced from database
Implementation Roadmap
Phase 1: Migrate RLN Application State
- Create new database tables for payments, swaps, channel IDs
- Modify
src/disk.rsread functions to query database instead of files - Modify
src/ldk.rswrite operations to save to database - Add migration logic to import existing file data on first run
- Remove file-based storage after successful migration
Phase 2: Optimize Backup
- Create backup command that exports only:
rln_db(complete database).ldk/manager(channel state).ldk/monitors/*(channel monitors)- RGB channel/payment files
- Create restore command that imports backup and syncs config files
Phase 3: (Future) Coordinate with rust-lightning
If you need further consolidation, propose changes to rust-lightning:
- Abstract
rgb_utilsfile access behind a trait - Allow custom storage backends for RGB state
Summary Table
| Data Category | Current Storage | Target Storage | Blocker |
|---|---|---|---|
| Mnemonic | Database | Database | None (done) |
| RGB Config | Database + Files | Database + Files | rust-lightning reads files |
| Channel Peers | Database | Database | None (done) |
| Revoked Tokens | Database | Database | None (done) |
| Payments (in/out) | Files | Database | None - migrate |
| Swaps | Files | Database | None - migrate |
| Channel IDs | Files | Database | None - migrate |
| Output Spender Txes | Files | Database | None - migrate |
| LDK Manager | Files | Files | rust-lightning |
| LDK Monitors | Files | Files | rust-lightning |
| Network Graph | Files | Files | rust-lightning (can regenerate) |
| Scorer | Files | Files | rust-lightning (can regenerate) |
| RGB Channel State | Files | Files | rust-lightning |
| RGB Payment State | Files | Files | rust-lightning |
| Logs | Files | Files | Should stay on filesystem |
| RGB-lib Wallet | Separate DB | Separate DB | rgb-lib |
Conclusion
You can migrate 6 data types (payments, swaps, channel IDs, output spender txes) to the database, which will consolidate most RLN application state. However, LDK core state and RGB channel/payment state must remain on the filesystem due to rust-lightning's direct file access patterns.
For backups, the recommended approach is:
- Migrate what you can to
rln_db - Backup
rln_db+ critical.ldk/files (manager, monitors, RGB state) - Skip regeneratable files (network_graph, scorer) and logs
Increase worker threads to 3
|
closing this in favor of: RGB-Tools#92 |
Data Persistence Analysis for Migration to Sea-ORM Database in LRN
The following data is currently written to disk:
1. Logs
data_dir/logs/logs.txt2. Channel Peer Data (
channel_peer_data)pubkey@address.ldk_data_dir/channel_peer_data3. PSBT Files (
psbt_{txid})ldk_data_dir/psbt_{funding_txid}4. Configuration Files
storage_dir_path/indexer_urlstorage_dir_path/bitcoin_networkstorage_dir_path/wallet_fingerprintstorage_dir_path/wallet_account_xpub_coloredstorage_dir_path/wallet_account_xpub_vanillastorage_dir_path/wallet_master_fingerprint5. Encrypted Mnemonic
mnemonic_path(user-specified)6. Revoked Tokens
7. Asset Media Files
file_path(user-uploaded)8. Backup Files
9. Serialized Lightning Data Structures
ldk_data_dir/network_graph(NetworkGraph)ldk_data_dir/inbound_payments(InboundPaymentInfoStorage)ldk_data_dir/outbound_payments(OutboundPaymentInfoStorage)ldk_data_dir/output_spender_txes(OutputSpenderTxes)ldk_data_dir/maker_swapsandtaker_swaps(SwapMap)ldk_data_dir/channel_ids(ChannelIdsMap)ldk_data_dir/scorer(ProbabilisticScorer)Candidates for DB Migration
Keep as Files