Skip to content

Commit db39843

Browse files
committed
Remove unnecessary sign_closing_transaction arg
1 parent d14ece4 commit db39843

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub trait ChannelKeys : Send {
148148
///
149149
/// Note that, due to rounding, there may be one "missing" satoshi, and either party may have
150150
/// chosen to forgo their output as dust.
151-
fn sign_closing_transaction<T: secp256k1::Signing>(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
151+
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
152152

153153
/// Signs a channel announcement message with our funding key, proving it comes from one
154154
/// of the channel participants.
@@ -223,11 +223,15 @@ impl ChannelKeys for InMemoryChannelKeys {
223223
Ok((commitment_sig, htlc_sigs))
224224
}
225225

226-
fn sign_closing_transaction<T: secp256k1::Signing>(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
226+
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
227227
if closing_tx.input.len() != 1 { return Err(()); }
228228
if closing_tx.input[0].witness.len() != 0 { return Err(()); }
229229
if closing_tx.output.len() > 2 { return Err(()); }
230230

231+
let remote_channel_pubkeys = self.remote_channel_pubkeys.as_ref().expect("must set remote channel pubkeys before signing");
232+
let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key);
233+
let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_pubkeys.funding_pubkey);
234+
231235
let sighash = hash_to_message!(&bip143::SighashComponents::new(closing_tx)
232236
.sighash_all(&closing_tx.input[0], &channel_funding_redeemscript, self.channel_value_satoshis)[..]);
233237
Ok(secp_ctx.sign(&sighash, &self.funding_key))

lightning/src/ln/channel.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2563,7 +2563,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
25632563

25642564
let (closing_tx, total_fee_satoshis) = self.build_closing_transaction(proposed_total_fee_satoshis, false);
25652565
let our_sig = self.local_keys
2566-
.sign_closing_transaction(&self.get_funding_redeemscript(), &closing_tx, &self.secp_ctx)
2566+
.sign_closing_transaction(&closing_tx, &self.secp_ctx)
25672567
.ok();
25682568
if our_sig.is_none() { return None; }
25692569

@@ -2719,7 +2719,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
27192719
let closing_tx_max_weight = Self::get_closing_transaction_weight(&self.get_closing_scriptpubkey(), self.their_shutdown_scriptpubkey.as_ref().unwrap());
27202720
let (closing_tx, used_total_fee) = self.build_closing_transaction($new_feerate * closing_tx_max_weight / 1000, false);
27212721
let our_sig = self.local_keys
2722-
.sign_closing_transaction(&funding_redeemscript, &closing_tx, &self.secp_ctx)
2722+
.sign_closing_transaction(&closing_tx, &self.secp_ctx)
27232723
.map_err(|_| ChannelError::Close("External signer refused to sign closing transaction"))?;
27242724
self.last_sent_closing_fee = Some(($new_feerate, used_total_fee, our_sig.clone()));
27252725
return Ok((Some(msgs::ClosingSigned {
@@ -2754,7 +2754,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
27542754
}
27552755

27562756
let our_sig = self.local_keys
2757-
.sign_closing_transaction(&funding_redeemscript, &closing_tx, &self.secp_ctx)
2757+
.sign_closing_transaction(&closing_tx, &self.secp_ctx)
27582758
.map_err(|_| ChannelError::Close("External signer refused to sign closing transaction"))?;
27592759
self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &our_sig);
27602760

lightning/src/util/enforcing_trait_impls.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ use std::cmp;
66
use std::sync::Mutex;
77

88
use bitcoin::blockdata::transaction::Transaction;
9-
use bitcoin::blockdata::script::Script;
109

1110
use secp256k1;
1211
use secp256k1::key::{SecretKey, PublicKey};
@@ -74,8 +73,8 @@ impl ChannelKeys for EnforcingChannelKeys {
7473
Ok(self.inner.sign_remote_commitment(feerate_per_kw, commitment_tx, keys, htlcs, to_self_delay, secp_ctx).unwrap())
7574
}
7675

77-
fn sign_closing_transaction<T: secp256k1::Signing>(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
78-
Ok(self.inner.sign_closing_transaction(channel_funding_redeemscript, closing_tx, secp_ctx).unwrap())
76+
fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
77+
Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
7978
}
8079

8180
fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {

0 commit comments

Comments
 (0)