Skip to content

Commit 49ffdcf

Browse files
tankyleoTheBlueMatt
andcommitted
Set 0FC HolderHTLCOutput, HolderFundingOutput to require addl funds
Also set the malleability of 0FC `HolderHLTCOutput` to be the same as in CSV anchor channels. And add debug asserts from CSV anchor channels that also apply to P2A anchor channels. Co-authored-by: Matt Corallo <git@bluematt.me>
1 parent b2b2dfb commit 49ffdcf

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2715,6 +2715,7 @@ impl<Signer: EcdsaChannelSigner> ChannelMonitorImpl<Signer> {
27152715
} else {
27162716
let funding = get_confirmed_funding_scope!(self);
27172717
debug_assert!(!funding.channel_type_features().supports_anchors_zero_fee_htlc_tx());
2718+
debug_assert!(!funding.channel_type_features().supports_anchor_zero_fee_commitments());
27182719
BitcoinOutPoint::new(*txid, 0)
27192720
}
27202721
} else {

lightning/src/chain/package.rs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -750,11 +750,17 @@ impl PackageSolvingData {
750750
PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => outp.htlc.amount_msat / 1000,
751751
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => outp.htlc.amount_msat / 1000,
752752
PackageSolvingData::HolderHTLCOutput(ref outp) => {
753-
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
753+
let free_htlcs = outp.channel_type_features.supports_anchors_zero_fee_htlc_tx();
754+
let free_commitments =
755+
outp.channel_type_features.supports_anchor_zero_fee_commitments();
756+
debug_assert!(free_htlcs || free_commitments);
754757
outp.amount_msat / 1000
755758
},
756759
PackageSolvingData::HolderFundingOutput(ref outp) => {
757-
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
760+
let free_htlcs = outp.channel_type_features.supports_anchors_zero_fee_htlc_tx();
761+
let free_commitments =
762+
outp.channel_type_features.supports_anchor_zero_fee_commitments();
763+
debug_assert!(free_htlcs || free_commitments);
758764
outp.funding_amount_sats.unwrap()
759765
}
760766
};
@@ -768,7 +774,10 @@ impl PackageSolvingData {
768774
PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => weight_offered_htlc(&outp.channel_type_features) as usize,
769775
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => weight_received_htlc(&outp.channel_type_features) as usize,
770776
PackageSolvingData::HolderHTLCOutput(ref outp) => {
771-
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
777+
let free_htlcs = outp.channel_type_features.supports_anchors_zero_fee_htlc_tx();
778+
let free_commitments =
779+
outp.channel_type_features.supports_anchor_zero_fee_commitments();
780+
debug_assert!(free_htlcs || free_commitments);
772781
if outp.preimage.is_none() {
773782
weight_offered_htlc(&outp.channel_type_features) as usize
774783
} else {
@@ -988,6 +997,7 @@ impl PackageSolvingData {
988997
match self {
989998
PackageSolvingData::HolderHTLCOutput(ref outp) => {
990999
debug_assert!(!outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
1000+
debug_assert!(!outp.channel_type_features.supports_anchor_zero_fee_commitments());
9911001
outp.get_maybe_signed_htlc_tx(onchain_handler, outpoint)
9921002
}
9931003
PackageSolvingData::HolderFundingOutput(ref outp) => {
@@ -1040,14 +1050,20 @@ impl PackageSolvingData {
10401050
PackageMalleability::Malleable(AggregationCluster::Unpinnable),
10411051
PackageSolvingData::CounterpartyReceivedHTLCOutput(..) =>
10421052
PackageMalleability::Malleable(AggregationCluster::Pinnable),
1043-
PackageSolvingData::HolderHTLCOutput(ref outp) if outp.channel_type_features.supports_anchors_zero_fee_htlc_tx() => {
1044-
if outp.preimage.is_some() {
1045-
PackageMalleability::Malleable(AggregationCluster::Unpinnable)
1053+
PackageSolvingData::HolderHTLCOutput(ref outp) => {
1054+
let free_htlcs = outp.channel_type_features.supports_anchors_zero_fee_htlc_tx();
1055+
let free_commits = outp.channel_type_features.supports_anchor_zero_fee_commitments();
1056+
1057+
if free_htlcs || free_commits {
1058+
if outp.preimage.is_some() {
1059+
PackageMalleability::Malleable(AggregationCluster::Unpinnable)
1060+
} else {
1061+
PackageMalleability::Malleable(AggregationCluster::Pinnable)
1062+
}
10461063
} else {
1047-
PackageMalleability::Malleable(AggregationCluster::Pinnable)
1064+
PackageMalleability::Untractable
10481065
}
10491066
},
1050-
PackageSolvingData::HolderHTLCOutput(..) => PackageMalleability::Untractable,
10511067
PackageSolvingData::HolderFundingOutput(..) => PackageMalleability::Untractable,
10521068
}
10531069
}
@@ -1364,7 +1380,10 @@ impl PackageTemplate {
13641380
for (previous_output, input) in &self.inputs {
13651381
match input {
13661382
PackageSolvingData::HolderHTLCOutput(ref outp) => {
1367-
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
1383+
let free_htlcs = outp.channel_type_features.supports_anchors_zero_fee_htlc_tx();
1384+
let free_commitments =
1385+
outp.channel_type_features.supports_anchor_zero_fee_commitments();
1386+
debug_assert!(free_htlcs || free_commitments);
13681387
outp.get_htlc_descriptor(onchain_handler, &previous_output).map(|htlc| {
13691388
htlcs.get_or_insert_with(|| Vec::with_capacity(self.inputs.len())).push(htlc);
13701389
});
@@ -1559,8 +1578,14 @@ impl PackageTemplate {
15591578
#[rustfmt::skip]
15601579
pub(crate) fn requires_external_funding(&self) -> bool {
15611580
self.inputs.iter().find(|input| match input.1 {
1562-
PackageSolvingData::HolderFundingOutput(ref outp) => outp.channel_type_features.supports_anchors_zero_fee_htlc_tx(),
1563-
PackageSolvingData::HolderHTLCOutput(ref outp) => outp.channel_type_features.supports_anchors_zero_fee_htlc_tx(),
1581+
PackageSolvingData::HolderFundingOutput(ref outp) => {
1582+
outp.channel_type_features.supports_anchors_zero_fee_htlc_tx()
1583+
|| outp.channel_type_features.supports_anchor_zero_fee_commitments()
1584+
},
1585+
PackageSolvingData::HolderHTLCOutput(ref outp) => {
1586+
outp.channel_type_features.supports_anchors_zero_fee_htlc_tx()
1587+
|| outp.channel_type_features.supports_anchor_zero_fee_commitments()
1588+
},
15641589
_ => false,
15651590
}).is_some()
15661591
}

0 commit comments

Comments
 (0)