Skip to content

RGB KVStore Integration#17

Open
dcorral wants to merge 1 commit intoRGB-Tools:rgbfrom
dcorral:persistence-layer
Open

RGB KVStore Integration#17
dcorral wants to merge 1 commit intoRGB-Tools:rgbfrom
dcorral:persistence-layer

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 through dependency injection.

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";
pub const RGB_CONSIGNMENT_NS: &str = "consignment";

New functions:

  • read_rgb_transfer_info / write_rgb_transfer_info
  • read_rgb_channel_info / write_rgb_channel_info / remove_rgb_channel_info
  • read_rgb_payment_info / write_rgb_payment_info
  • read_rgb_consignment / write_rgb_consignment / remove_rgb_consignment
  • get_rgb_channel_info_pending
  • is_payment_rgb
  • filter_first_hops

Dependency Injection

KVStore is now passed through struct fields as Arc<dyn KVStoreSync + Send + Sync>:

  • ChannelManager.rgb_kv_store
  • ChannelManagerReadArgs.rgb_kv_store
  • ChannelContext.rgb_kv_store
  • OutboundPayments.rgb_kv_store
  • KeysManager.rgb_kv_store
  • InMemorySigner.rgb_kv_store

Updated RGB Functions

All RGB functions now receive KVStore directly instead of filesystem paths:

  • color_commitment - Reads pending channel info and payment info from KVStore, writes transfer info
  • color_htlc - Reads transfer info from KVStore, writes updated transfer info
  • color_closing - Reads pending channel info from KVStore, writes transfer info
  • is_channel_rgb - Checks KVStore for channel RGB data
  • get_rgb_channel_info - Reads from KVStore
  • rename_rgb_files - Renames channel info and consignment entries in KVStore
  • handle_funding - Writes consignment and channel info to KVStore
  • update_rgb_channel_amount - Reads/writes channel info via KVStore

Proxy Key Pattern for HTLC Payments

Payment info uses a proxy key scheme for HTLC tracking:

  • Main key: payment_hash (hex)
  • Proxy key: {channel_id}_{payment_hash}
  • Pending key: {payment_hash}_pending

Design

  1. KVStore via dependency injection - Flows through all main structures rather than using a global registry
  2. Namespaced storage - All RGB data organized under rgb primary namespace with typed secondary namespaces
  3. Structured serialization - RgbInfo, RgbPaymentInfo, and TransferInfo serialized to KVStore

Breaking Changes

The following public functions now require a kv_store parameter instead of filesystem paths:

Function New Parameter
is_channel_rgb kv_store: &K where K: KVStoreSync
update_rgb_channel_amount kv_store: &K where K: KVStoreSync
write_rgb_payment_info_file kv_store: &K where K: KVStoreSync (also removed ldk_data_dir)
color_htlc kv_store: &dyn KVStoreSync
color_closing kv_store: &dyn KVStoreSync
handle_funding kv_store: &K where K: KVStoreSync

Struct constructors (ChannelManager, KeysManager, InMemorySigner, OutboundPayments) now require an rgb_kv_store parameter.

@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

Comments