Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lightning/src/chain/channelmonitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7107,7 +7107,9 @@ mod tests {
SecretKey::from_slice(&[41; 32]).unwrap(),
[41; 32],
[0; 32],
std::path::PathBuf::new(),
[0; 32],
None,
);

let counterparty_pubkeys = ChannelPublicKeys {
Expand Down Expand Up @@ -7370,7 +7372,9 @@ mod tests {
SecretKey::from_slice(&[41; 32]).unwrap(),
[41; 32],
[0; 32],
std::path::PathBuf::new(),
[0; 32],
None,
);

let counterparty_pubkeys = ChannelPublicKeys {
Expand Down
2 changes: 2 additions & 0 deletions lightning/src/chain/onchaintx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,9 @@ mod tests {
SecretKey::from_slice(&[41; 32]).unwrap(),
[41; 32],
[0; 32],
std::path::PathBuf::new(),
[0; 32],
None,
);
let counterparty_pubkeys = ChannelPublicKeys {
funding_pubkey: PublicKey::from_secret_key(
Expand Down
4 changes: 3 additions & 1 deletion lightning/src/ln/chan_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::ln::msgs::DecodeError;
use crate::rgb_utils::{color_htlc, is_tx_colored};
use crate::sign::EntropySource;
use crate::types::payment::{PaymentHash, PaymentPreimage};
use crate::util::persist::KVStoreSync;
use crate::util::ser::{Readable, ReadableArgs, RequiredWrapper, Writeable, Writer};
use crate::util::transaction_utils;

Expand Down Expand Up @@ -2156,6 +2157,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
pub fn get_htlc_sigs<T: secp256k1::Signing, ES: Deref>(
&self, htlc_base_key: &SecretKey, channel_parameters: &DirectedChannelTransactionParameters,
entropy_source: &ES, secp_ctx: &Secp256k1<T>, ldk_data_dir: &PathBuf,
rgb_kv_store: &dyn KVStoreSync,
) -> Result<Vec<Signature>, ()> where ES::Target: EntropySource {
let inner = self.inner;
let keys = &inner.keys;
Expand All @@ -2167,7 +2169,7 @@ impl<'a> TrustedCommitmentTransaction<'a> {
assert!(this_htlc.transaction_output_index.is_some());
let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &self.channel_type_features, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
if inner.is_colored() {
if let Err(_e) = color_htlc(&mut htlc_tx, this_htlc, ldk_data_dir) {
if let Err(_e) = color_htlc(&mut htlc_tx, this_htlc, ldk_data_dir, rgb_kv_store) {
return Err(());
}
}
Expand Down
66 changes: 37 additions & 29 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,8 @@ use crate::ln::types::ChannelId;
use crate::ln::LN_MAX_MSG_LEN;
use crate::offers::static_invoice::StaticInvoice;
use crate::rgb_utils::{
color_closing, color_commitment, color_htlc, get_rgb_channel_info_path,
get_rgb_channel_info_pending, parse_rgb_channel_info, rename_rgb_files,
update_rgb_channel_amount_pending,
color_closing, color_commitment, color_htlc, get_rgb_channel_info_pending,
read_rgb_channel_info, rename_rgb_files, update_rgb_channel_amount_pending,
};
use crate::routing::gossip::NodeId;
use crate::sign::ecdsa::EcdsaChannelSigner;
Expand All @@ -104,6 +103,8 @@ use crate::prelude::*;
use crate::sign::type_resolver::ChannelSignerType;
#[cfg(any(test, fuzzing, debug_assertions))]
use crate::sync::Mutex;
use crate::sync::Arc;
use crate::util::persist::KVStoreSync;
use core::ops::Deref;
use core::time::Duration;
use core::{cmp, fmt, mem};
Expand Down Expand Up @@ -3132,6 +3133,9 @@ where
pub(super) consignment_endpoint: Option<RgbTransport>,

pub(crate) ldk_data_dir: PathBuf,

/// Optional KVStore for RGB data persistence
pub(crate) rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
}

/// A channel struct implementing this trait can receive an initial counterparty commitment
Expand Down Expand Up @@ -3232,7 +3236,7 @@ where
let temporary_channel_id = context.channel_id;
context.channel_id = channel_id;
if context.is_colored() {
rename_rgb_files(&context.channel_id, &temporary_channel_id, &context.ldk_data_dir);
rename_rgb_files(&context.channel_id, &temporary_channel_id, context.rgb_kv_store.as_ref());
}

assert!(!context.channel_state.is_monitor_update_in_progress()); // We have not had any monitor(s) yet to fail update!
Expand Down Expand Up @@ -3401,6 +3405,7 @@ where
msg_push_msat: u64,
open_channel_fields: msgs::CommonOpenChannelFields,
ldk_data_dir: PathBuf,
rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
) -> Result<(FundingScope, ChannelContext<SP>), ChannelError>
where
ES::Target: EntropySource,
Expand Down Expand Up @@ -3723,6 +3728,7 @@ where

consignment_endpoint: open_channel_fields.consignment_endpoint,
ldk_data_dir,
rgb_kv_store,
};

Ok((funding, channel_context))
Expand All @@ -3748,6 +3754,7 @@ where
_logger: L,
consignment_endpoint: Option<RgbTransport>,
ldk_data_dir: PathBuf,
rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
) -> Result<(FundingScope, ChannelContext<SP>), APIError>
where
ES::Target: EntropySource,
Expand Down Expand Up @@ -3966,6 +3973,7 @@ where

consignment_endpoint,
ldk_data_dir,
rgb_kv_store,
};

Ok((funding, channel_context))
Expand Down Expand Up @@ -4344,13 +4352,8 @@ where

/// Get the channel local RGB amount
pub fn get_local_rgb_amount(&self) -> u64 {
let info_file_path = get_rgb_channel_info_path(
&self.channel_id.0.as_hex().to_string(),
&self.ldk_data_dir,
false,
);
if info_file_path.exists() {
let rgb_info = parse_rgb_channel_info(&info_file_path);
let channel_id_str = self.channel_id.0.as_hex().to_string();
if let Ok(rgb_info) = read_rgb_channel_info(self.rgb_kv_store.as_ref(), &channel_id_str, false) {
rgb_info.local_rgb_amount
} else {
0
Expand All @@ -4359,13 +4362,8 @@ where

/// Get the channel remote RGB amount
pub fn get_remote_rgb_amount(&self) -> u64 {
let info_file_path = get_rgb_channel_info_path(
&self.channel_id.0.as_hex().to_string(),
&self.ldk_data_dir,
false,
);
if info_file_path.exists() {
let rgb_info = parse_rgb_channel_info(&info_file_path);
let channel_id_str = self.channel_id.0.as_hex().to_string();
if let Ok(rgb_info) = read_rgb_channel_info(self.rgb_kv_store.as_ref(), &channel_id_str, false) {
rgb_info.remote_rgb_amount
} else {
0
Expand Down Expand Up @@ -5080,7 +5078,7 @@ where
&holder_keys.revocation_key,
);
if self.is_colored() {
color_htlc(&mut htlc_tx, htlc, &self.ldk_data_dir)
color_htlc(&mut htlc_tx, htlc, &self.ldk_data_dir, self.rgb_kv_store.as_ref())
.expect("successful htlc coloring");
}

Expand Down Expand Up @@ -7324,6 +7322,7 @@ where
&self.context.channel_id,
&mut closing_transaction,
&self.context.ldk_data_dir,
self.context.rgb_kv_store.as_ref(),
)
.expect("successful closing TX coloring");
}
Expand Down Expand Up @@ -8914,7 +8913,7 @@ where
&self.context.channel_id,
rgb_offered_htlc,
rgb_received_htlc,
&self.context.ldk_data_dir,
self.context.rgb_kv_store.as_ref(),
);
}

Expand Down Expand Up @@ -11729,7 +11728,7 @@ where
let were_node_one = node_id.as_slice() < counterparty_node_id.as_slice();

let contract_id = if self.context.is_colored() {
let (rgb_info, _) = get_rgb_channel_info_pending(&self.context.channel_id, &self.context.ldk_data_dir);
let rgb_info = get_rgb_channel_info_pending(&self.context.channel_id, self.context.rgb_kv_store.as_ref());
Some(rgb_info.contract_id)
} else {
None
Expand Down Expand Up @@ -12883,7 +12882,7 @@ where
}
}
if self.context.is_colored() && rgb_received_htlc > 0 {
update_rgb_channel_amount_pending(&self.context.channel_id, 0, rgb_received_htlc, &self.context.ldk_data_dir);
update_rgb_channel_amount_pending(&self.context.channel_id, 0, rgb_received_htlc, self.context.rgb_kv_store.as_ref());
}
if let Some((feerate, update_state)) = self.context.pending_update_fee {
if update_state == FeeUpdateState::AwaitingRemoteRevokeToAnnounce {
Expand Down Expand Up @@ -13550,6 +13549,7 @@ where
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP, counterparty_node_id: PublicKey, their_features: &InitFeatures,
channel_value_satoshis: u64, push_msat: u64, user_id: u128, config: &UserConfig, current_chain_height: u32,
outbound_scid_alias: u64, temporary_channel_id: Option<ChannelId>, logger: L, consignment_endpoint: Option<RgbTransport>, ldk_data_dir: PathBuf,
rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
) -> Result<OutboundV1Channel<SP>, APIError>
where ES::Target: EntropySource,
F::Target: FeeEstimator,
Expand Down Expand Up @@ -13589,6 +13589,7 @@ where
logger,
consignment_endpoint,
ldk_data_dir,
rgb_kv_store,
)?;
let unfunded_context = UnfundedChannelContext {
unfunded_channel_age_ticks: 0,
Expand Down Expand Up @@ -13672,7 +13673,7 @@ where
let temporary_channel_id = self.context.channel_id;
self.context.channel_id = ChannelId::v1_from_funding_outpoint(funding_txo);
if self.context.is_colored() {
rename_rgb_files(&self.context.channel_id, &temporary_channel_id, &self.context.ldk_data_dir);
rename_rgb_files(&self.context.channel_id, &temporary_channel_id, self.context.rgb_kv_store.as_ref());
}

// If the funding transaction is a coinbase transaction, we need to set the minimum depth to 100.
Expand Down Expand Up @@ -13925,7 +13926,8 @@ where
fee_estimator: &LowerBoundedFeeEstimator<F>, entropy_source: &ES, signer_provider: &SP,
counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
their_features: &InitFeatures, msg: &msgs::OpenChannel, user_id: u128, config: &UserConfig,
current_chain_height: u32, logger: &L, is_0conf: bool, ldk_data_dir: PathBuf
current_chain_height: u32, logger: &L, is_0conf: bool, ldk_data_dir: PathBuf,
rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
) -> Result<InboundV1Channel<SP>, ChannelError>
where ES::Target: EntropySource,
F::Target: FeeEstimator,
Expand Down Expand Up @@ -13966,6 +13968,7 @@ where
msg.push_msat,
msg.common_fields.clone(),
ldk_data_dir,
rgb_kv_store,
)?;
let unfunded_context = UnfundedChannelContext {
unfunded_channel_age_ticks: 0,
Expand Down Expand Up @@ -14166,7 +14169,7 @@ where
counterparty_node_id: PublicKey, their_features: &InitFeatures, funding_satoshis: u64,
funding_inputs: Vec<FundingTxInput>, user_id: u128, config: &UserConfig,
current_chain_height: u32, outbound_scid_alias: u64, funding_confirmation_target: ConfirmationTarget,
logger: L, ldk_data_dir: PathBuf,
logger: L, ldk_data_dir: PathBuf, rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
) -> Result<Self, APIError>
where ES::Target: EntropySource,
F::Target: FeeEstimator,
Expand Down Expand Up @@ -14209,6 +14212,7 @@ where
// ok to pass consignment_endpoint as None since this method is unused
None,
ldk_data_dir,
rgb_kv_store,
)?;
let unfunded_context = UnfundedChannelContext {
unfunded_channel_age_ticks: 0,
Expand Down Expand Up @@ -14319,7 +14323,7 @@ where
holder_node_id: PublicKey, counterparty_node_id: PublicKey, our_supported_features: &ChannelTypeFeatures,
their_features: &InitFeatures, msg: &msgs::OpenChannelV2,
user_id: u128, config: &UserConfig, current_chain_height: u32, logger: &L,
ldk_data_dir: PathBuf,
ldk_data_dir: PathBuf, rgb_kv_store: Arc<dyn KVStoreSync + Send + Sync>,
) -> Result<Self, ChannelError>
where ES::Target: EntropySource,
F::Target: FeeEstimator,
Expand Down Expand Up @@ -14365,6 +14369,7 @@ where
0 /* push_msat not used in dual-funding */,
msg.common_fields.clone(),
ldk_data_dir,
rgb_kv_store,
)?;
let channel_id = ChannelId::v2_from_revocation_basepoints(
&funding.get_holder_pubkeys().revocation_basepoint,
Expand Down Expand Up @@ -15054,16 +15059,16 @@ where
}
}

impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c ChannelTypeFeatures, PathBuf)>
impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, &'c ChannelTypeFeatures, PathBuf, Arc<dyn KVStoreSync + Send + Sync>)>
for FundedChannel<SP>
where
ES::Target: EntropySource,
SP::Target: SignerProvider,
{
fn read<R: io::Read>(
reader: &mut R, args: (&'a ES, &'b SP, &'c ChannelTypeFeatures, PathBuf),
reader: &mut R, args: (&'a ES, &'b SP, &'c ChannelTypeFeatures, PathBuf, Arc<dyn KVStoreSync + Send + Sync>),
) -> Result<Self, DecodeError> {
let (entropy_source, signer_provider, our_supported_features, ldk_data_dir) = args;
let (entropy_source, signer_provider, our_supported_features, ldk_data_dir, rgb_kv_store) = args;
let ver = read_ver_prefix!(reader, SERIALIZATION_VERSION);
if ver <= 2 {
return Err(DecodeError::UnknownVersion);
Expand Down Expand Up @@ -15859,6 +15864,7 @@ where

consignment_endpoint,
ldk_data_dir,
rgb_kv_store,
},
holder_commitment_point,
pending_splice,
Expand Down Expand Up @@ -16770,7 +16776,9 @@ mod tests {
// These aren't set in the test vectors:
[0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff],
[0; 32],
std::path::PathBuf::new(),
[0; 32],
None,
);

let holder_pubkeys = signer.pubkeys(&secp_ctx);
Expand Down
Loading