Skip to content

Commit f83fb70

Browse files
committed
Let ChannelSigner set commit tx htlc output script pubkey
1 parent d35fa33 commit f83fb70

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1557,9 +1557,8 @@ impl CommitmentTransaction {
15571557

15581558
let mut htlcs = Vec::with_capacity(htlcs_with_aux.len());
15591559
for (htlc, _) in htlcs_with_aux {
1560-
let script = get_htlc_redeemscript(&htlc, &channel_parameters.channel_type_features(), &keys);
15611560
let txout = TxOut {
1562-
script_pubkey: script.to_p2wsh(),
1561+
script_pubkey: signer.get_htlc_spk(htlc, is_holder_tx, &keys.per_commitment_point, secp_ctx),
15631562
value: htlc.to_bitcoin_amount(),
15641563
};
15651564
txouts.push((txout, Some(htlc)));

lightning/src/sign/mod.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,12 @@ pub trait ChannelSigner {
952952
/// Gets the weight of the witness of the input that spends the htlc output of a
953953
/// holder commitment transaction
954954
fn get_holder_htlc_transaction_witness_weight(&self, offered: bool) -> u64;
955+
956+
/// Gets the script pubkey of a htlc output in a commitment transaction
957+
fn get_htlc_spk(
958+
&self, htlc: &HTLCOutputInCommitment, is_holder_tx: bool, per_commitment_point: &PublicKey,
959+
secp_ctx: &Secp256k1<secp256k1::All>,
960+
) -> ScriptBuf;
955961
}
956962

957963
/// Specifies the recipient of an invoice.
@@ -1812,6 +1818,25 @@ impl ChannelSigner for InMemorySigner {
18121818
chan_utils::HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT
18131819
}
18141820
}
1821+
1822+
fn get_htlc_spk(
1823+
&self, htlc: &HTLCOutputInCommitment, is_holder_tx: bool, per_commitment_point: &PublicKey,
1824+
secp_ctx: &Secp256k1<secp256k1::All>,
1825+
) -> ScriptBuf {
1826+
let params = if is_holder_tx {
1827+
self.channel_parameters.as_ref().unwrap().as_holder_broadcastable()
1828+
} else {
1829+
self.channel_parameters.as_ref().unwrap().as_counterparty_broadcastable()
1830+
};
1831+
let keys = TxCreationKeys::from_channel_static_keys(
1832+
per_commitment_point,
1833+
params.broadcaster_pubkeys(),
1834+
params.countersignatory_pubkeys(),
1835+
secp_ctx,
1836+
);
1837+
let script = chan_utils::get_htlc_redeemscript(htlc, params.channel_type_features(), &keys);
1838+
script.to_p2wsh()
1839+
}
18151840
}
18161841

18171842
const MISSING_PARAMS_ERR: &'static str =

lightning/src/util/test_channel_signer.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,10 @@ impl ChannelSigner for TestChannelSigner {
353353
fn get_holder_htlc_transaction_witness_weight(&self, offered: bool) -> u64 {
354354
self.inner.get_holder_htlc_transaction_witness_weight(offered)
355355
}
356+
357+
fn get_htlc_spk(&self, htlc: &HTLCOutputInCommitment, holder_tx: bool, per_commitment_point: &PublicKey, secp_ctx: &Secp256k1<secp256k1::All>) -> ScriptBuf {
358+
self.inner.get_htlc_spk(htlc, holder_tx, per_commitment_point, secp_ctx)
359+
}
356360
}
357361

358362
impl EcdsaChannelSigner for TestChannelSigner {

0 commit comments

Comments
 (0)