From: Devrandom Date: Thu, 23 Jan 2020 22:32:29 +0000 (-0800) Subject: Remove unnecessary sign_closing_transaction arg X-Git-Tag: v0.0.12~149^2 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=db398438aba338f23d458813f756f801d2675c5f;p=rust-lightning Remove unnecessary sign_closing_transaction arg --- diff --git a/lightning/src/chain/keysinterface.rs b/lightning/src/chain/keysinterface.rs index f46fe7da8..c35dbc4bc 100644 --- a/lightning/src/chain/keysinterface.rs +++ b/lightning/src/chain/keysinterface.rs @@ -148,7 +148,7 @@ pub trait ChannelKeys : Send { /// /// Note that, due to rounding, there may be one "missing" satoshi, and either party may have /// chosen to forgo their output as dust. - fn sign_closing_transaction(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1) -> Result; + fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1) -> Result; /// Signs a channel announcement message with our funding key, proving it comes from one /// of the channel participants. @@ -223,11 +223,15 @@ impl ChannelKeys for InMemoryChannelKeys { Ok((commitment_sig, htlc_sigs)) } - fn sign_closing_transaction(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1) -> Result { + fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1) -> Result { if closing_tx.input.len() != 1 { return Err(()); } if closing_tx.input[0].witness.len() != 0 { return Err(()); } if closing_tx.output.len() > 2 { return Err(()); } + let remote_channel_pubkeys = self.remote_channel_pubkeys.as_ref().expect("must set remote channel pubkeys before signing"); + let funding_pubkey = PublicKey::from_secret_key(secp_ctx, &self.funding_key); + let channel_funding_redeemscript = make_funding_redeemscript(&funding_pubkey, &remote_channel_pubkeys.funding_pubkey); + let sighash = hash_to_message!(&bip143::SighashComponents::new(closing_tx) .sighash_all(&closing_tx.input[0], &channel_funding_redeemscript, self.channel_value_satoshis)[..]); Ok(secp_ctx.sign(&sighash, &self.funding_key)) diff --git a/lightning/src/ln/channel.rs b/lightning/src/ln/channel.rs index 7f5288a30..164a128ac 100644 --- a/lightning/src/ln/channel.rs +++ b/lightning/src/ln/channel.rs @@ -2563,7 +2563,7 @@ impl Channel { let (closing_tx, total_fee_satoshis) = self.build_closing_transaction(proposed_total_fee_satoshis, false); let our_sig = self.local_keys - .sign_closing_transaction(&self.get_funding_redeemscript(), &closing_tx, &self.secp_ctx) + .sign_closing_transaction(&closing_tx, &self.secp_ctx) .ok(); if our_sig.is_none() { return None; } @@ -2719,7 +2719,7 @@ impl Channel { let closing_tx_max_weight = Self::get_closing_transaction_weight(&self.get_closing_scriptpubkey(), self.their_shutdown_scriptpubkey.as_ref().unwrap()); let (closing_tx, used_total_fee) = self.build_closing_transaction($new_feerate * closing_tx_max_weight / 1000, false); let our_sig = self.local_keys - .sign_closing_transaction(&funding_redeemscript, &closing_tx, &self.secp_ctx) + .sign_closing_transaction(&closing_tx, &self.secp_ctx) .map_err(|_| ChannelError::Close("External signer refused to sign closing transaction"))?; self.last_sent_closing_fee = Some(($new_feerate, used_total_fee, our_sig.clone())); return Ok((Some(msgs::ClosingSigned { @@ -2754,7 +2754,7 @@ impl Channel { } let our_sig = self.local_keys - .sign_closing_transaction(&funding_redeemscript, &closing_tx, &self.secp_ctx) + .sign_closing_transaction(&closing_tx, &self.secp_ctx) .map_err(|_| ChannelError::Close("External signer refused to sign closing transaction"))?; self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &our_sig); diff --git a/lightning/src/util/enforcing_trait_impls.rs b/lightning/src/util/enforcing_trait_impls.rs index a1d774949..daee724ae 100644 --- a/lightning/src/util/enforcing_trait_impls.rs +++ b/lightning/src/util/enforcing_trait_impls.rs @@ -6,7 +6,6 @@ use std::cmp; use std::sync::Mutex; use bitcoin::blockdata::transaction::Transaction; -use bitcoin::blockdata::script::Script; use secp256k1; use secp256k1::key::{SecretKey, PublicKey}; @@ -74,8 +73,8 @@ impl ChannelKeys for EnforcingChannelKeys { Ok(self.inner.sign_remote_commitment(feerate_per_kw, commitment_tx, keys, htlcs, to_self_delay, secp_ctx).unwrap()) } - fn sign_closing_transaction(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1) -> Result { - Ok(self.inner.sign_closing_transaction(channel_funding_redeemscript, closing_tx, secp_ctx).unwrap()) + fn sign_closing_transaction(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1) -> Result { + Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap()) } fn sign_channel_announcement(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1) -> Result {