Skip to content
Merged
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
2 changes: 1 addition & 1 deletion lightning-invoice/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ serde = { version = "1.0", optional = true, default-features = false, features =
bitcoin = { version = "0.32.2", default-features = false, features = ["secp-recovery"] }

# RGB and related
rgb-lib = { version = "=0.3.0-beta.6", features = [
rgb-lib = { version = "=0.3.0-beta.7", features = [
"electrum",
"esplora",
] }
Expand Down
2 changes: 1 addition & 1 deletion lightning/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ inventory = { version = "0.3", optional = true }

# RGB and related
futures = "0.3"
rgb-lib = { version = "=0.3.0-beta.6", features = [
rgb-lib = { version = "=0.3.0-beta.7", features = [
"electrum",
"esplora",
] }
Expand Down
104 changes: 56 additions & 48 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use bitcoin::secp256k1::{ecdsa::Signature, Secp256k1};
use bitcoin::secp256k1::{PublicKey, SecretKey};
use bitcoin::{secp256k1, sighash, FeeRate, Sequence, TxIn};

use rgb_lib::{ContractId, RgbTransport};
use rgb_lib::ContractId;

use crate::blinded_path::message::BlindedMessagePath;
use crate::chain::chaininterface::{
Expand Down Expand Up @@ -79,8 +79,8 @@ 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,
get_rgb_channel_info_pending, is_asset_known, parse_rgb_channel_info, rename_rgb_files,
set_counterparty_knows_asset, update_rgb_channel_amount_pending,
};
use crate::routing::gossip::NodeId;
use crate::sign::ecdsa::EcdsaChannelSigner;
Expand Down Expand Up @@ -2358,11 +2358,9 @@ pub(crate) struct FundingScope {
/// [`ChannelContext::minimum_depth`].
minimum_depth_override: Option<u32>,

/// The consignment endpoint used to exchange the RGB consignment.
pub(super) consignment_endpoint: Option<RgbTransport>,

/// The RGB asset amount to push to the counterparty on channel open.
pub(super) push_asset_amount: Option<u64>,
/// The RGB asset this channel is for, if it is a colored channel: the contract ID of the asset
/// plus the amount of it pushed to the counterparty on channel open, if any.
pub(super) rgb_asset: Option<(ContractId, Option<u64>)>,
}

impl Writeable for FundingScope {
Expand All @@ -2377,8 +2375,7 @@ impl Writeable for FundingScope {
(13, self.funding_tx_confirmation_height, required),
(15, self.short_channel_id, option),
(17, self.minimum_depth_override, option),
(19, self.consignment_endpoint, option),
(21, self.push_asset_amount, option),
(21, self.rgb_asset, option),
});
Ok(())
}
Expand All @@ -2396,8 +2393,7 @@ impl Readable for FundingScope {
let mut funding_tx_confirmation_height = RequiredWrapper(None);
let mut short_channel_id = None;
let mut minimum_depth_override = None;
let mut consignment_endpoint = None;
let mut push_asset_amount = None;
let mut rgb_asset: Option<(ContractId, Option<u64>)> = None;

read_tlv_fields!(reader, {
(1, value_to_self_msat, required),
Expand All @@ -2409,8 +2405,7 @@ impl Readable for FundingScope {
(13, funding_tx_confirmation_height, required),
(15, short_channel_id, option),
(17, minimum_depth_override, option),
(19, consignment_endpoint, option),
(21, push_asset_amount, option),
(21, rgb_asset, option),
});

Ok(Self {
Expand All @@ -2427,8 +2422,7 @@ impl Readable for FundingScope {
funding_tx_confirmation_height: funding_tx_confirmation_height.0.unwrap(),
short_channel_id,
minimum_depth_override,
consignment_endpoint,
push_asset_amount,
rgb_asset,
#[cfg(any(test, fuzzing))]
next_local_fee: Mutex::new(PredictedNextFee::default()),
#[cfg(any(test, fuzzing))]
Expand All @@ -2446,6 +2440,21 @@ impl FundingScope {
self.value_to_self_msat
}

/// Whether this is an RGB (colored) channel.
pub(crate) fn is_colored(&self) -> bool {
self.rgb_asset.is_some()
}

/// The RGB contract ID of the asset this channel is for, if it is a colored channel.
pub(crate) fn contract_id(&self) -> Option<ContractId> {
self.rgb_asset.map(|(contract_id, _)| contract_id)
}

/// The RGB asset amount pushed to the counterparty on channel open, if any.
pub(crate) fn push_asset_amount(&self) -> Option<u64> {
self.rgb_asset.and_then(|(_, push_asset_amount)| push_asset_amount)
}

pub fn get_holder_counterparty_selected_channel_reserve_satoshis(&self) -> (u64, Option<u64>) {
(
self.holder_selected_channel_reserve_satoshis,
Expand Down Expand Up @@ -2616,8 +2625,7 @@ impl FundingScope {
funding_tx_confirmed_in: None,
minimum_depth_override: None,
short_channel_id: None,
consignment_endpoint: None,
push_asset_amount: None,
rgb_asset: None,
}
}

Expand Down Expand Up @@ -3415,7 +3423,7 @@ where
msg_channel_reserve_satoshis: u64,
msg_push_msat: u64,
open_channel_fields: msgs::CommonOpenChannelFields,
push_asset_amount: Option<u64>,
rgb_asset: Option<(ContractId, Option<u64>)>,
ldk_data_dir: PathBuf,
) -> Result<(FundingScope, ChannelContext<SP>), ChannelError>
where
Expand Down Expand Up @@ -3624,8 +3632,7 @@ where
funding_tx_confirmation_height: 0,
short_channel_id: None,
minimum_depth_override: None,
consignment_endpoint: open_channel_fields.consignment_endpoint.clone(),
push_asset_amount,
rgb_asset,
};
let channel_context = ChannelContext {
user_id,
Expand Down Expand Up @@ -3739,7 +3746,7 @@ where

interactive_tx_signing_session: None,

is_colored: funding.consignment_endpoint.is_some(),
is_colored: funding.is_colored(),
ldk_data_dir,
};

Expand All @@ -3764,9 +3771,8 @@ where
channel_keys_id: [u8; 32],
holder_signer: <SP::Target as SignerProvider>::EcdsaSigner,
_logger: L,
consignment_endpoint: Option<RgbTransport>,
rgb_asset: Option<(ContractId, Option<u64>)>,
ldk_data_dir: PathBuf,
push_asset_amount: Option<u64>,
) -> Result<(FundingScope, ChannelContext<SP>), APIError>
where
ES::Target: EntropySource,
Expand Down Expand Up @@ -3872,8 +3878,7 @@ where
funding_tx_confirmation_height: 0,
short_channel_id: None,
minimum_depth_override: None,
consignment_endpoint: consignment_endpoint.clone(),
push_asset_amount,
rgb_asset,
};
let channel_context = Self {
user_id,
Expand Down Expand Up @@ -3985,7 +3990,7 @@ where

interactive_tx_signing_session: None,

is_colored: funding.consignment_endpoint.is_some(),
is_colored: funding.is_colored(),
ldk_data_dir,
};

Expand Down Expand Up @@ -13578,7 +13583,7 @@ where
pub fn new<ES: Deref, F: Deref, L: Deref>(
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, push_asset_amount: Option<u64>,
outbound_scid_alias: u64, temporary_channel_id: Option<ChannelId>, logger: L, rgb_asset: Option<(ContractId, Option<u64>)>, ldk_data_dir: PathBuf,
) -> Result<OutboundV1Channel<SP>, APIError>
where ES::Target: EntropySource,
F::Target: FeeEstimator,
Expand Down Expand Up @@ -13616,9 +13621,8 @@ where
channel_keys_id,
holder_signer,
logger,
consignment_endpoint,
rgb_asset,
ldk_data_dir,
push_asset_amount,
)?;
let unfunded_context = UnfundedChannelContext {
unfunded_channel_age_ticks: 0,
Expand Down Expand Up @@ -13796,11 +13800,10 @@ where
None => Builder::new().into_script(),
}),
channel_type: Some(self.funding.get_channel_type().clone()),
consignment_endpoint: self.funding.consignment_endpoint.clone(),
},
push_msat: self.funding.get_value_satoshis() * 1000 - self.funding.value_to_self_msat,
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
push_asset_amount: self.funding.push_asset_amount,
rgb_asset: self.funding.rgb_asset,
})
}

