Skip to content

Commit aae1faf

Browse files
committed
Add ChannelSigner::get_{broadcaster,counterparty}_anchor_txout
1 parent 0c16e50 commit aae1faf

File tree

6 files changed

+94
-69
lines changed

6 files changed

+94
-69
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,16 +3409,14 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {
34093409
let countersignatory_keys =
34103410
&self.onchain_tx_handler.channel_transaction_parameters.holder_pubkeys;
34113411

3412-
let broadcaster_funding_key = broadcaster_keys.funding_pubkey;
3413-
let countersignatory_funding_key = countersignatory_keys.funding_pubkey;
34143412
let keys = TxCreationKeys::from_channel_static_keys(&their_per_commitment_point,
34153413
&broadcaster_keys, &countersignatory_keys, &self.onchain_tx_handler.secp_ctx);
34163414
let channel_parameters =
34173415
&self.onchain_tx_handler.channel_transaction_parameters.as_counterparty_broadcastable();
34183416

34193417
CommitmentTransaction::new_with_auxiliary_htlc_data(commitment_number,
3420-
to_broadcaster_value, to_countersignatory_value, broadcaster_funding_key,
3421-
countersignatory_funding_key, keys, feerate_per_kw, &mut nondust_htlcs,
3418+
to_broadcaster_value, to_countersignatory_value,
3419+
keys, feerate_per_kw, &mut nondust_htlcs,
34223420
channel_parameters, &self.onchain_tx_handler.signer, &self.onchain_tx_handler.secp_ctx, false)
34233421
}
34243422

lightning/src/ln/chan_utils.rs

