Skip to content

Commit d4b6b8b

Browse files
committed
Respond to comments.
1 parent 0821c74 commit d4b6b8b

File tree

5 files changed

+20
-27
lines changed

5 files changed

+20
-27
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4512,7 +4512,7 @@ mod tests {
45124512
}
45134513

45144514
// Justice tx with 1 revoked HTLC-Success tx output
4515-
for opt_anchors in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::static_remote_key_with_anchors()].iter() {
4515+
for channel_type_features in [ChannelTypeFeatures::only_static_remote_key(), ChannelTypeFeatures::static_remote_key_with_anchors()].iter() {
45164516
let mut claim_tx = Transaction { version: 0, lock_time: PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
45174517
let mut sum_actual_sigs = 0;
45184518
claim_tx.input.push(TxIn {
@@ -4534,7 +4534,7 @@ mod tests {
45344534
{
45354535
let mut sighash_parts = sighash::SighashCache::new(&mut claim_tx);
45364536
for (idx, inp) in inputs_weight.iter().enumerate() {
4537-
sign_input!(sighash_parts, idx, 0, inp, sum_actual_sigs, opt_anchors);
4537+
sign_input!(sighash_parts, idx, 0, inp, sum_actual_sigs, channel_type_features);
45384538
inputs_total_weight += inp;
45394539
}
45404540
}

lightning/src/chain/package.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,7 @@ impl CounterpartyOfferedHTLCOutput {
203203

204204
impl Writeable for CounterpartyOfferedHTLCOutput {
205205
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
206-
let mut channel_type_features = Some(self.channel_type_features.clone());
207-
if !self.channel_type_features.supports_anchors() {
208-
channel_type_features = None;
209-
}
206+
let channel_type_features = self.channel_type_features.serializable_option();
210207
write_tlv_fields!(writer, {
211208
(0, self.per_commitment_point, required),
212209
(2, self.counterparty_delayed_payment_base_key, required),
@@ -275,10 +272,7 @@ impl CounterpartyReceivedHTLCOutput {
275272

276273
impl Writeable for CounterpartyReceivedHTLCOutput {
277274
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
278-
let mut channel_type_features = Some(self.channel_type_features.clone());
279-
if !self.channel_type_features.supports_anchors() {
280-
channel_type_features = None;
281-
}
275+
let channel_type_features = self.channel_type_features.serializable_option();
282276
write_tlv_fields!(writer, {
283277
(0, self.per_commitment_point, required),
284278
(2, self.counterparty_delayed_payment_base_key, required),
@@ -351,10 +345,7 @@ impl HolderHTLCOutput {
351345

352346
impl Writeable for HolderHTLCOutput {
353347
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
354-
let mut channel_type_features = Some(self.channel_type_features.clone());
355-
if !self.channel_type_features.supports_anchors() {
356-
channel_type_features = None;
357-
}
348+
let channel_type_features = self.channel_type_features.serializable_option();
358349
write_tlv_fields!(writer, {
359350
(0, self.amount_msat, required),
360351
(2, self.cltv_expiry, required),
@@ -411,10 +402,7 @@ impl HolderFundingOutput {
411402

412403
impl Writeable for HolderFundingOutput {
413404
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
414-
let mut channel_type_features = Some(self.channel_type_features.clone());
415-
if !self.channel_type_features.supports_anchors() {
416-
channel_type_features = None;
417-
}
405+
let channel_type_features = self.channel_type_features.serializable_option();
418406
write_tlv_fields!(writer, {
419407
(0, self.funding_redeemscript, required),
420408
(2, channel_type_features, option),

lightning/src/ln/chan_utils.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -878,10 +878,7 @@ impl_writeable_tlv_based!(CounterpartyChannelTransactionParameters, {
878878

879879
impl Writeable for ChannelTransactionParameters {
880880
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
881-
let mut channel_type_features = Some(self.channel_type_features.clone());
882-
if !self.channel_type_features.supports_anchors() {
883-
channel_type_features = None;
884-
}
881+
let channel_type_features = self.channel_type_features.serializable_option();
885882
write_tlv_fields!(writer, {
886883
(0, self.holder_pubkeys, required),
887884
(2, self.holder_selected_contest_delay, required),
@@ -1295,10 +1292,7 @@ impl PartialEq for CommitmentTransaction {
12951292

12961293
impl Writeable for CommitmentTransaction {
12971294
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
1298-
let mut channel_type_features = Some(self.channel_type_features.clone());
1299-
if !self.channel_type_features.supports_anchors() {
1300-
channel_type_features = None;
1301-
}
1295+
let channel_type_features = self.channel_type_features.serializable_option();
13021296
write_tlv_fields!(writer, {
13031297
(0, self.commitment_number, required),
13041298
(2, self.to_broadcaster_value_sat, required),

lightning/src/ln/features.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,16 @@ impl ChannelTypeFeatures {
631631
Self::only_static_remote_key()
632632
}
633633
}
634+
635+
/// To actually serialize the features in a manner that won't break the structs read by
636+
/// older versions of LDK, we should skip serialization entirely if anchors are not supported.
637+
/// This is a helper method to do just that.
638+
pub(crate) fn serializable_option(&self) -> Option<Self> {
639+
if !self.supports_anchors() {
640+
return None;
641+
}
642+
Some(self.clone())
643+
}
634644
}
635645

636646
impl ToBase32 for InvoiceFeatures {

lightning/src/sign/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,8 @@ impl InMemorySigner {
835835
pub fn get_channel_parameters(&self) -> &ChannelTransactionParameters {
836836
self.channel_parameters.as_ref().unwrap()
837837
}
838-
/// Returns whether anchors should be used.
838+
/// Returns the channel type features of the channel parameters. Should be helpful to for
839+
/// determining a channel's category, i. e. legacy/anchors/taproot/etc.
839840
///
840841
/// Will panic if [`ChannelSigner::provide_channel_parameters`] has not been called before.
841842
pub fn channel_type_features(&self) -> ChannelTypeFeatures {

0 commit comments

Comments
 (0)