Expand All @@ -13815,7 +13818,13 @@ where
their_features,
&msg.common_fields,
msg.channel_reserve_satoshis,
)
)?;

if self.funding.is_colored() && msg.known_asset {
set_counterparty_knows_asset(&self.context.channel_id, &self.context.ldk_data_dir);
}

Ok(())
}

/// Handles a funding_signed message from the remote end.
Expand Down Expand Up @@ -13996,7 +14005,7 @@ where
msg.channel_reserve_satoshis,
msg.push_msat,
msg.common_fields.clone(),
msg.push_asset_amount,
msg.rgb_asset,
ldk_data_dir,
)?;
let unfunded_context = UnfundedChannelContext {
Expand Down Expand Up @@ -14053,6 +14062,11 @@ where
};
let keys = self.funding.get_holder_pubkeys();

let known_asset = match self.funding.contract_id() {
Some(contract_id) => is_asset_known(contract_id, &self.context.ldk_data_dir),
None => false,
};

Some(msgs::AcceptChannel {
common_fields: msgs::CommonAcceptChannelFields {
temporary_channel_id: self.context.channel_id,
Expand All @@ -14075,6 +14089,7 @@ where
channel_type: Some(self.funding.get_channel_type().clone()),
},
channel_reserve_satoshis: self.funding.holder_selected_channel_reserve_satoshis,
known_asset,
#[cfg(taproot)]
next_local_nonce: None,
})
Expand Down Expand Up @@ -14238,10 +14253,9 @@ where
channel_keys_id,
holder_signer,
logger,
// ok to pass consignment_endpoint as None since this method is unused
// ok to pass rgb_asset as None since this method is unused
None,
ldk_data_dir,
None,
)?;
let unfunded_context = UnfundedChannelContext {
unfunded_channel_age_ticks: 0,
Expand Down Expand Up @@ -14333,7 +14347,6 @@ where
None => Builder::new().into_script(),
}),
channel_type: Some(self.funding.get_channel_type().clone()),
consignment_endpoint: self.funding.consignment_endpoint.clone(),
},
funding_feerate_sat_per_1000_weight: self.context.feerate_per_kw,
second_per_commitment_point,
Expand Down Expand Up @@ -15081,8 +15094,7 @@ where
(65, self.quiescent_action, option), // Added in 0.2
(67, pending_outbound_held_htlc_flags, optional_vec), // Added in 0.2
(69, holding_cell_held_htlc_flags, optional_vec), // Added in 0.2
(71, self.funding.consignment_endpoint, option),
(73, self.funding.push_asset_amount, option),
(73, self.funding.rgb_asset, option),
});