Lines changed: 16 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use bitcoin::{secp256k1, Sequence, Witness};
4141
use crate::io;
4242
use core::cmp;
4343
use crate::util::transaction_utils::sort_outputs;
44-
use crate::ln::channel::{INITIAL_COMMITMENT_NUMBER, ANCHOR_OUTPUT_VALUE_SATOSHI};
44+
use crate::ln::channel::INITIAL_COMMITMENT_NUMBER;
4545
use core::ops::Deref;
4646
use crate::chain;
4747
use crate::types::features::ChannelTypeFeatures;
@@ -1136,7 +1136,7 @@ impl HolderCommitmentTransaction {
11361136
for _ in 0..htlcs.len() {
11371137
counterparty_htlc_sigs.push(dummy_sig);
11381138
}
1139-
let inner = CommitmentTransaction::new_with_auxiliary_htlc_data(0, 0, 0, dummy_key.clone(), dummy_key.clone(), keys, 0, htlcs, &channel_parameters.as_counterparty_broadcastable(), &signer, &secp_ctx, false);
1139+
let inner = CommitmentTransaction::new_with_auxiliary_htlc_data(0, 0, 0, keys, 0, htlcs, &channel_parameters.as_counterparty_broadcastable(), &signer, &secp_ctx, false);
11401140
htlcs.sort_by_key(|htlc| htlc.0.transaction_output_index);
11411141
HolderCommitmentTransaction {
11421142
inner,
@@ -1446,12 +1446,12 @@ impl CommitmentTransaction {
14461446
/// Only include HTLCs that are above the dust limit for the channel.
14471447
///
14481448
/// This is not exported to bindings users due to the generic though we likely should expose a version without
1449-
pub fn new_with_auxiliary_htlc_data<T, Signer: ChannelSigner>(commitment_number: u64, to_broadcaster_value_sat: u64, to_countersignatory_value_sat: u64, broadcaster_funding_key: PublicKey, countersignatory_funding_key: PublicKey, keys: TxCreationKeys, feerate_per_kw: u32, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, channel_parameters: &DirectedChannelTransactionParameters, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool) -> CommitmentTransaction {
1449+
pub fn new_with_auxiliary_htlc_data<T, Signer: ChannelSigner>(commitment_number: u64, to_broadcaster_value_sat: u64, to_countersignatory_value_sat: u64, keys: TxCreationKeys, feerate_per_kw: u32, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, channel_parameters: &DirectedChannelTransactionParameters, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool) -> CommitmentTransaction {
14501450
let to_broadcaster_value_sat = Amount::from_sat(to_broadcaster_value_sat);
14511451
let to_countersignatory_value_sat = Amount::from_sat(to_countersignatory_value_sat);
14521452

14531453
// Sort outputs and populate output indices while keeping track of the auxiliary data
1454-
let (outputs, htlcs) = Self::internal_build_outputs(&keys.per_commitment_point, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, channel_parameters, &broadcaster_funding_key, &countersignatory_funding_key, signer, secp_ctx, is_holder_tx, commitment_number).unwrap();
1454+
let (outputs, htlcs) = Self::internal_build_outputs(&keys.per_commitment_point, to_broadcaster_value_sat, to_countersignatory_value_sat, htlcs_with_aux, signer, secp_ctx, is_holder_tx, commitment_number).unwrap();
14551455

14561456
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(commitment_number, channel_parameters);
14571457
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
@@ -1480,11 +1480,11 @@ impl CommitmentTransaction {
14801480
self
14811481
}
14821482

1483-
fn internal_rebuild_transaction<Signer: ChannelSigner>(&self, per_commitment_point: &PublicKey, channel_parameters: &DirectedChannelTransactionParameters, broadcaster_funding_key: &PublicKey, countersignatory_funding_key: &PublicKey, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool) -> Result<BuiltCommitmentTransaction, ()> {
1483+
fn internal_rebuild_transaction<Signer: ChannelSigner>(&self, per_commitment_point: &PublicKey, channel_parameters: &DirectedChannelTransactionParameters, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool) -> Result<BuiltCommitmentTransaction, ()> {
14841484
let (obscured_commitment_transaction_number, txins) = Self::internal_build_inputs(self.commitment_number, channel_parameters);
14851485

14861486
let mut htlcs_with_aux = self.htlcs.iter().map(|h| (h.clone(), ())).collect();
1487-
let (outputs, _) = Self::internal_build_outputs(per_commitment_point, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, channel_parameters, broadcaster_funding_key, countersignatory_funding_key, signer, secp_ctx, is_holder_tx, self.commitment_number)?;
1487+
let (outputs, _) = Self::internal_build_outputs(per_commitment_point, self.to_broadcaster_value_sat, self.to_countersignatory_value_sat, &mut htlcs_with_aux, signer, secp_ctx, is_holder_tx, self.commitment_number)?;
14881488

14891489
let transaction = Self::make_transaction(obscured_commitment_transaction_number, txins, outputs);
14901490
let txid = transaction.compute_txid();
@@ -1508,7 +1508,7 @@ impl CommitmentTransaction {
15081508
// - initial sorting of outputs / HTLCs in the constructor, in which case T is auxiliary data the
15091509
// caller needs to have sorted together with the HTLCs so it can keep track of the output index
15101510
// - building of a bitcoin transaction during a verify() call, in which case T is just ()
1511-
fn internal_build_outputs<T, Signer: ChannelSigner>(per_commitment_point: &PublicKey, to_broadcaster_value_sat: Amount, to_countersignatory_value_sat: Amount, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, channel_parameters: &DirectedChannelTransactionParameters, broadcaster_funding_key: &PublicKey, countersignatory_funding_key: &PublicKey, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool, commitment_number: u64) -> Result<(Vec<TxOut>, Vec<HTLCOutputInCommitment>), ()> {
1511+
fn internal_build_outputs<T, Signer: ChannelSigner>(per_commitment_point: &PublicKey, to_broadcaster_value_sat: Amount, to_countersignatory_value_sat: Amount, htlcs_with_aux: &mut Vec<(HTLCOutputInCommitment, T)>, signer: &Signer, secp_ctx: &Secp256k1<secp256k1::All>, is_holder_tx: bool, commitment_number: u64) -> Result<(Vec<TxOut>, Vec<HTLCOutputInCommitment>), ()> {
15121512
let mut txouts: Vec<(TxOut, Option<&mut HTLCOutputInCommitment>)> = Vec::new();
15131513

15141514
if to_countersignatory_value_sat > Amount::ZERO {
@@ -1531,27 +1531,15 @@ impl CommitmentTransaction {
15311531
));
15321532
}
15331533

1534-
if channel_parameters.channel_type_features().supports_anchors_zero_fee_htlc_tx() {
1535-
if to_broadcaster_value_sat > Amount::ZERO || !htlcs_with_aux.is_empty() {
1536-
let anchor_script = get_anchor_redeemscript(broadcaster_funding_key);
1537-
txouts.push((
1538-
TxOut {
1539-
script_pubkey: anchor_script.to_p2wsh(),
1540-
value: Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
1541-
},
1542-
None,
1543-
));
1534+
if to_broadcaster_value_sat > Amount::ZERO || !htlcs_with_aux.is_empty() {
1535+
if let Some(txout) = signer.get_broadcaster_anchor_txout(is_holder_tx) {
1536+
txouts.push((txout, None));
15441537
}
1538+
}
15451539

1546-
if to_countersignatory_value_sat > Amount::ZERO || !htlcs_with_aux.is_empty() {
1547-
let anchor_script = get_anchor_redeemscript(countersignatory_funding_key);
1548-
txouts.push((
1549-
TxOut {
1550-
script_pubkey: anchor_script.to_p2wsh(),
1551-
value: Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
1552-
},
1553-
None,
1554-
));
1540+
if to_countersignatory_value_sat > Amount::ZERO || !htlcs_with_aux.is_empty() {
1541+
if let Some(txout) = signer.get_counterparty_anchor_txout(is_holder_tx) {
1542+
txouts.push((txout, None));
15551543
}
15561544
}
15571545

@@ -1667,14 +1655,10 @@ impl CommitmentTransaction {
16671655
///
16681656
/// An external validating signer must call this method before signing
16691657
/// or using the built transaction.
1670-
pub fn verify<Signer: ChannelSigner>(&self, channel_parameters: &DirectedChannelTransactionParameters, broadcaster_keys: &ChannelPublicKeys, countersignatory_keys: &ChannelPublicKeys, secp_ctx: &Secp256k1<secp256k1::All>, signer: &Signer, is_holder_tx: bool) -> Result<TrustedCommitmentTransaction, ()> {
1658+
pub fn verify<Signer: ChannelSigner>(&self, channel_parameters: &DirectedChannelTransactionParameters, secp_ctx: &Secp256k1<secp256k1::All>, signer: &Signer, is_holder_tx: bool) -> Result<TrustedCommitmentTransaction, ()> {
16711659
// This is the only field of the key cache that we trust
16721660
let per_commitment_point = self.keys.per_commitment_point;
1673-
let keys = TxCreationKeys::from_channel_static_keys(&per_commitment_point, broadcaster_keys, countersignatory_keys, secp_ctx);
1674-
if keys != self.keys {
1675-
return Err(());
1676-
}
1677-
let tx = self.internal_rebuild_transaction(&keys.per_commitment_point, channel_parameters, &broadcaster_keys.funding_pubkey, &countersignatory_keys.funding_pubkey, signer, secp_ctx, is_holder_tx)?;
1661+
let tx = self.internal_rebuild_transaction(&per_commitment_point, channel_parameters, signer, secp_ctx, is_holder_tx)?;
16781662
if self.built.transaction != tx.transaction || self.built.txid != tx.txid {
16791663
return Err(());
16801664
}
@@ -1876,8 +1860,6 @@ mod tests {
18761860

18771861
struct TestCommitmentTxBuilder {
18781862
commitment_number: u64,
1879-
holder_funding_pubkey: PublicKey,
1880-
counterparty_funding_pubkey: PublicKey,
18811863
keys: TxCreationKeys,
18821864
feerate_per_kw: u32,
18831865
htlcs_with_aux: Vec<(HTLCOutputInCommitment, ())>,
@@ -1913,8 +1895,6 @@ mod tests {
19131895

19141896
Self {
19151897
commitment_number: 0,
1916-
holder_funding_pubkey: holder_pubkeys.funding_pubkey,
1917-
counterparty_funding_pubkey: counterparty_pubkeys.funding_pubkey,
19181898
keys,
19191899
feerate_per_kw: 1,
19201900
htlcs_with_aux,
@@ -1930,8 +1910,6 @@ mod tests {
19301910
self.commitment_number,
19311911
to_broadcaster_sats,
19321912
to_countersignatory_sats,
1933-
self.holder_funding_pubkey.clone(),
1934-
self.counterparty_funding_pubkey.clone(),
19351913
self.keys.clone(), self.feerate_per_kw,
19361914
&mut self.htlcs_with_aux, &self.channel_parameters.as_holder_broadcastable(),
19371915
&self.signer,

lightning/src/ln/channel.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3154,11 +3154,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31543154

31553155
let mut value_to_a = if local { value_to_self } else { value_to_remote };
31563156
let mut value_to_b = if local { value_to_remote } else { value_to_self };
3157-
let (funding_pubkey_a, funding_pubkey_b) = if local {
3158-
(self.get_holder_pubkeys().funding_pubkey, self.get_counterparty_pubkeys().funding_pubkey)
3159-
} else {
3160-
(self.get_counterparty_pubkeys().funding_pubkey, self.get_holder_pubkeys().funding_pubkey)
3161-
};
31623157

31633158
if value_to_a >= (broadcaster_dust_limit_satoshis as i64) {
31643159
log_trace!(logger, " ...including {} output with value {}", if local { "to_local" } else { "to_remote" }, value_to_a);
@@ -3180,8 +3175,6 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
31803175
let tx = CommitmentTransaction::new_with_auxiliary_htlc_data(commitment_number,
31813176
value_to_a as u64,
31823177
value_to_b as u64,
3183-
funding_pubkey_a,
3184-
funding_pubkey_b,
31853178
keys.clone(),
31863179
feerate_per_kw,
31873180
&mut included_non_dust_htlcs,

lightning/src/ln/functional_tests.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -731,18 +731,17 @@ fn test_update_fee_that_funder_cannot_afford() {
731731

732732
// Get the TestChannelSigner for each channel, which will be used to (1) get the keys
733733
// needed to sign the new commitment tx and (2) sign the new commitment tx.
734-
let (local_revocation_basepoint, local_htlc_basepoint, local_funding) = {
734+
let (local_revocation_basepoint, local_htlc_basepoint) = {
735735
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
736736
let chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
737737
let local_chan = chan_lock.channel_by_id.get(&chan.2).map(
738738
|phase| if let ChannelPhase::Funded(chan) = phase { Some(chan) } else { None }
739739
).flatten().unwrap();
740740
let chan_signer = local_chan.get_signer();
741741
let pubkeys = chan_signer.as_ref().pubkeys();
742-
(pubkeys.revocation_basepoint, pubkeys.htlc_basepoint,
743-
pubkeys.funding_pubkey)
742+
(pubkeys.revocation_basepoint, pubkeys.htlc_basepoint)
744743
};
745-
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point, remote_funding) = {
744+
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point) = {
746745
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
747746
let chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
748747
let remote_chan = chan_lock.channel_by_id.get(&chan.2).map(
@@ -751,8 +750,7 @@ fn test_update_fee_that_funder_cannot_afford() {
751750
let chan_signer = remote_chan.get_signer();
752751
let pubkeys = chan_signer.as_ref().pubkeys();
753752
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
754-
chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap(),
755-
pubkeys.funding_pubkey)
753+
chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap())
756754
};
757755

758756
// Assemble the set of keys we can use for signatures for our commitment_signed message.
@@ -771,7 +769,6 @@ fn test_update_fee_that_funder_cannot_afford() {
771769
INITIAL_COMMITMENT_NUMBER - 1,
772770
push_sats,
773771
channel_value - push_sats - commit_tx_fee_msat(non_buffer_feerate + 4, 0, &channel_type_features) / 1000,
774-
local_funding, remote_funding,
775772
commit_tx_keys.clone(),
776773
non_buffer_feerate + 4,
777774
&mut htlcs,
@@ -1470,7 +1467,7 @@ fn test_fee_spike_violation_fails_htlc() {
14701467

14711468
// Get the TestChannelSigner for each channel, which will be used to (1) get the keys
14721469
// needed to sign the new commitment tx and (2) sign the new commitment tx.
1473-
let (local_revocation_basepoint, local_htlc_basepoint, local_secret, next_local_point, local_funding) = {
1470+
let (local_revocation_basepoint, local_htlc_basepoint, local_secret, next_local_point) = {
14741471
let per_peer_state = nodes[0].node.per_peer_state.read().unwrap();
14751472
let chan_lock = per_peer_state.get(&nodes[1].node.get_our_node_id()).unwrap().lock().unwrap();
14761473
let local_chan = chan_lock.channel_by_id.get(&chan.2).map(
@@ -1483,10 +1480,9 @@ fn test_fee_spike_violation_fails_htlc() {
14831480
let pubkeys = chan_signer.as_ref().pubkeys();
14841481
(pubkeys.revocation_basepoint, pubkeys.htlc_basepoint,
14851482
chan_signer.as_ref().release_commitment_secret(INITIAL_COMMITMENT_NUMBER).unwrap(),
1486-
chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx).unwrap(),
1487-
chan_signer.as_ref().pubkeys().funding_pubkey)
1483+
chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 2, &secp_ctx).unwrap())
14881484
};
1489-
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point, remote_funding) = {
1485+
let (remote_delayed_payment_basepoint, remote_htlc_basepoint, remote_point) = {
14901486
let per_peer_state = nodes[1].node.per_peer_state.read().unwrap();
14911487
let chan_lock = per_peer_state.get(&nodes[0].node.get_our_node_id()).unwrap().lock().unwrap();
14921488
let remote_chan = chan_lock.channel_by_id.get(&chan.2).map(
@@ -1495,8 +1491,7 @@ fn test_fee_spike_violation_fails_htlc() {
14951491
let chan_signer = remote_chan.get_signer();
14961492
let pubkeys = chan_signer.as_ref().pubkeys();
14971493
(pubkeys.delayed_payment_basepoint, pubkeys.htlc_basepoint,
1498-
chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap(),
1499-
chan_signer.as_ref().pubkeys().funding_pubkey)
1494+
chan_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &secp_ctx).unwrap())
15001495
};
15011496

15021497
// Assemble the set of keys we can use for signatures for our commitment_signed message.
@@ -1528,7 +1523,6 @@ fn test_fee_spike_violation_fails_htlc() {
15281523
commitment_number,
15291524
95000,
15301525
local_chan_balance,
1531-
local_funding, remote_funding,
15321526
commit_tx_keys.clone(),
15331527
feerate_per_kw,
15341528
&mut vec![(accepted_htlc_info, ())],

lightning/src/sign/mod.rs

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ use crate::chain::transaction::OutPoint;
4242
use crate::crypto::utils::{hkdf_extract_expand_twice, sign, sign_with_aux_rand};
4343
use crate::ln::chan_utils;
4444
use crate::ln::chan_utils::{
45-
get_counterparty_payment_script, get_revokeable_redeemscript, make_funding_redeemscript,
46-
ChannelPublicKeys, ChannelTransactionParameters, ClosingTransaction, CommitmentTransaction,
47-
HTLCOutputInCommitment, HolderCommitmentTransaction,
45+
get_anchor_redeemscript, get_counterparty_payment_script, get_revokeable_redeemscript,
46+
make_funding_redeemscript, ChannelPublicKeys, ChannelTransactionParameters, ClosingTransaction,
47+
CommitmentTransaction, HTLCOutputInCommitment, HolderCommitmentTransaction,
4848
};
4949
use crate::ln::channel::ANCHOR_OUTPUT_VALUE_SATOSHI;
5050
use crate::ln::channel_keys::{
@@ -958,6 +958,12 @@ pub trait ChannelSigner {
958958
&self, htlc: &HTLCOutputInCommitment, is_holder_tx: bool, per_commitment_point: &PublicKey,
959959
secp_ctx: &Secp256k1<secp256k1::All>,
960960
) -> ScriptBuf;
961+
962+
/// Get the broadcaster anchor output of a commit tx
963+
fn get_broadcaster_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut>;
964+
965+
/// Get the counterparty anchor output of a commit tx
966+
fn get_counterparty_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut>;
961967
}
962968

963969
/// Specifies the recipient of an invoice.
@@ -1837,6 +1843,54 @@ impl ChannelSigner for InMemorySigner {
18371843
let script = chan_utils::get_htlc_redeemscript(htlc, params.channel_type_features(), &keys);
18381844
script.to_p2wsh()
18391845
}
1846+
1847+
fn get_broadcaster_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut> {
1848+
if self
1849+
.channel_parameters
1850+
.as_ref()
1851+
.unwrap()
1852+
.channel_type_features
1853+
.supports_anchors_zero_fee_htlc_tx()
1854+
{
1855+
let params = if is_holder_tx {
1856+
self.channel_parameters.as_ref().unwrap().as_holder_broadcastable()
1857+
} else {
1858+
self.channel_parameters.as_ref().unwrap().as_counterparty_broadcastable()
1859+
};
1860+
let broadcaster_funding_key = params.broadcaster_pubkeys().funding_pubkey;
1861+
let anchor_script = get_anchor_redeemscript(&broadcaster_funding_key);
1862+
Some(TxOut {
1863+
script_pubkey: anchor_script.to_p2wsh(),
1864+
value: Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
1865+
})
1866+
} else {
1867+
None
1868+
}
1869+
}
1870+
1871+
fn get_counterparty_anchor_txout(&self, is_holder_tx: bool) -> Option<TxOut> {
1872+
if self
1873+
.channel_parameters
1874+
.as_ref()
1875+
.unwrap()
1876+
.channel_type_features
1877+
.supports_anchors_zero_fee_htlc_tx()
1878+
{
1879+
let params = if is_holder_tx {
1880+
self.channel_parameters.as_ref().unwrap().as_holder_broadcastable()
1881+
} else {
1882+
self.channel_parameters.as_ref().unwrap().as_counterparty_broadcastable()
1883+
};
1884+
let counterparty_funding_key = params.countersignatory_pubkeys().funding_pubkey;
1885+
let anchor_script = get_anchor_redeemscript(&counterparty_funding_key);
1886+
Some(TxOut {
1887+
script_pubkey: anchor_script.to_p2wsh(),
1888+
value: Amount::from_sat(ANCHOR_OUTPUT_VALUE_SATOSHI),
1889+
})
1890+
} else {
1891+
None
1892+
}
1893+
}
18401894
}
18411895

18421896
const MISSING_PARAMS_ERR: &'static str =

0 commit comments

Comments
 (0)