Skip to content

Commit 4bd1d4c

Browse files
committed
Merge 'Add back vanilla channels and support for swaps'
2 parents 50c4508 + bfef26e commit 4bd1d4c

15 files changed

+341
-120
lines changed

lightning/src/chain/channelmonitor.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ impl<Signer: WriteableEcdsaChannelSigner> Writeable for ChannelMonitorImpl<Signe
948948
writer.write_all(&$htlc_output.cltv_expiry.to_be_bytes())?;
949949
writer.write_all(&$htlc_output.payment_hash.0[..])?;
950950
$htlc_output.transaction_output_index.write(writer)?;
951-
writer.write_all(&$htlc_output.amount_rgb.to_be_bytes())?;
951+
$htlc_output.amount_rgb.write(writer)?;
952952
}
953953
}
954954

@@ -3853,7 +3853,7 @@ impl<'a, 'b, ES: EntropySource, SP: SignerProvider> ReadableArgs<(&'a ES, &'b SP
38533853
let cltv_expiry: u32 = Readable::read(reader)?;
38543854
let payment_hash: PaymentHash = Readable::read(reader)?;
38553855
let transaction_output_index: Option<u32> = Readable::read(reader)?;
3856-
let amount_rgb: u64 = Readable::read(reader)?;
3856+
let amount_rgb: Option<u64> = Readable::read(reader)?;
38573857

38583858
HTLCOutputInCommitment {
38593859
offered, amount_msat, cltv_expiry, payment_hash, transaction_output_index, amount_rgb

lightning/src/chain/keysinterface.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -824,9 +824,11 @@ impl EcdsaChannelSigner for InMemorySigner {
824824
for htlc in commitment_tx.htlcs() {
825825
let channel_parameters = self.get_channel_parameters();
826826
let mut htlc_tx = chan_utils::build_htlc_transaction(&commitment_txid, commitment_tx.feerate_per_kw(), self.holder_selected_contest_delay(), htlc, self.opt_anchors(), channel_parameters.opt_non_zero_fee_anchors.is_some(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
827-
match color_htlc(&mut htlc_tx, &htlc, &self.ldk_data_dir) {
828-
Err(_e) => return Err(()),
829-
_ => {}
827+
if commitment_tx.is_colored {
828+
match color_htlc(&mut htlc_tx, &htlc, &self.ldk_data_dir) {
829+
Err(_e) => return Err(()),
830+
_ => {}
831+
}
830832
}
831833
let htlc_redeemscript = chan_utils::get_htlc_redeemscript(&htlc, self.opt_anchors(), &keys);
832834
let htlc_sighashtype = if self.opt_anchors() { EcdsaSighashType::SinglePlusAnyoneCanPay } else { EcdsaSighashType::All };

lightning/src/events/mod.rs

+26-1
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,15 @@ pub enum Event {
624624
/// check that whatever fee you want has been included here or subtract it as required. Further,
625625
/// LDK will not stop you from forwarding more than you received.
626626
expected_outbound_amount_msat: u64,
627+
628+
/// Inbound assets, if any
629+
inbound_rgb_amount: Option<u64>,
630+
/// How much assets should be forwarded, if any
631+
expected_outbound_rgb_amount: Option<u64>,
632+
/// Whether the intercept is a swap
633+
is_swap: bool,
634+
/// Previous short channel id
635+
prev_short_channel_id: u64,
627636
},
628637
/// Used to indicate that an output which you should know how to spend was confirmed on chain
629638
/// and is now spendable.
@@ -903,7 +912,7 @@ impl Writeable for Event {
903912
(0, WithoutLength(outputs), required),
904913
});
905914
},
906-
&Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, intercept_id } => {
915+
&Event::HTLCIntercepted { requested_next_hop_scid, payment_hash, inbound_amount_msat, expected_outbound_amount_msat, inbound_rgb_amount, expected_outbound_rgb_amount, intercept_id, is_swap, prev_short_channel_id } => {
907916
6u8.write(writer)?;
908917
let intercept_scid = InterceptNextHop::FakeScid { requested_next_hop_scid };
909918
write_tlv_fields!(writer, {
@@ -912,6 +921,10 @@ impl Writeable for Event {
912921
(4, payment_hash, required),
913922
(6, inbound_amount_msat, required),
914923
(8, expected_outbound_amount_msat, required),
924+
(10, inbound_rgb_amount, option),
925+
(12, expected_outbound_rgb_amount, option),
926+
(14, is_swap, required),
927+
(16, prev_short_channel_id, required),
915928
});
916929
}
917930
&Event::PaymentForwarded {
@@ -1174,12 +1187,20 @@ impl MaybeReadable for Event {
11741187
let mut requested_next_hop_scid = InterceptNextHop::FakeScid { requested_next_hop_scid: 0 };
11751188
let mut inbound_amount_msat = 0;
11761189
let mut expected_outbound_amount_msat = 0;
1190+
let mut inbound_rgb_amount = None;
1191+
let mut expected_outbound_rgb_amount = None;
1192+
let mut is_swap = false;
1193+
let mut prev_short_channel_id = 0;
11771194
read_tlv_fields!(reader, {
11781195
(0, intercept_id, required),
11791196
(2, requested_next_hop_scid, required),
11801197
(4, payment_hash, required),
11811198
(6, inbound_amount_msat, required),
11821199
(8, expected_outbound_amount_msat, required),
1200+
(10, inbound_rgb_amount, option),
1201+
(12, expected_outbound_rgb_amount, option),
1202+
(14, is_swap, required),
1203+
(16, prev_short_channel_id, required),
11831204
});
11841205
let next_scid = match requested_next_hop_scid {
11851206
InterceptNextHop::FakeScid { requested_next_hop_scid: scid } => scid
@@ -1189,7 +1210,11 @@ impl MaybeReadable for Event {
11891210
requested_next_hop_scid: next_scid,
11901211
inbound_amount_msat,
11911212
expected_outbound_amount_msat,
1213+
inbound_rgb_amount,
1214+
expected_outbound_rgb_amount,
11921215
intercept_id,
1216+
is_swap,
1217+
prev_short_channel_id,
11931218
}))
11941219
},
11951220
7u8 => {

lightning/src/ln/chan_utils.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ pub struct HTLCOutputInCommitment {
566566
/// value is spent to additional transaction fees).
567567
pub transaction_output_index: Option<u32>,
568568
/// The RGB amount allocated to the HTLC
569-
pub amount_rgb: u64,
569+
pub amount_rgb: Option<u64>,
570570
}
571571

572572
impl_writeable_tlv_based!(HTLCOutputInCommitment, {
@@ -575,7 +575,7 @@ impl_writeable_tlv_based!(HTLCOutputInCommitment, {
575575
(4, cltv_expiry, required),
576576
(6, payment_hash, required),
577577
(8, transaction_output_index, option),
578-
(10, amount_rgb, required),
578+
(10, amount_rgb, option),
579579
});
580580

581581
#[inline]
@@ -1022,7 +1022,7 @@ impl HolderCommitmentTransaction {
10221022
for _ in 0..htlcs.len() {
10231023
counterparty_htlc_sigs.push(dummy_sig);
10241024
}
1025-
let inner = CommitmentTransaction::new_with_auxiliary_htlc_data(0, 0, 0, false, dummy_key.clone(), dummy_key.clone(), keys, 0, htlcs, &channel_parameters.as_counterparty_broadcastable());
1025+
let inner = CommitmentTransaction::new_with_auxiliary_htlc_data(0, 0, 0, false, dummy_key.clone(), dummy_key.clone(), keys, 0, htlcs, &channel_parameters.as_counterparty_broadcastable(), false);
10261026
htlcs.sort_by_key(|htlc| htlc.0.transaction_output_index);
10271027
HolderCommitmentTransaction {
10281028
inner,
@@ -1248,6 +1248,7 @@ pub struct CommitmentTransaction {
12481248
keys: TxCreationKeys,
12491249
// For access to the pre-built transaction, see doc for trust()
12501250
pub(crate) built: BuiltCommitmentTransaction,
1251+
pub(crate) is_colored: bool,
12511252
}
12521253

12531254
impl Eq for CommitmentTransaction {}
@@ -1278,6 +1279,7 @@ impl_writeable_tlv_based!(CommitmentTransaction, {
12781279
(12, htlcs, vec_type),
12791280
(14, opt_anchors, option),
12801281
(16, opt_non_zero_fee_anchors, option),
1282+
(18, is_colored, required),
12811283
});
12821284

12831285
impl CommitmentTransaction {
@@ -1291,7 +1293,7 @@ impl CommitmentTransaction {
12911293
/// Only include HTLCs that are above the dust limit for the channel.
12921294
///
12931295
/// This is not exported to bindings users due to the generic though we likely should expose a version without
1294-
pub fn new_with_auxiliary_htlc_data<T>(commitment_number: u64, to_broadcaster_value_sat: u64, to_countersignatory_value_sat: u64, opt_anchors: bool, broadcaster_funding_key: PublicKey, countersignatory_funding_key: PublicKey, keys: TxCreationKeys, feerate_per_kw: u32, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, channel_parameters: &DirectedChannelTransactionParameters) -> CommitmentTransaction {
1296+
pub fn new_with_auxiliary_htlc_data<T>(commitment_number: u64, to_broadcaster_value_sat: u64, to_countersignatory_value_sat: u64, opt_anchors: bool, broadcaster_funding_key: PublicKey, countersignatory_funding_key: PublicKey, keys: TxCreationKeys, feerate_per_kw: u32, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, channel_parameters: &DirectedChannelTransactionParameters, is_colored: bool) -> CommitmentTransaction {
12951297
// Sort outputs and populate output indices while keeping track of the auxiliary data
12961298
let (outputs, htlcs) = Self::internal_build_outputs(&keys, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters, opt_anchors, &broadcaster_funding_key, &countersignatory_funding_key).unwrap();
12971299

@@ -1311,6 +1313,7 @@ impl CommitmentTransaction {
13111313
txid
13121314
},
13131315
opt_non_zero_fee_anchors: None,
1316+
is_colored,
13141317
}
13151318
}
13161319

@@ -1590,9 +1593,11 @@ impl<'a> TrustedCommitmentTransaction<'a> {
15901593
for this_htlc in inner.htlcs.iter() {
15911594
assert!(this_htlc.transaction_output_index.is_some());
15921595
let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, self.opt_anchors(), self.opt_non_zero_fee_anchors.is_some(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
1593-
match color_htlc(&mut htlc_tx, &this_htlc, &ldk_data_dir) {
1594-
Err(_e) => return Err(()),
1595-
_ => {}
1596+
if inner.is_colored {
1597+
match color_htlc(&mut htlc_tx, &this_htlc, &ldk_data_dir) {
1598+
Err(_e) => return Err(()),
1599+
_ => {}
1600+
}
15961601
}
15971602

15981603
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, self.opt_anchors(), &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
@@ -1616,7 +1621,9 @@ impl<'a> TrustedCommitmentTransaction<'a> {
16161621
if this_htlc.offered && preimage.is_some() { unreachable!(); }
16171622

16181623
let mut htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, self.opt_anchors(), self.opt_non_zero_fee_anchors.is_some(), &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
1619-
color_htlc(&mut htlc_tx, &this_htlc, &ldk_data_dir).expect("successful htlc tx coloring");
1624+
if inner.is_colored {
1625+
color_htlc(&mut htlc_tx, &this_htlc, &ldk_data_dir).expect("successful htlc tx coloring");
1626+
}
16201627

16211628
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, self.opt_anchors(), &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
16221629

0 commit comments

Comments
 (0)