Remove unnecessary sign_closing_transaction arg
authorDevrandom <c1.devrandom@niftybox.net>
Thu, 23 Jan 2020 22:32:29 +0000 (14:32 -0800)
committerDevrandom <c1.devrandom@niftybox.net>
Fri, 24 Jan 2020 03:06:57 +0000 (19:06 -0800)
lightning/src/chain/keysinterface.rs
lightning/src/ln/channel.rs
lightning/src/util/enforcing_trait_impls.rs

index f46fe7da85ffbb2898804350c162ff05ec9b8a74..c35dbc4bc46150e954a38c56c381a33dcef546f6 100644 (file)
@@ -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<T: secp256k1::Signing>(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
+       fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()>;
 
        /// 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<T: secp256k1::Signing>(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+       fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
                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))
index 7f5288a301aac913bcedf71d44cd4753d7cbb2cd..164a128acfe1679bc335a35d33ca97b4e49beea1 100644 (file)
@@ -2563,7 +2563,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
 
                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<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                                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<ChanSigner: ChannelKeys> Channel<ChanSigner> {
                }
 
                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);
 
index a1d774949c22191a8c58a376fe31329427fa3b22..daee724ae6ac837b282bcfd0445c3746c6ed88bc 100644 (file)
@@ -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<T: secp256k1::Signing>(&self, channel_funding_redeemscript: &Script, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
-               Ok(self.inner.sign_closing_transaction(channel_funding_redeemscript, closing_tx, secp_ctx).unwrap())
+       fn sign_closing_transaction<T: secp256k1::Signing>(&self, closing_tx: &Transaction, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {
+               Ok(self.inner.sign_closing_transaction(closing_tx, secp_ctx).unwrap())
        }
 
        fn sign_channel_announcement<T: secp256k1::Signing>(&self, msg: &msgs::UnsignedChannelAnnouncement, secp_ctx: &Secp256k1<T>) -> Result<Signature, ()> {