Skip to content

Commit 1bc4bf5

Browse files
committed
Check local signtures explicitly in channel tx-generation tests
It appears the local signatures which are specified in the channel transaction-generation tests were never checked directly (though they were checked as a part of the overall fully-signed-transaction tests). Check them explicitly so that they can be updated for static remote key.
1 parent e8036c1 commit 1bc4bf5

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

lightning/src/ln/chan_utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,14 @@ impl LocalCommitmentTransaction {
567567
}
568568
}
569569

570+
#[cfg(test)]
571+
/// Gets the local signature we will/would/have added to our transaction.
572+
pub fn get_local_sig<T: secp256k1::Signing>(&self, funding_key: &SecretKey, funding_redeemscript: &Script, channel_value_satoshis: u64, secp_ctx: &Secp256k1<T>) -> secp256k1::Signature {
573+
let sighash = hash_to_message!(&bip143::SighashComponents::new(&self.tx)
574+
.sighash_all(&self.tx.input[0], funding_redeemscript, channel_value_satoshis)[..]);
575+
secp_ctx.sign(&sighash, funding_key)
576+
}
577+
570578
pub fn add_local_sig<T: secp256k1::Signing>(&mut self, funding_key: &SecretKey, funding_redeemscript: &Script, channel_value_satoshis: u64, secp_ctx: &Secp256k1<T>) {
571579
if self.has_local_sig() { return; }
572580
let sighash = hash_to_message!(&bip143::SighashComponents::new(&self.tx)

lightning/src/ln/channel.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4414,6 +4414,8 @@ mod tests {
44144414
secp_ctx.verify(&sighash, &their_signature, chan.their_funding_pubkey()).unwrap();
44154415

44164416
let mut localtx = LocalCommitmentTransaction::new_missing_local_sig(unsigned_tx.0.clone(), &their_signature, &PublicKey::from_secret_key(&secp_ctx, chan.local_keys.funding_key()), chan.their_funding_pubkey());
4417+
assert_eq!(Signature::from_der(&hex::decode($our_sig_hex).unwrap()[..]).unwrap(),
4418+
localtx.get_local_sig(chan.local_keys.funding_key(), &redeemscript, chan.channel_value_satoshis, &chan.secp_ctx));
44174419
localtx.add_local_sig(chan.local_keys.funding_key(), &redeemscript, chan.channel_value_satoshis, &chan.secp_ctx);
44184420

44194421
assert_eq!(serialize(localtx.with_valid_witness())[..],
@@ -4443,7 +4445,9 @@ mod tests {
44434445
assert!(preimage.is_some());
44444446
}
44454447

4446-
chan_utils::sign_htlc_transaction(&mut htlc_tx, &remote_signature, &preimage, &htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key, &keys.per_commitment_point, chan.local_keys.htlc_base_key(), &chan.secp_ctx).unwrap();
4448+
let our_signature = Signature::from_der(&hex::decode($our_sig_hex).unwrap()[..]).unwrap();
4449+
assert_eq!(our_signature,
4450+
chan_utils::sign_htlc_transaction(&mut htlc_tx, &remote_signature, &preimage, &htlc, &keys.a_htlc_key, &keys.b_htlc_key, &keys.revocation_key, &keys.per_commitment_point, chan.local_keys.htlc_base_key(), &chan.secp_ctx).unwrap().0);
44474451
assert_eq!(serialize(&htlc_tx)[..],
44484452
hex::decode($tx_hex).unwrap()[..]);
44494453
};

0 commit comments

Comments
 (0)