Skip to content

Commit 3945b6d

Browse files
committed
Add HTLCDescriptor::witness_weight
1 parent e0cc071 commit 3945b6d

File tree

4 files changed

+11
-7
lines changed

4 files changed

+11
-7
lines changed

lightning/src/chain/channelmonitor.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,6 +3361,7 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {
33613361
let revokeable_spk = htlcs.first().map(|htlc| self.onchain_tx_handler.signer.get_revokeable_spk(true, htlc.per_commitment_number, &htlc.per_commitment_point, &self.onchain_tx_handler.secp_ctx));
33623362
for htlc in htlcs {
33633363
let htlc_spk = self.onchain_tx_handler.signer.get_htlc_spk(&htlc.htlc, true, &htlc.per_commitment_point, &self.onchain_tx_handler.secp_ctx);
3364+
let witness_weight = self.onchain_tx_handler.signer.get_holder_htlc_transaction_witness_weight(htlc.preimage.is_some());
33643365
htlc_descriptors.push(HTLCDescriptor {
33653366
channel_derivation_parameters: ChannelDerivationParameters {
33663367
keys_id: self.channel_keys_id,
@@ -3376,6 +3377,7 @@ impl<Signer: ChannelSigner> ChannelMonitorImpl<Signer> {
33763377
counterparty_sig: htlc.counterparty_sig,
33773378
prev_script_pubkey: htlc_spk,
33783379
next_script_pubkey: revokeable_spk.clone().unwrap(),
3380+
witness_weight,
33793381
});
33803382
}
33813383
ret.push(Event::BumpTransaction(BumpTransactionEvent::HTLCResolution {

lightning/src/chain/onchaintx.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,7 @@ impl<Signer: ChannelSigner> OnchainTxHandler<Signer> {
12151215
htlc_idx, preimage, revokeable_spk.clone(),
12161216
);
12171217
let htlc_spk = self.signer.get_htlc_spk(&htlc, true, &trusted_tx.per_commitment_point(), &self.secp_ctx);
1218+
let witness_weight = self.signer.get_holder_htlc_transaction_witness_weight(preimage.is_some());
12181219

12191220
let htlc_descriptor = HTLCDescriptor {
12201221
channel_derivation_parameters: ChannelDerivationParameters {
@@ -1231,6 +1232,7 @@ impl<Signer: ChannelSigner> OnchainTxHandler<Signer> {
12311232
counterparty_sig: counterparty_htlc_sig.clone(),
12321233
prev_script_pubkey: htlc_spk,
12331234
next_script_pubkey: revokeable_spk,
1235+
witness_weight,
12341236
};
12351237
if let Ok(witness) = self.signer.sign_holder_htlc_transaction(&htlc_tx, 0, &htlc_descriptor, &self.secp_ctx) {
12361238
htlc_tx.input[0].witness = witness;

lightning/src/events/bump_transaction.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -725,19 +725,16 @@ where
725725
let mut signers_and_revokeable_spks = BTreeMap::new();
726726
for htlc_descriptor in htlc_descriptors {
727727
// TODO: avoid having mutable references flying around
728-
let (_, witness_weight) = signers_and_revokeable_spks.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
728+
let _ = signers_and_revokeable_spks.entry(htlc_descriptor.channel_derivation_parameters.keys_id)
729729
.or_insert_with(|| {
730-
let signer = htlc_descriptor.derive_channel_signer(&self.signer_provider);
731-
// TODO: cache this, it does not change throughout the lifetime of the channel
732-
let witness_weight = signer.get_holder_htlc_transaction_witness_weight(htlc_descriptor.preimage.is_some());
733-
(signer, witness_weight)
730+
htlc_descriptor.derive_channel_signer(&self.signer_provider)
734731
});
735732

736733
let htlc_input = htlc_descriptor.unsigned_tx_input();
737734
must_spend.push(Input {
738735
outpoint: htlc_input.previous_output.clone(),
739736
previous_utxo: htlc_descriptor.previous_utxo(),
740-
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + *witness_weight,
737+
satisfaction_weight: EMPTY_SCRIPT_SIG_WEIGHT + htlc_descriptor.witness_weight,
741738
});
742739
htlc_tx.input.push(htlc_input);
743740
let htlc_output = htlc_descriptor.tx_output();
@@ -791,7 +788,7 @@ where
791788

792789
for (idx, htlc_descriptor) in htlc_descriptors.iter().enumerate() {
793790
// Unwrap because we derived the corresponding signers for all htlc descriptors further above
794-
let signer = &signers_and_revokeable_spks.get(&htlc_descriptor.channel_derivation_parameters.keys_id).unwrap().0;
791+
let signer = signers_and_revokeable_spks.get(&htlc_descriptor.channel_derivation_parameters.keys_id).unwrap();
795792
let witness = signer.sign_holder_htlc_transaction(&htlc_tx, idx, htlc_descriptor, &self.secp)?;
796793
htlc_tx.input[idx].witness = witness;
797794
}

lightning/src/sign/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,8 @@ pub struct HTLCDescriptor {
580580
pub prev_script_pubkey: ScriptBuf,
581581
/// Next script pubkey
582582
pub next_script_pubkey: ScriptBuf,
583+
/// The witness weight
584+
pub witness_weight: u64,
583585
}
584586

585587
impl_writeable_tlv_based!(HTLCDescriptor, {
@@ -593,6 +595,7 @@ impl_writeable_tlv_based!(HTLCDescriptor, {
593595
(12, counterparty_sig, required),
594596
(14, prev_script_pubkey, required),
595597
(16, next_script_pubkey, required),
598+
(18, witness_weight, required),
596599
});
597600

598601
impl HTLCDescriptor {

0 commit comments

Comments
 (0)