Ok(())
Expand Down Expand Up @@ -15418,8 +15430,7 @@ where
let mut channel_keys_id = [0u8; 32];
let mut temporary_channel_id: Option<ChannelId> = None;
let mut holder_max_accepted_htlcs: Option<u16> = None;
let mut consignment_endpoint: Option<RgbTransport> = None;
let mut push_asset_amount: Option<u64> = None;
let mut rgb_asset: Option<(ContractId, Option<u64>)> = None;

let mut blocked_monitor_updates = Some(Vec::new());

Expand Down Expand Up @@ -15502,8 +15513,7 @@ where
(65, quiescent_action, upgradable_option), // Added in 0.2
(67, pending_outbound_held_htlc_flags_opt, optional_vec), // Added in 0.2
(69, holding_cell_held_htlc_flags_opt, optional_vec), // Added in 0.2
(71, consignment_endpoint, option),
(73, push_asset_amount, option),
(73, rgb_asset, option),
});

let holder_signer = signer_provider.derive_channel_signer(channel_keys_id);
Expand Down Expand Up @@ -15782,8 +15792,7 @@ where
funding_tx_confirmation_height,
short_channel_id,
minimum_depth_override,
consignment_endpoint: consignment_endpoint.clone(),
push_asset_amount,
rgb_asset,
},
context: ChannelContext {
user_id,
Expand Down Expand Up @@ -15895,7 +15904,7 @@ where
is_manual_broadcast: is_manual_broadcast.unwrap_or(false),

interactive_tx_signing_session,
is_colored: consignment_endpoint.is_some(),
is_colored: rgb_asset.is_some(),
ldk_data_dir,
},
holder_commitment_point,
Expand Down Expand Up @@ -17886,8 +17895,7 @@ mod tests {
funding_tx_confirmation_height: 0,
short_channel_id: None,
minimum_depth_override: None,
consignment_endpoint: None,
push_asset_amount: None,
rgb_asset: None,
};
let post_channel_value =
funding.compute_post_splice_value(our_funding_contribution, their_funding_contribution);
Expand Down
10 changes: 5 additions & 5 deletions lightning/src/ln/channelmanager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use bitcoin::secp256k1::Secp256k1;
use bitcoin::secp256k1::{PublicKey, SecretKey};
use bitcoin::{secp256k1, Sequence, SignedAmount};

