Skip to content

Commit 2552fd5

Browse files
committed
fixup! remove dust handling from TrustedCommitmentTransaction.get_htlc_sigs
1 parent 8b6dbe6 commit 2552fd5

File tree

5 files changed

+14
-29
lines changed

5 files changed

+14
-29
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ pub trait ChannelKeys : Send+Clone {
258258
///
259259
/// Either an Err should be returned, or a Vec with one entry for each HTLC which exists in
260260
/// holder_commitment_tx.
261-
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()>;
261+
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Signature>, ()>;
262262

263263
/// Create a signature for the given input in a transaction spending an HTLC or commitment
264264
/// transaction output when our counterparty broadcasts an old state.
@@ -485,9 +485,7 @@ impl ChannelKeys for InMemoryChannelKeys {
485485
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
486486
let funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &self.counterparty_pubkeys().funding_pubkey);
487487
let sig = commitment_tx.trust().built_transaction().sign(&self.funding_key, &funding_redeemscript, self.channel_value_satoshis, secp_ctx);
488-
let htlc_sigs_o = self.sign_holder_commitment_htlc_transactions(&commitment_tx, secp_ctx)?;
489-
let htlc_sigs = htlc_sigs_o.iter().map(|o| o.unwrap()).collect();
490-
488+
let htlc_sigs = self.sign_holder_commitment_htlc_transactions(&commitment_tx, secp_ctx)?;
491489
Ok((sig, htlc_sigs))
492490
}
493491

@@ -498,7 +496,7 @@ impl ChannelKeys for InMemoryChannelKeys {
498496
Ok(commitment_tx.trust().built_transaction().sign(&self.funding_key, &channel_funding_redeemscript, self.channel_value_satoshis, secp_ctx))
499497
}
500498

501-
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
499+
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Signature>, ()> {
502500
let channel_parameters = self.make_channel_parameters();
503501
let trusted_tx = commitment_tx.trust();
504502
trusted_tx.get_htlc_sigs(&self.htlc_base_key, &channel_parameters.as_holder_broadcastable(), secp_ctx)

lightning/src/ln/chan_utils.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,27 +1150,22 @@ impl<'a> TrustedCommitmentTransaction<'a> {
11501150
/// Get a signature for each HTLC which was included in the commitment transaction (ie for
11511151
/// which HTLCOutputInCommitment::transaction_output_index.is_some()).
11521152
///
1153-
/// The returned Vec has one entry for each HTLC, and in the same order. For HTLCs which were
1154-
/// considered dust and not included, a None entry exists, for all others a signature is
1155-
/// included.
1156-
pub fn get_htlc_sigs<T: secp256k1::Signing>(&self, htlc_base_key: &SecretKey, channel_parameters: &DirectedChannelTransactionParameters, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
1153+
/// The returned Vec has one entry for each HTLC, and in the same order.
1154+
pub fn get_htlc_sigs<T: secp256k1::Signing>(&self, htlc_base_key: &SecretKey, channel_parameters: &DirectedChannelTransactionParameters, secp_ctx: &Secp256k1<T>) -> Result<Vec<Signature>, ()> {
11571155
let inner = self.inner;
11581156
let keys = &inner.keys;
11591157
let txid = inner.built.txid;
11601158
let mut ret = Vec::with_capacity(inner.htlcs.len());
11611159
let holder_htlc_key = derive_private_key(secp_ctx, &inner.keys.per_commitment_point, htlc_base_key).map_err(|_| ())?;
11621160

11631161
for this_htlc in inner.htlcs.iter() {
1164-
if this_htlc.transaction_output_index.is_some() {
1165-
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
1162+
assert!(this_htlc.transaction_output_index.is_some());
1163+
let htlc_tx = build_htlc_transaction(&txid, inner.feerate_per_kw, channel_parameters.contest_delay(), &this_htlc, &keys.broadcaster_delayed_payment_key, &keys.revocation_key);
11661164

1167-
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
1165+
let htlc_redeemscript = get_htlc_redeemscript_with_explicit_keys(&this_htlc, &keys.broadcaster_htlc_key, &keys.countersignatory_htlc_key, &keys.revocation_key);
11681166

1169-
let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.amount_msat / 1000, SigHashType::All)[..]);
1170-
ret.push(Some(secp_ctx.sign(&sighash, &holder_htlc_key)));
1171-
} else {
1172-
ret.push(None);
1173-
}
1167+
let sighash = hash_to_message!(&bip143::SigHashCache::new(&htlc_tx).signature_hash(0, &htlc_redeemscript, this_htlc.amount_msat / 1000, SigHashType::All)[..]);
1168+
ret.push(secp_ctx.sign(&sighash, &holder_htlc_key));
11741169
}
11751170
Ok(ret)
11761171
}

lightning/src/ln/channel.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,18 +4780,14 @@ mod tests {
47804780
assert_eq!((htlc_sig.0).0.transaction_output_index, Some($htlc_idx), "output index");
47814781

47824782
let signature = Signature::from_der(&hex::decode($htlc_sig_hex).unwrap()[..]).unwrap();
4783-
assert_eq!(Some(signature), *(htlc_sig.1).1, "htlc sig");
4783+
assert_eq!(signature, *(htlc_sig.1).1, "htlc sig");
47844784
let index = (htlc_sig.1).0;
47854785
let channel_parameters = chan.channel_transaction_parameters.as_holder_broadcastable();
47864786
let trusted_tx = holder_commitment_tx.trust();
4787-
assert_eq!(serialize(&trusted_tx.get_signed_htlc_tx(&channel_parameters, index, &(htlc_sig.0).1, (htlc_sig.1).1.as_ref().unwrap(), &preimage))[..],
4787+
assert_eq!(serialize(&trusted_tx.get_signed_htlc_tx(&channel_parameters, index, &(htlc_sig.0).1, (htlc_sig.1).1, &preimage))[..],
47884788
hex::decode($htlc_tx_hex).unwrap()[..], "htlc tx");
47894789
})*
4790-
loop {
4791-
let htlc_sig = htlc_sig_iter.next();
4792-
if htlc_sig.is_none() { break; }
4793-
assert!((htlc_sig.unwrap().1).1.is_none());
4794-
}
4790+
assert!(htlc_sig_iter.next().is_none());
47954791
} }
47964792
}
47974793

