]> git.bitcoin.ninja Git - rust-lightning/commitdiff
move expensive checks to enforcing trait
authorDevrandom <c1.devrandom@niftybox.net>
Wed, 15 Jan 2020 19:11:13 +0000 (11:11 -0800)
committerDevrandom <c1.devrandom@niftybox.net>
Wed, 15 Jan 2020 19:11:13 +0000 (11:11 -0800)
lightning/src/chain/keysinterface.rs
lightning/src/util/enforcing_trait_impls.rs

index 3e4cb612f01ba4c3c560e78e12efe080d410c1e3..2f4454cf6698030b6a7a04413d373726ff71c2b4 100644 (file)
@@ -202,17 +202,6 @@ impl ChannelKeys for InMemoryChannelKeys {
                if commitment_tx.input.len() != 1 { return Err(()); }
                if commitment_tx.output.len() != redeem_scripts.len() { return Err(()); }
 
-               for (out, redeem_script) in commitment_tx.output.iter().zip(redeem_scripts.iter()) {
-                       if out.script_pubkey.is_v0_p2wpkh() {
-                               if !redeem_script.is_empty() {
-                                       return Err(())
-                               }
-                       } else {
-                               if out.script_pubkey != redeem_script.to_v0_p2wsh() {
-                                       return Err(())
-                               }
-                       }
-               }
                let commitment_sighash = hash_to_message!(&bip143::SighashComponents::new(&commitment_tx).sighash_all(&commitment_tx.input[0], &channel_funding_redeemscript, channel_value_satoshis)[..]);
                let commitment_sig = secp_ctx.sign(&commitment_sighash, &self.funding_key);
 
index 39905b413f664e8a77c188f75367e0022b89166e..4653e3cd2ce9fa4ab805e545e59cf8df8bba676a 100644 (file)
@@ -39,6 +39,18 @@ impl ChannelKeys for EnforcingChannelKeys {
                if commitment_tx.input.len() != 1 { panic!(); }
                if commitment_tx.output.len() != redeem_scripts.len() { panic!(); }
 
+               for (out, redeem_script) in commitment_tx.output.iter().zip(redeem_scripts.iter()) {
+                       if out.script_pubkey.is_v0_p2wpkh() {
+                               if !redeem_script.is_empty() {
+                                       return Err(())
+                               }
+                       } else {
+                               if out.script_pubkey != redeem_script.to_v0_p2wsh() {
+                                       return Err(())
+                               }
+                       }
+               }
+
                let obscured_commitment_transaction_number = (commitment_tx.lock_time & 0xffffff) as u64 | ((commitment_tx.input[0].sequence as u64 & 0xffffff) << 3*8);
 
                {