use rgb_lib::{ContractId, RgbTransport};
use rgb_lib::ContractId;

use crate::blinded_path::message::{
AsyncPaymentsContext, BlindedMessagePath, MessageForwardNode, OffersContext,
Expand Down Expand Up @@ -4144,7 +4144,7 @@ where
/// [`Event::FundingGenerationReady::temporary_channel_id`]: events::Event::FundingGenerationReady::temporary_channel_id
/// [`Event::ChannelClosed::channel_id`]: events::Event::ChannelClosed::channel_id
#[rustfmt::skip]
pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_channel_id: u128, temporary_channel_id: Option<ChannelId>, override_config: Option<UserConfig>, consignment_endpoint: Option<RgbTransport>, push_asset_amount: Option<u64>) -> Result<ChannelId, APIError> {
pub fn create_channel(&self, their_network_key: PublicKey, channel_value_satoshis: u64, push_msat: u64, user_channel_id: u128, temporary_channel_id: Option<ChannelId>, override_config: Option<UserConfig>, rgb_asset: Option<(ContractId, Option<u64>)>) -> Result<ChannelId, APIError> {
if channel_value_satoshis < 1000 {
return Err(APIError::APIMisuseError { err: format!("Channel value must be at least 1000 satoshis. It was {}", channel_value_satoshis) });
}
Expand Down Expand Up @@ -4180,7 +4180,7 @@ where
};
match OutboundV1Channel::new(&self.fee_estimator, &self.entropy_source, &self.signer_provider, their_network_key,
their_features, channel_value_satoshis, push_msat, user_channel_id, config,
self.best_block.read().unwrap().height, outbound_scid_alias, temporary_channel_id, &*self.logger, consignment_endpoint, self.ldk_data_dir.clone(), push_asset_amount)
self.best_block.read().unwrap().height, outbound_scid_alias, temporary_channel_id, &*self.logger, rgb_asset, self.ldk_data_dir.clone())
{
Ok(res) => res,
Err(e) => {
Expand Down Expand Up @@ -10463,8 +10463,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
{
Some(Ok(inbound_chan)) => {
let logger = WithChannelContext::from(&self.logger, &inbound_chan.context, None);
if let Some(consignment_endpoint) = &inbound_chan.funding.consignment_endpoint {
match handle_funding(&msg.temporary_channel_id, msg.funding_txid.to_string(), &self.ldk_data_dir, consignment_endpoint.clone(), inbound_chan.funding.push_asset_amount) {
if inbound_chan.funding.is_colored() {
match handle_funding(&msg.temporary_channel_id, msg.funding_txid.to_string(), &self.ldk_data_dir, inbound_chan.funding.push_asset_amount()) {
Ok(()) => (),
Err(e) => {
// at this point the channel initiator already transitioned its channel to the funded channel ID
Expand Down
Loading
Loading