Skip to content

Conversation

@dcorral
Copy link

@dcorral dcorral commented Feb 11, 2026

This PR adds database persistence for RGB-specific data via the KVStoreSync trait, replacing direct filesystem operations with KVStore calls while maintaining filesystem fallback for backward compatibility.

Changes

New KVStore Functions (rgb_utils/mod.rs)

Added namespace constants and persistence functions:

pub const RGB_PRIMARY_NS: &str = "rgb";
pub const RGB_CHANNEL_INFO_NS: &str = "channel_info";
pub const RGB_CHANNEL_INFO_PENDING_NS: &str = "channel_info_pending";
pub const RGB_PAYMENT_INFO_INBOUND_NS: &str = "payment_info_inbound";
pub const RGB_PAYMENT_INFO_OUTBOUND_NS: &str = "payment_info_outbound";
pub const RGB_TRANSFER_INFO_NS: &str = "transfer_info";

New functions:

  • read_rgb_transfer_info_kv / write_rgb_transfer_info_kv
  • read_rgb_channel_info_kv / write_rgb_channel_info_kv / remove_rgb_channel_info_kv
  • read_rgb_payment_info_kv / write_rgb_payment_info_kv
  • get_rgb_channel_info_pending_kv

Dependency Injection

KVStore is now passed through struct fields:

  • KeysManager.rgb_kv_store
  • InMemorySigner.rgb_kv_store
  • OutboundPayments.rgb_kv_store
  • ChannelContext.rgb_kv_store

Filesystem Fallback

All RGB functions support graceful fallback when KVStore is None:

  • color_htlc - KVStore read/write with filesystem fallback
  • color_closing - Uses get_rgb_channel_info_pending with fallback
  • is_channel_rgb - Checks KVStore first, then filesystem
  • get_rgb_channel_info - KVStore with filesystem fallback
  • rename_rgb_files - Operates on both for compatibility

Design

  1. Optional KVStore - All functions accept Option<&Arc<dyn KVStoreSync + Send + Sync>>
  2. Backward compatible - Falls back to filesystem when KVStore unavailable

Breaking Changes

The following public functions now require an additional kv_store parameter:

Function New Parameter
is_channel_rgb kv_store: Option<&Arc<dyn KVStoreSync + Send + Sync>>
update_rgb_channel_amount kv_store: Option<&Arc<dyn KVStoreSync + Send + Sync>>
write_rgb_payment_info_file kv_store: &Arc<dyn KVStoreSync + Send + Sync> (also removed ldk_data_dir)

Callers can pass None to maintain existing filesystem-only behavior.

@dcorral dcorral changed the title RGB KVStore for persistence implementation RGB KVStore Integration Feb 11, 2026
@dcorral dcorral marked this pull request as draft February 11, 2026 10:16
@dcorral dcorral marked this pull request as ready for review February 11, 2026 12:37
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.

1 participant