lightning/src/ln/onchaintx.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -896,8 +896,6 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
896896
fn sign_latest_holder_htlcs(&mut self) {
897897
if let Some(ref holder_commitment) = self.holder_commitment {
898898
if let Ok(sigs) = self.key_storage.sign_holder_commitment_htlc_transactions(holder_commitment, &self.secp_ctx) {
899-
// since we are no longer maintaining dust HTLCs info in OnchainTxHandler, all signatures must be present
900-
let sigs: Vec<Signature> = sigs.iter().map(|o| o.unwrap()).collect();
901899
self.holder_htlc_sigs = Some(Self::extract_holder_sigs(holder_commitment, sigs));
902900
}
903901
}
@@ -906,8 +904,6 @@ impl<ChanSigner: ChannelKeys> OnchainTxHandler<ChanSigner> {
906904
fn sign_prev_holder_htlcs(&mut self) {
907905
if let Some(ref holder_commitment) = self.prev_holder_commitment {
908906
if let Ok(sigs) = self.key_storage.sign_holder_commitment_htlc_transactions(holder_commitment, &self.secp_ctx) {
909-
// since we are no longer maintaining dust HTLCs info in OnchainTxHandler, all signatures must be present
910-
let sigs: Vec<Signature> = sigs.iter().map(|o| o.unwrap()).collect();
911907
self.prev_holder_htlc_sigs = Some(Self::extract_holder_sigs(holder_commitment, sigs));
912908
}
913909
}

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl ChannelKeys for EnforcingChannelKeys {
8585
Ok(self.inner.unsafe_sign_holder_commitment(holder_commitment_tx, secp_ctx).unwrap())
8686
}
8787

88-
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Option<Signature>>, ()> {
88+
fn sign_holder_commitment_htlc_transactions<T: secp256k1::Signing + secp256k1::Verification>(&self, holder_commitment_tx: &HolderCommitmentTransaction, secp_ctx: &Secp256k1<T>) -> Result<Vec<Signature>, ()> {
8989
let commitment_tx = self.verify_holder_commitment_tx(holder_commitment_tx, secp_ctx);
9090
let commitment_txid = commitment_tx.txid();
9191
let holder_csv = self.inner.counterparty_selected_contest_delay();

0 commit comments

Comments
 (0)