Skip to content

Commit 5f6e037

Browse files
committed
Let ChannelSigner set commit tx htlc output script pubkey
1 parent 05fdbfa commit 5f6e037

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -950,6 +950,12 @@ pub trait ChannelSigner {
950950
/// Gets the weight of the witness of the input that spends the htlc output of a
951951
/// holder commitment transaction
952952
fn get_holder_htlc_transaction_witness_weight(&self, offered: bool) -> u64;
953+
954+
/// Gets the script pubkey of a htlc output in a commitment transaction
955+
fn get_htlc_spk(
956+
&self, htlc: &HTLCOutputInCommitment, is_holder_tx: bool, per_commitment_point: &PublicKey,
957+
secp_ctx: &Secp256k1<secp256k1::All>,
958+
) -> ScriptBuf;
953959
}
954960

955961
/// Specifies the recipient of an invoice.
@@ -1780,6 +1786,24 @@ impl ChannelSigner for InMemorySigner {
17801786
chan_utils::HTLC_TIMEOUT_INPUT_ANCHOR_WITNESS_WEIGHT
17811787
}
17821788
}
1789+
1790+
fn get_htlc_spk(
1791+
&self, htlc: &HTLCOutputInCommitment, is_holder_tx: bool, per_commitment_point: &PublicKey,
1792+
secp_ctx: &Secp256k1<secp256k1::All>,
1793+
) -> ScriptBuf {
1794+
let params = if is_holder_tx {
1795+
self.channel_parameters.as_ref().unwrap().as_holder_broadcastable()
1796+
} else {
1797+
self.channel_parameters.as_ref().unwrap().as_counterparty_broadcastable()
1798+
};
1799+
let keys = TxCreationKeys::from_channel_static_keys(
1800+
per_commitment_point,
1801+
params.broadcaster_pubkeys(),
1802+
params.countersignatory_pubkeys(),
1803+
secp_ctx,
1804+
);
1805+
chan_utils::get_htlc_redeemscript(htlc, params.channel_type_features(), &keys).to_p2wsh()
1806+
}
17831807
}
17841808

17851809
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
@@ -339,6 +339,10 @@ impl ChannelSigner for TestChannelSigner {
339339
fn get_holder_htlc_transaction_witness_weight(&self, offered: bool) -> u64 {
340340
self.inner.get_holder_htlc_transaction_witness_weight(offered)
341341
}
342+
343+
fn get_htlc_spk(&self, htlc: &HTLCOutputInCommitment, holder_tx: bool, per_commitment_point: &PublicKey, secp_ctx: &Secp256k1<secp256k1::All>) -> ScriptBuf {
344+
self.inner.get_htlc_spk(htlc, holder_tx, per_commitment_point, secp_ctx)
345+
}
342346
}
343347

344348
impl EcdsaChannelSigner for TestChannelSigner {

0 commit comments

Comments
 (0)