Skip to content

Commit dc85603

Browse files
committed
Use .supports_anchors_zero_fee_htlc_tx instead of .supports_anchors everywhere but features.rs
1 parent a602822 commit dc85603

File tree

6 files changed

+44
-44
lines changed

6 files changed

+44
-44
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1600,7 +1600,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
16001600
debug_assert!(htlc_input_idx_opt.is_some());
16011601
BitcoinOutPoint::new(*txid, htlc_input_idx_opt.unwrap_or(0))
16021602
} else {
1603-
debug_assert!(!self.onchain_tx_handler.channel_type_features().supports_anchors());
1603+
debug_assert!(!self.onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx());
16041604
BitcoinOutPoint::new(*txid, 0)
16051605
}
16061606
} else {
@@ -2459,7 +2459,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
24592459
// If the channel supports anchor outputs, we'll need to emit an external
24602460
// event to be consumed such that a child transaction is broadcast with a
24612461
// high enough feerate for the parent commitment transaction to confirm.
2462-
if self.onchain_tx_handler.channel_type_features().supports_anchors() {
2462+
if self.onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
24632463
let funding_output = HolderFundingOutput::build(
24642464
self.funding_redeemscript.clone(), self.channel_value_satoshis,
24652465
self.onchain_tx_handler.channel_type_features(),
@@ -2651,7 +2651,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
26512651
// First, process non-htlc outputs (to_holder & to_counterparty)
26522652
for (idx, outp) in tx.output.iter().enumerate() {
26532653
if outp.script_pubkey == revokeable_p2wsh {
2654-
let revk_outp = RevokedOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, outp.value, self.counterparty_commitment_params.on_counterparty_tx_csv, self.onchain_tx_handler.channel_type_features().supports_anchors());
2654+
let revk_outp = RevokedOutput::build(per_commitment_point, self.counterparty_commitment_params.counterparty_delayed_payment_base_key, self.counterparty_commitment_params.counterparty_htlc_base_key, per_commitment_key, outp.value, self.counterparty_commitment_params.on_counterparty_tx_csv, self.onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx());
26552655
let justice_package = PackageTemplate::build_package(commitment_txid, idx as u32, PackageSolvingData::RevokedOutput(revk_outp), height + self.counterparty_commitment_params.on_counterparty_tx_csv as u32, height);
26562656
claimable_outpoints.push(justice_package);
26572657
to_counterparty_output_info =
@@ -2959,7 +2959,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29592959
let mut holder_transactions = vec![commitment_tx];
29602960
// When anchor outputs are present, the HTLC transactions are only valid once the commitment
29612961
// transaction confirms.
2962-
if self.onchain_tx_handler.channel_type_features().supports_anchors() {
2962+
if self.onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
29632963
return holder_transactions;
29642964
}
29652965
for htlc in self.current_holder_commitment_tx.htlc_outputs.iter() {
@@ -2997,7 +2997,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
29972997
let mut holder_transactions = vec![commitment_tx];
29982998
// When anchor outputs are present, the HTLC transactions are only final once the commitment
29992999
// transaction confirms due to the CSV 1 encumberance.
3000-
if self.onchain_tx_handler.channel_type_features().supports_anchors() {
3000+
if self.onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
30013001
return holder_transactions;
30023002
}
30033003
for htlc in self.current_holder_commitment_tx.htlc_outputs.iter() {
@@ -3230,7 +3230,7 @@ impl<Signer: WriteableEcdsaChannelSigner> ChannelMonitorImpl<Signer> {
32303230
// We can't broadcast our HTLC transactions while the commitment transaction is
32313231
// unconfirmed. We'll delay doing so until we detect the confirmed commitment in
32323232
// `transactions_confirmed`.
3233-
if !self.onchain_tx_handler.channel_type_features().supports_anchors() {
3233+
if !self.onchain_tx_handler.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
32343234
// Because we're broadcasting a commitment transaction, we should construct the package
32353235
// assuming it gets confirmed in the next block. Sadly, we have code which considers
32363236
// "not yet confirmed" things as discardable, so we cannot do that here.

lightning/src/chain/package.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,28 @@ pub(crate) fn weight_revoked_offered_htlc(channel_type_features: &ChannelTypeFea
5151
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
5252
const WEIGHT_REVOKED_OFFERED_HTLC: u64 = 1 + 1 + 73 + 1 + 33 + 1 + 133;
5353
const WEIGHT_REVOKED_OFFERED_HTLC_ANCHORS: u64 = WEIGHT_REVOKED_OFFERED_HTLC + 3; // + OP_1 + OP_CSV + OP_DROP
54-
if channel_type_features.supports_anchors() { WEIGHT_REVOKED_OFFERED_HTLC_ANCHORS } else { WEIGHT_REVOKED_OFFERED_HTLC }
54+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { WEIGHT_REVOKED_OFFERED_HTLC_ANCHORS } else { WEIGHT_REVOKED_OFFERED_HTLC }
5555
}
5656

5757
pub(crate) fn weight_revoked_received_htlc(channel_type_features: &ChannelTypeFeatures) -> u64 {
5858
// number_of_witness_elements + sig_length + revocation_sig + pubkey_length + revocationpubkey + witness_script_length + witness_script
5959
const WEIGHT_REVOKED_RECEIVED_HTLC: u64 = 1 + 1 + 73 + 1 + 33 + 1 + 139;
6060
const WEIGHT_REVOKED_RECEIVED_HTLC_ANCHORS: u64 = WEIGHT_REVOKED_RECEIVED_HTLC + 3; // + OP_1 + OP_CSV + OP_DROP
61-
if channel_type_features.supports_anchors() { WEIGHT_REVOKED_RECEIVED_HTLC_ANCHORS } else { WEIGHT_REVOKED_RECEIVED_HTLC }
61+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { WEIGHT_REVOKED_RECEIVED_HTLC_ANCHORS } else { WEIGHT_REVOKED_RECEIVED_HTLC }
6262
}
6363

6464
pub(crate) fn weight_offered_htlc(channel_type_features: &ChannelTypeFeatures) -> u64 {
6565
// number_of_witness_elements + sig_length + counterpartyhtlc_sig + preimage_length + preimage + witness_script_length + witness_script
6666
const WEIGHT_OFFERED_HTLC: u64 = 1 + 1 + 73 + 1 + 32 + 1 + 133;
6767
const WEIGHT_OFFERED_HTLC_ANCHORS: u64 = WEIGHT_OFFERED_HTLC + 3; // + OP_1 + OP_CSV + OP_DROP
68-
if channel_type_features.supports_anchors() { WEIGHT_OFFERED_HTLC_ANCHORS } else { WEIGHT_OFFERED_HTLC }
68+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { WEIGHT_OFFERED_HTLC_ANCHORS } else { WEIGHT_OFFERED_HTLC }
6969
}
7070

7171
pub(crate) fn weight_received_htlc(channel_type_features: &ChannelTypeFeatures) -> u64 {
7272
// number_of_witness_elements + sig_length + counterpartyhtlc_sig + empty_vec_length + empty_vec + witness_script_length + witness_script
7373
const WEIGHT_RECEIVED_HTLC: u64 = 1 + 1 + 73 + 1 + 1 + 1 + 139;
7474
const WEIGHT_RECEIVED_HTLC_ANCHORS: u64 = WEIGHT_RECEIVED_HTLC + 3; // + OP_1 + OP_CSV + OP_DROP
75-
if channel_type_features.supports_anchors() { WEIGHT_RECEIVED_HTLC_ANCHORS } else { WEIGHT_RECEIVED_HTLC }
75+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { WEIGHT_RECEIVED_HTLC_ANCHORS } else { WEIGHT_RECEIVED_HTLC }
7676
}
7777

7878
// number_of_witness_elements + sig_length + revocation_sig + true_length + op_true + witness_script_length + witness_script
@@ -454,11 +454,11 @@ impl PackageSolvingData {
454454
PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => outp.htlc.amount_msat / 1000,
455455
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => outp.htlc.amount_msat / 1000,
456456
PackageSolvingData::HolderHTLCOutput(ref outp) => {
457-
debug_assert!(outp.channel_type_features.supports_anchors());
457+
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
458458
outp.amount_msat / 1000
459459
},
460460
PackageSolvingData::HolderFundingOutput(ref outp) => {
461-
debug_assert!(outp.channel_type_features.supports_anchors());
461+
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
462462
outp.funding_amount.unwrap()
463463
}
464464
};
@@ -471,7 +471,7 @@ impl PackageSolvingData {
471471
PackageSolvingData::CounterpartyOfferedHTLCOutput(ref outp) => weight_offered_htlc(&outp.channel_type_features) as usize,
472472
PackageSolvingData::CounterpartyReceivedHTLCOutput(ref outp) => weight_received_htlc(&outp.channel_type_features) as usize,
473473
PackageSolvingData::HolderHTLCOutput(ref outp) => {
474-
debug_assert!(outp.channel_type_features.supports_anchors());
474+
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
475475
if outp.preimage.is_none() {
476476
weight_offered_htlc(&outp.channel_type_features) as usize
477477
} else {
@@ -560,7 +560,7 @@ impl PackageSolvingData {
560560
fn get_finalized_tx<Signer: WriteableEcdsaChannelSigner>(&self, outpoint: &BitcoinOutPoint, onchain_handler: &mut OnchainTxHandler<Signer>) -> Option<Transaction> {
561561
match self {
562562
PackageSolvingData::HolderHTLCOutput(ref outp) => {
563-
debug_assert!(!outp.channel_type_features.supports_anchors());
563+
debug_assert!(!outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
564564
return onchain_handler.get_fully_signed_htlc_tx(outpoint, &outp.preimage);
565565
}
566566
PackageSolvingData::HolderFundingOutput(ref outp) => {
@@ -598,7 +598,7 @@ impl PackageSolvingData {
598598
PackageSolvingData::RevokedHTLCOutput(..) => { (PackageMalleability::Malleable, true) },
599599
PackageSolvingData::CounterpartyOfferedHTLCOutput(..) => { (PackageMalleability::Malleable, true) },
600600
PackageSolvingData::CounterpartyReceivedHTLCOutput(..) => { (PackageMalleability::Malleable, false) },
601-
PackageSolvingData::HolderHTLCOutput(ref outp) => if outp.channel_type_features.supports_anchors() {
601+
PackageSolvingData::HolderHTLCOutput(ref outp) => if outp.channel_type_features.supports_anchors_zero_fee_htlc_tx() {
602602
(PackageMalleability::Malleable, outp.preimage.is_some())
603603
} else {
604604
(PackageMalleability::Untractable, false)
@@ -823,7 +823,7 @@ impl PackageTemplate {
823823
for (previous_output, input) in &self.inputs {
824824
match input {
825825
PackageSolvingData::HolderHTLCOutput(ref outp) => {
826-
debug_assert!(outp.channel_type_features.supports_anchors());
826+
debug_assert!(outp.channel_type_features.supports_anchors_zero_fee_htlc_tx());
827827
onchain_handler.generate_external_htlc_claim(&previous_output, &outp.preimage).map(|htlc| {
828828
htlcs.get_or_insert_with(|| Vec::with_capacity(self.inputs.len())).push(htlc);
829829
});
@@ -947,8 +947,8 @@ impl PackageTemplate {
947947
/// attached to help the spending transaction reach confirmation.
948948
pub(crate) fn requires_external_funding(&self) -> bool {
949949
self.inputs.iter().find(|input| match input.1 {
950-
PackageSolvingData::HolderFundingOutput(ref outp) => outp.channel_type_features.supports_anchors(),
951-
PackageSolvingData::HolderHTLCOutput(ref outp) => outp.channel_type_features.supports_anchors(),
950+
PackageSolvingData::HolderFundingOutput(ref outp) => outp.channel_type_features.supports_anchors_zero_fee_htlc_tx(),
951+
PackageSolvingData::HolderHTLCOutput(ref outp) => outp.channel_type_features.supports_anchors_zero_fee_htlc_tx(),
952952
_ => false,
953953
}).is_some()
954954
}

lightning/src/ln/chan_utils.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ pub const MAX_ACCEPTED_HTLC_SCRIPT_WEIGHT: usize = 143;
6363
pub fn htlc_success_tx_weight(channel_type_features: &ChannelTypeFeatures) -> u64 {
6464
const HTLC_SUCCESS_TX_WEIGHT: u64 = 703;
6565
const HTLC_SUCCESS_ANCHOR_TX_WEIGHT: u64 = 706;
66-
if channel_type_features.supports_anchors() { HTLC_SUCCESS_ANCHOR_TX_WEIGHT } else { HTLC_SUCCESS_TX_WEIGHT }
66+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { HTLC_SUCCESS_ANCHOR_TX_WEIGHT } else { HTLC_SUCCESS_TX_WEIGHT }
6767
}
6868

6969
/// Gets the weight for an HTLC-Timeout transaction.
7070
#[inline]
7171
pub fn htlc_timeout_tx_weight(channel_type_features: &ChannelTypeFeatures) -> u64 {
7272
const HTLC_TIMEOUT_TX_WEIGHT: u64 = 663;
7373
const HTLC_TIMEOUT_ANCHOR_TX_WEIGHT: u64 = 666;
74-
if channel_type_features.supports_anchors() { HTLC_TIMEOUT_ANCHOR_TX_WEIGHT } else { HTLC_TIMEOUT_TX_WEIGHT }
74+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() { HTLC_TIMEOUT_ANCHOR_TX_WEIGHT } else { HTLC_TIMEOUT_TX_WEIGHT }
7575
}
7676

7777
/// Describes the type of HTLC claim as determined by analyzing the witness.
@@ -603,7 +603,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
603603
.push_opcode(opcodes::all::OP_EQUALVERIFY)
604604
.push_opcode(opcodes::all::OP_CHECKSIG)
605605
.push_opcode(opcodes::all::OP_ENDIF);
606-
if channel_type_features.supports_anchors() {
606+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
607607
bldr = bldr.push_opcode(opcodes::all::OP_PUSHNUM_1)
608608
.push_opcode(opcodes::all::OP_CSV)
609609
.push_opcode(opcodes::all::OP_DROP);
@@ -639,7 +639,7 @@ pub(crate) fn get_htlc_redeemscript_with_explicit_keys(htlc: &HTLCOutputInCommit
639639
.push_opcode(opcodes::all::OP_DROP)
640640
.push_opcode(opcodes::all::OP_CHECKSIG)
641641
.push_opcode(opcodes::all::OP_ENDIF);
642-
if channel_type_features.supports_anchors() {
642+
if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
643643
bldr = bldr.push_opcode(opcodes::all::OP_PUSHNUM_1)
644644
.push_opcode(opcodes::all::OP_CSV)
645645
.push_opcode(opcodes::all::OP_DROP);
@@ -708,7 +708,7 @@ pub(crate) fn build_htlc_input(commitment_txid: &Txid, htlc: &HTLCOutputInCommit
708708
vout: htlc.transaction_output_index.expect("Can't build an HTLC transaction for a dust output"),
709709
},
710710
script_sig: Script::new(),
711-
sequence: Sequence(if channel_type_features.supports_anchors() { 1 } else { 0 }),
711+
sequence: Sequence(if channel_type_features.supports_anchors_zero_fee_htlc_tx() { 1 } else { 0 }),
712712
witness: Witness::new(),
713713
}
714714
}
@@ -721,7 +721,7 @@ pub(crate) fn build_htlc_output(
721721
} else {
722722
htlc_success_tx_weight(channel_type_features)
723723
};
724-
let output_value = if channel_type_features.supports_anchors() && !channel_type_features.supports_anchors_nonzero_fee_htlc_tx() {
724+
let output_value = if channel_type_features.supports_anchors_zero_fee_htlc_tx() && !channel_type_features.supports_anchors_nonzero_fee_htlc_tx() {
725725
htlc.amount_msat / 1000
726726
} else {
727727
let total_fee = feerate_per_kw as u64 * weight / 1000;
@@ -739,7 +739,7 @@ pub fn build_htlc_input_witness(
739739
local_sig: &Signature, remote_sig: &Signature, preimage: &Option<PaymentPreimage>,
740740
redeem_script: &Script, channel_type_features: &ChannelTypeFeatures,
741741
) -> Witness {
742-
let remote_sighash_type = if channel_type_features.supports_anchors() {
742+
let remote_sighash_type = if channel_type_features.supports_anchors_zero_fee_htlc_tx() {
743743
EcdsaSighashType::SinglePlusAnyoneCanPay
744744
} else {
745745
EcdsaSighashType::All
@@ -1418,7 +1418,7 @@ impl CommitmentTransaction {
14181418
let mut txouts: Vec<(TxOut, Option<&mut HTLCOutputInCommitment>)> = Vec::new();
14191419

14201420
if to_countersignatory_value_sat > 0 {
1421-
let script = if channel_parameters.channel_type_features().supports_anchors() {
1421+
let script = if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
14221422
get_to_countersignatory_with_anchors_redeemscript(&countersignatory_pubkeys.payment_point).to_v0_p2wsh()
14231423
} else {
14241424
Payload::p2wpkh(&BitcoinPublicKey::new(countersignatory_pubkeys.payment_point)).unwrap().script_pubkey()
@@ -1447,7 +1447,7 @@ impl CommitmentTransaction {
14471447
));
14481448
}
14491449

1450-
if channel_parameters.channel_type_features().supports_anchors() {
1450+
if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
14511451
if to_broadcaster_value_sat > 0 || !htlcs_with_aux.is_empty() {
14521452
let anchor_script = get_anchor_redeemscript(broadcaster_funding_key);
14531453
txouts.push((

0 commit comments

Comments
 (0)