Merge pull request #231 from philipr-za/philip-204-check-commitment-transaction-fee
authorMatt Corallo <649246+TheBlueMatt@users.noreply.github.com>
Tue, 20 Nov 2018 21:29:21 +0000 (16:29 -0500)
committerGitHub <noreply@github.com>
Tue, 20 Nov 2018 21:29:21 +0000 (16:29 -0500)
Check funder can afford commitment transaction fee when receiving update_fee

Cargo.toml
fuzz/Cargo.toml
fuzz/fuzz_targets/full_stack_target.rs
src/chain/chaininterface.rs
src/chain/keysinterface.rs
src/chain/transaction.rs
src/ln/channel.rs
src/ln/channelmanager.rs
src/ln/channelmonitor.rs

index 052f2fc03d2d98b6a8a99687e161e92a7f60080d..9ecd10fb2bede052abc6d0ddf2f2683e1c6b543f 100644 (file)
@@ -23,7 +23,7 @@ max_level_info = []
 max_level_debug = []
 
 [dependencies]
-bitcoin = "0.14"
+bitcoin = "0.15"
 rust-crypto = "0.2"
 rand = "0.4"
 secp256k1 = "0.11"
@@ -32,7 +32,7 @@ secp256k1 = "0.11"
 cc = "1.0"
 
 [dev-dependencies.bitcoin]
-version = "0.14"
+version = "0.15"
 features = ["bitcoinconsensus"]
 
 [dev-dependencies]
index a457df1a790eb0b628708263215a337ff273ae87..ecf3809c59b3ec8cc88ca349b3ad1eff3b9cb7b0 100644 (file)
@@ -18,7 +18,7 @@ honggfuzz_fuzz = ["honggfuzz"]
 [dependencies]
 afl = { version = "0.4", optional = true }
 lightning = { path = "..", features = ["fuzztarget"] }
-bitcoin = { version = "0.14", features = ["fuzztarget"] }
+bitcoin = { version = "0.15", features = ["fuzztarget"] }
 hex = "0.3"
 honggfuzz = { version = "0.5", optional = true }
 rust-crypto = "0.2"
index f943945531e834a854ebca0927288c57e46c108b..3b277906b0bea91d9bac2c89c194b5b147e952ac 100644 (file)
@@ -7,9 +7,9 @@ use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::{Transaction, TxOut};
 use bitcoin::blockdata::script::{Builder, Script};
 use bitcoin::blockdata::opcodes;
+use bitcoin::consensus::encode::{deserialize, serialize};
 use bitcoin::network::constants::Network;
-use bitcoin::network::serialize::{deserialize, serialize, BitcoinHash};
-use bitcoin::util::hash::{Sha256dHash, Hash160};
+use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160};
 
 use crypto::digest::Digest;
 
@@ -168,7 +168,7 @@ impl<'a> MoneyLossDetector<'a> {
                let mut txn = Vec::with_capacity(all_txn.len());
                let mut txn_idxs = Vec::with_capacity(all_txn.len());
                for (idx, tx) in all_txn.iter().enumerate() {
-                       let txid = Sha256dHash::from_data(&serialize(tx).unwrap()[..]);
+                       let txid = tx.txid();
                        match self.txids_confirmed.entry(txid) {
                                hash_map::Entry::Vacant(e) => {
                                        e.insert(self.height);
@@ -432,7 +432,7 @@ pub fn do_test(data: &[u8], logger: &Arc<Logger>) {
                                                        value: funding_generation.1, script_pubkey: funding_generation.2,
                                                }] };
                                        let funding_output = 'search_loop: loop {
-                                               let funding_txid = Sha256dHash::from_data(&serialize(&tx).unwrap()[..]);
+                                               let funding_txid = tx.txid();
                                                if let None = loss_detector.txids_confirmed.get(&funding_txid) {
                                                        let outpoint = OutPoint::new(funding_txid, 0);
                                                        for chan in channelmanager.list_channels() {
index 9999177de966e15a0b9ebb4c90b9f3a590c743b5..7b5e0d0749832a7cf2ffcfcd560156d085fd53f7 100644 (file)
@@ -8,9 +8,8 @@ use bitcoin::blockdata::block::{Block, BlockHeader};
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::script::Script;
 use bitcoin::blockdata::constants::genesis_block;
-use bitcoin::util::hash::Sha256dHash;
+use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
 use bitcoin::network::constants::Network;
-use bitcoin::network::serialize::BitcoinHash;
 
 use util::logger::Logger;
 
index 556be6dc5bbaa4c881ca58f12be762c28598ff54..8e71625df73c29338d71a7457180c8f59d4d962e 100644 (file)
@@ -37,19 +37,34 @@ pub enum SpendableOutputDescriptor {
                /// The output which is referenced by the given outpoint
                output: TxOut,
        },
-       /// Outpoint commits to a P2WSH, should be spend by the following witness :
+       /// Outpoint commits to a P2WSH
+       /// P2WSH should be spend by the following witness :
        /// <local_delayedsig> 0 <witnessScript>
        /// With input nSequence set to_self_delay.
-       /// Outputs from a HTLC-Success/Timeout tx
-       DynamicOutput {
+       /// Outputs from a HTLC-Success/Timeout tx/commitment tx
+       DynamicOutputP2WSH {
                /// Outpoint spendable by user wallet
                outpoint: OutPoint,
-               /// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint)
-               local_delayedkey: SecretKey,
-               /// witness redeemScript encumbering output
+               /// local_delayedkey = delayed_payment_basepoint_secret + SHA256(per_commitment_point || delayed_payment_basepoint) OR
+               key: SecretKey,
+               /// witness redeemScript encumbering output.
                witness_script: Script,
                /// nSequence input must commit to self_delay to satisfy script's OP_CSV
                to_self_delay: u16,
+               /// The output which is referenced by the given outpoint
+               output: TxOut,
+       },
+       /// Outpoint commits to a P2WPKH
+       /// P2WPKH should be spend by the following witness :
+       /// <local_sig> <local_pubkey>
+       /// Outputs to_remote from a commitment tx
+       DynamicOutputP2WPKH {
+               /// Outpoint spendable by user wallet
+               outpoint: OutPoint,
+               /// localkey = payment_basepoint_secret + SHA256(per_commitment_point || payment_basepoint
+               key: SecretKey,
+               /// The output which is reference by the given outpoint
+               output: TxOut,
        }
 }
 
index e8ebae7092556286e4a6f22a8bfde7baa0ef9b30..a9b314dd08e4eec7ddb7a5bd6f94d43816191217 100644 (file)
@@ -44,13 +44,13 @@ mod tests {
        use chain::transaction::OutPoint;
 
        use bitcoin::blockdata::transaction::Transaction;
-       use bitcoin::network::serialize;
+       use bitcoin::consensus::encode;
 
        use hex;
 
        #[test]
        fn test_channel_id_calculation() {
-               let tx: Transaction = serialize::deserialize(&hex::decode("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
+               let tx: Transaction = encode::deserialize(&hex::decode("020000000001010e0adef48412e4361325ac1c6e36411299ab09d4f083b9d8ddb55fbc06e1b0c00000000000feffffff0220a1070000000000220020f81d95e040bd0a493e38bae27bff52fe2bb58b93b293eb579c01c31b05c5af1dc072cfee54a3000016001434b1d6211af5551905dc2642d05f5b04d25a8fe80247304402207f570e3f0de50546aad25a872e3df059d277e776dda4269fa0d2cc8c2ee6ec9a022054e7fae5ca94d47534c86705857c24ceea3ad51c69dd6051c5850304880fc43a012103cb11a1bacc223d98d91f1946c6752e358a5eb1a1c983b3e6fb15378f453b76bd00000000").unwrap()[..]).unwrap();
                assert_eq!(&OutPoint {
                        txid: tx.txid(),
                        index: 0
index 57070e41d5fe27aa2085a4155952a9618a218a34..d0a4644abdfa7164a25275ca2738f4a3e535b093 100644 (file)
@@ -2,11 +2,9 @@ use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::script::{Script,Builder};
 use bitcoin::blockdata::transaction::{TxIn, TxOut, Transaction, SigHashType};
 use bitcoin::blockdata::opcodes;
-use bitcoin::util::hash::{Sha256dHash, Hash160};
+use bitcoin::util::hash::{BitcoinHash, Sha256dHash, Hash160};
 use bitcoin::util::bip143;
-use bitcoin::network;
-use bitcoin::network::serialize::{BitcoinHash, RawDecoder, RawEncoder};
-use bitcoin::network::encodable::{ConsensusEncodable, ConsensusDecodable};
+use bitcoin::consensus::encode::{self, Encodable, Decodable};
 
 use secp256k1::key::{PublicKey,SecretKey};
 use secp256k1::{Secp256k1,Message,Signature};
@@ -439,7 +437,7 @@ impl Channel {
 
                let secp_ctx = Secp256k1::new();
                let channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
-                                                         &chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT,
+                                                         &chan_keys.htlc_base_key, &chan_keys.payment_base_key, &keys_provider.get_shutdown_pubkey(), BREAKDOWN_TIMEOUT,
                                                          keys_provider.get_destination_script(), logger.clone());
 
                Ok(Channel {
@@ -627,9 +625,10 @@ impl Channel {
 
                let secp_ctx = Secp256k1::new();
                let mut channel_monitor = ChannelMonitor::new(&chan_keys.revocation_base_key, &chan_keys.delayed_payment_base_key,
-                                                             &chan_keys.htlc_base_key, BREAKDOWN_TIMEOUT,
+                                                             &chan_keys.htlc_base_key, &chan_keys.payment_base_key, &keys_provider.get_shutdown_pubkey(), BREAKDOWN_TIMEOUT,
                                                              keys_provider.get_destination_script(), logger.clone());
                channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
+               channel_monitor.provide_their_next_revocation_point(Some((INITIAL_COMMITMENT_NUMBER, msg.first_per_commitment_point)));
                channel_monitor.set_their_to_self_delay(msg.to_self_delay);
 
                let mut chan = Channel {
@@ -1123,8 +1122,9 @@ impl Channel {
                Ok(our_sig)
        }
 
-       /// May return an IgnoreError, but should not, and will always return Ok(_) when
-       /// debug_assertions are turned on
+       /// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
+       /// In such cases we debug_assert!(false) and return an IgnoreError. Thus, will always return
+       /// Ok(_) if debug assertions are turned on and preconditions are met.
        fn get_update_fulfill_htlc(&mut self, htlc_id_arg: u64, payment_preimage_arg: [u8; 32]) -> Result<(Option<msgs::UpdateFulfillHTLC>, Option<ChannelMonitor>), HandleError> {
                // Either ChannelFunded got set (which means it wont bet unset) or there is no way any
                // caller thought we could have something claimed (cause we wouldn't have accepted in an
@@ -1176,7 +1176,9 @@ impl Channel {
                                        &HTLCUpdateAwaitingACK::FailHTLC { htlc_id, .. } => {
                                                if htlc_id_arg == htlc_id {
                                                        debug_assert!(false, "Tried to fulfill an HTLC we already had a holding-cell failure on");
-                                                       return Err(HandleError{err: "Unable to find a pending HTLC which matched the given HTLC ID", action: Some(msgs::ErrorAction::IgnoreError)});
+                                                       // Return the new channel monitor in a last-ditch effort to hit the
+                                                       // chain and claim the funds
+                                                       return Ok((None, Some(self.channel_monitor.clone())));
                                                }
                                        },
                                        _ => {}
@@ -1216,8 +1218,9 @@ impl Channel {
                }
        }
 
-       /// May return an IgnoreError, but should not, and will always return Ok(_) when
-       /// debug_assertions are turned on
+       /// Per HTLC, only one get_update_fail_htlc or get_update_fulfill_htlc call may be made.
+       /// In such cases we debug_assert!(false) and return an IgnoreError. Thus, will always return
+       /// Ok(_) if debug assertions are turned on and preconditions are met.
        pub fn get_update_fail_htlc(&mut self, htlc_id_arg: u64, err_packet: msgs::OnionErrorPacket) -> Result<Option<msgs::UpdateFailHTLC>, HandleError> {
                if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
                        panic!("Was asked to fail an HTLC when channel was not in an operational state");
@@ -1350,6 +1353,7 @@ impl Channel {
                }
 
                self.channel_monitor.set_their_base_keys(&msg.htlc_basepoint, &msg.delayed_payment_basepoint);
+               self.channel_monitor.provide_their_next_revocation_point(Some((INITIAL_COMMITMENT_NUMBER, msg.first_per_commitment_point)));
 
                self.their_dust_limit_satoshis = msg.dust_limit_satoshis;
                self.their_max_htlc_value_in_flight_msat = cmp::min(msg.max_htlc_value_in_flight_msat, self.channel_value_satoshis * 1000);
@@ -1374,22 +1378,25 @@ impl Channel {
                Ok(())
        }
 
-       fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Signature), HandleError> {
+       fn funding_created_signature(&mut self, sig: &Signature) -> Result<(Transaction, Transaction, Signature, TxCreationKeys), HandleError> {
                let funding_script = self.get_funding_redeemscript();
 
                let local_keys = self.build_local_transaction_keys(self.cur_local_commitment_transaction_number)?;
-               let local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false, self.feerate_per_kw).0;
+               let mut local_initial_commitment_tx = self.build_commitment_transaction(self.cur_local_commitment_transaction_number, &local_keys, true, false, self.feerate_per_kw).0;
                let local_sighash = Message::from_slice(&bip143::SighashComponents::new(&local_initial_commitment_tx).sighash_all(&local_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
 
-               // They sign the "local" commitment transaction, allowing us to broadcast the tx if we wish.
+               // They sign the "local" commitment transaction...
                secp_call!(self.secp_ctx.verify(&local_sighash, &sig, &self.their_funding_pubkey.unwrap()), "Invalid funding_created signature from peer", self.channel_id());
 
+               // ...and we sign it, allowing us to broadcast the tx if we wish
+               self.sign_commitment_transaction(&mut local_initial_commitment_tx, sig);
+
                let remote_keys = self.build_remote_transaction_keys()?;
                let remote_initial_commitment_tx = self.build_commitment_transaction(self.cur_remote_commitment_transaction_number, &remote_keys, false, false, self.feerate_per_kw).0;
                let remote_sighash = Message::from_slice(&bip143::SighashComponents::new(&remote_initial_commitment_tx).sighash_all(&remote_initial_commitment_tx.input[0], &funding_script, self.channel_value_satoshis)[..]).unwrap();
 
                // We sign the "remote" commitment transaction, allowing them to broadcast the tx if they wish.
-               Ok((remote_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key)))
+               Ok((remote_initial_commitment_tx, local_initial_commitment_tx, self.secp_ctx.sign(&remote_sighash, &self.local_keys.funding_key), local_keys))
        }
 
        pub fn funding_created(&mut self, msg: &msgs::FundingCreated) -> Result<(msgs::FundingSigned, ChannelMonitor), HandleError> {
@@ -1412,7 +1419,7 @@ impl Channel {
                let funding_txo_script = self.get_funding_redeemscript().to_v0_p2wsh();
                self.channel_monitor.set_funding_info((funding_txo, funding_txo_script));
 
-               let (remote_initial_commitment_tx, our_signature) = match self.funding_created_signature(&msg.signature) {
+               let (remote_initial_commitment_tx, local_initial_commitment_tx, our_signature, local_keys) = match self.funding_created_signature(&msg.signature) {
                        Ok(res) => res,
                        Err(e) => {
                                self.channel_monitor.unset_funding_info();
@@ -1423,6 +1430,8 @@ impl Channel {
                // Now that we're past error-generating stuff, update our local state:
 
                self.channel_monitor.provide_latest_remote_commitment_tx_info(&remote_initial_commitment_tx, Vec::new(), self.cur_remote_commitment_transaction_number);
+               self.last_local_commitment_txn = vec![local_initial_commitment_tx.clone()];
+               self.channel_monitor.provide_latest_local_commitment_tx_info(local_initial_commitment_tx, local_keys, self.feerate_per_kw, Vec::new());
                self.channel_state = ChannelState::FundingSent as u32;
                self.channel_id = funding_txo.to_channel_id();
                self.cur_remote_commitment_transaction_number -= 1;
@@ -1492,6 +1501,7 @@ impl Channel {
                        return Err(ChannelError::Close("Peer sent a funding_locked at a strange time"));
                }
 
+               self.channel_monitor.provide_their_next_revocation_point(Some((INITIAL_COMMITMENT_NUMBER - 1 , msg.next_per_commitment_point)));
                self.their_prev_commitment_point = self.their_cur_commitment_point;
                self.their_cur_commitment_point = Some(msg.next_per_commitment_point);
                Ok(())
@@ -1884,7 +1894,8 @@ impl Channel {
                                return Err(HandleError{err: "Got a revoke commitment secret which didn't correspond to their current pubkey", action: None});
                        }
                }
-               self.channel_monitor.provide_secret(self.cur_remote_commitment_transaction_number + 1, msg.per_commitment_secret, Some((self.cur_remote_commitment_transaction_number - 1, msg.next_per_commitment_point)))?;
+               self.channel_monitor.provide_secret(self.cur_remote_commitment_transaction_number + 1, msg.per_commitment_secret)?;
+               self.channel_monitor.provide_their_next_revocation_point(Some((self.cur_remote_commitment_transaction_number - 1, msg.next_per_commitment_point)));
 
                // Update state now that we've passed all the can-fail calls...
                // (note that we may still fail to generate the new commitment_signed message, but that's
@@ -2836,6 +2847,16 @@ impl Channel {
                                                self.channel_update_count += 1;
                                                return Err(HandleError{err: "funding tx had wrong script/value", action: Some(ErrorAction::DisconnectPeer{msg: None})});
                                        } else {
+                                               if self.channel_outbound {
+                                                       for input in tx.input.iter() {
+                                                               if input.witness.is_empty() {
+                                                                       // We generated a malleable funding transaction, implying we've
+                                                                       // just exposed ourselves to funds loss to our counterparty.
+                                                                       #[cfg(not(feature = "fuzztarget"))]
+                                                                       panic!("Client called ChannelManager::funding_transaction_generated with bogus transaction!");
+                                                               }
+                                                       }
+                                               }
                                                self.funding_tx_confirmations = 1;
                                                self.short_channel_id = Some(((height as u64)          << (5*8)) |
                                                                             ((*index_in_block as u64) << (2*8)) |
@@ -3524,9 +3545,9 @@ impl Writeable for Channel {
 
                (self.last_local_commitment_txn.len() as u64).write(writer)?;
                for tx in self.last_local_commitment_txn.iter() {
-                       if let Err(e) = tx.consensus_encode(&mut RawEncoder::new(WriterWriteAdaptor(writer))) {
+                       if let Err(e) = tx.consensus_encode(&mut WriterWriteAdaptor(writer)) {
                                match e {
-                                       network::serialize::Error::Io(e) => return Err(e),
+                                       encode::Error::Io(e) => return Err(e),
                                        _ => panic!("last_local_commitment_txn must have been well-formed!"),
                                }
                        }
@@ -3703,7 +3724,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
                let last_local_commitment_txn_count: u64 = Readable::read(reader)?;
                let mut last_local_commitment_txn = Vec::with_capacity(cmp::min(last_local_commitment_txn_count as usize, OUR_MAX_HTLCS as usize*2 + 1));
                for _ in 0..last_local_commitment_txn_count {
-                       last_local_commitment_txn.push(match Transaction::consensus_decode(&mut RawDecoder::new(reader.by_ref())) {
+                       last_local_commitment_txn.push(match Transaction::consensus_decode(reader.by_ref()) {
                                Ok(tx) => tx,
                                Err(_) => return Err(DecodeError::InvalidValue),
                        });
@@ -3831,7 +3852,7 @@ impl<R : ::std::io::Read> ReadableArgs<R, Arc<Logger>> for Channel {
 mod tests {
        use bitcoin::util::hash::{Sha256dHash, Hash160};
        use bitcoin::util::bip143;
-       use bitcoin::network::serialize::serialize;
+       use bitcoin::consensus::encode::serialize;
        use bitcoin::blockdata::script::{Script, Builder};
        use bitcoin::blockdata::transaction::Transaction;
        use bitcoin::blockdata::opcodes;
@@ -3953,7 +3974,7 @@ mod tests {
 
                                chan.sign_commitment_transaction(&mut unsigned_tx.0, &their_signature);
 
-                               assert_eq!(serialize(&unsigned_tx.0).unwrap()[..],
+                               assert_eq!(serialize(&unsigned_tx.0)[..],
                                                hex::decode($tx_hex).unwrap()[..]);
                        };
                }
@@ -3986,7 +4007,7 @@ mod tests {
                                }
 
                                chan.sign_htlc_transaction(&mut htlc_tx, &remote_signature, &preimage, &htlc, &keys).unwrap();
-                               assert_eq!(serialize(&htlc_tx).unwrap()[..],
+                               assert_eq!(serialize(&htlc_tx)[..],
                                                hex::decode($tx_hex).unwrap()[..]);
                        };
                }
index 0600c4e703cd82bdd3bb98a83f963f2e95817054..20a3779899a620b185723bdf78d7513017321ee4 100644 (file)
@@ -12,8 +12,7 @@ use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::Transaction;
 use bitcoin::blockdata::constants::genesis_block;
 use bitcoin::network::constants::Network;
-use bitcoin::network::serialize::BitcoinHash;
-use bitcoin::util::hash::Sha256dHash;
+use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
 
 use secp256k1::key::{SecretKey,PublicKey};
 use secp256k1::{Secp256k1,Message};
@@ -3210,7 +3209,7 @@ mod tests {
        use chain::chaininterface;
        use chain::transaction::OutPoint;
        use chain::chaininterface::{ChainListener, ChainWatchInterface};
-       use chain::keysinterface::KeysInterface;
+       use chain::keysinterface::{KeysInterface, SpendableOutputDescriptor};
        use chain::keysinterface;
        use ln::channel::{COMMITMENT_TX_BASE_WEIGHT, COMMITMENT_TX_WEIGHT_PER_HTLC};
        use ln::channelmanager::{ChannelManager,ChannelManagerReadArgs,OnionKeys,PaymentFailReason,RAACommitmentOrder};
@@ -3225,13 +3224,16 @@ mod tests {
        use util::ser::{Writeable, Writer, ReadableArgs};
        use util::config::UserConfig;
 
-       use bitcoin::util::hash::Sha256dHash;
+       use bitcoin::util::hash::{BitcoinHash, Sha256dHash};
+       use bitcoin::util::bip143;
+       use bitcoin::util::address::Address;
+       use bitcoin::util::bip32::{ChildNumber, ExtendedPubKey, ExtendedPrivKey};
        use bitcoin::blockdata::block::{Block, BlockHeader};
-       use bitcoin::blockdata::transaction::{Transaction, TxOut};
+       use bitcoin::blockdata::transaction::{Transaction, TxOut, TxIn, SigHashType};
+       use bitcoin::blockdata::script::{Builder, Script};
+       use bitcoin::blockdata::opcodes;
        use bitcoin::blockdata::constants::genesis_block;
        use bitcoin::network::constants::Network;
-       use bitcoin::network::serialize::serialize;
-       use bitcoin::network::serialize::BitcoinHash;
 
        use hex;
 
@@ -3532,7 +3534,7 @@ mod tests {
                                tx = Transaction { version: chan_id as u32, lock_time: 0, input: Vec::new(), output: vec![TxOut {
                                        value: *channel_value_satoshis, script_pubkey: output_script.clone(),
                                }]};
-                               funding_output = OutPoint::new(Sha256dHash::from_data(&serialize(&tx).unwrap()[..]), 0);
+                               funding_output = OutPoint::new(tx.txid(), 0);
 
                                node_a.node.funding_transaction_generated(&temporary_channel_id, funding_output);
                                let mut added_monitors = node_a.chan_monitor.added_monitors.lock().unwrap();
@@ -3682,7 +3684,7 @@ mod tests {
                }
        }
 
-       fn close_channel(outbound_node: &Node, inbound_node: &Node, channel_id: &[u8; 32], funding_tx: Transaction, close_inbound_first: bool) -> (msgs::ChannelUpdate, msgs::ChannelUpdate) {
+       fn close_channel(outbound_node: &Node, inbound_node: &Node, channel_id: &[u8; 32], funding_tx: Transaction, close_inbound_first: bool) -> (msgs::ChannelUpdate, msgs::ChannelUpdate, Transaction) {
                let (node_a, broadcaster_a, struct_a) = if close_inbound_first { (&inbound_node.node, &inbound_node.tx_broadcaster, inbound_node) } else { (&outbound_node.node, &outbound_node.tx_broadcaster, outbound_node) };
                let (node_b, broadcaster_b) = if close_inbound_first { (&outbound_node.node, &outbound_node.tx_broadcaster) } else { (&inbound_node.node, &inbound_node.tx_broadcaster) };
                let (tx_a, tx_b);
@@ -3745,7 +3747,7 @@ mod tests {
                assert_eq!(tx_a, tx_b);
                check_spends!(tx_a, funding_tx);
 
-               (as_update, bs_update)
+               (as_update, bs_update, tx_a)
        }
 
        struct SendEvent {
@@ -6229,7 +6231,7 @@ mod tests {
 
        /// pending_htlc_adds includes both the holding cell and in-flight update_add_htlcs, whereas
        /// for claims/fails they are separated out.
-       fn reconnect_nodes(node_a: &Node, node_b: &Node, pre_all_htlcs: bool, pending_htlc_adds: (i64, i64), pending_htlc_claims: (usize, usize), pending_cell_htlc_claims: (usize, usize), pending_cell_htlc_fails: (usize, usize), pending_raa: (bool, bool)) {
+       fn reconnect_nodes(node_a: &Node, node_b: &Node, send_funding_locked: (bool, bool), pending_htlc_adds: (i64, i64), pending_htlc_claims: (usize, usize), pending_cell_htlc_claims: (usize, usize), pending_cell_htlc_fails: (usize, usize), pending_raa: (bool, bool)) {
                node_a.node.peer_connected(&node_b.node.get_our_node_id());
                let reestablish_1 = get_chan_reestablish_msgs!(node_a, node_b);
                node_b.node.peer_connected(&node_a.node.get_our_node_id());
@@ -6262,7 +6264,7 @@ mod tests {
                        (pending_htlc_adds.1 == 0 && pending_htlc_claims.1 == 0 && pending_cell_htlc_claims.1 == 0 && pending_cell_htlc_fails.1 == 0));
 
                for chan_msgs in resp_1.drain(..) {
-                       if pre_all_htlcs {
+                       if send_funding_locked.0 {
                                node_a.node.handle_funding_locked(&node_b.node.get_our_node_id(), &chan_msgs.0.unwrap()).unwrap();
                                let announcement_event = node_a.node.get_and_clear_pending_msg_events();
                                if !announcement_event.is_empty() {
@@ -6319,7 +6321,7 @@ mod tests {
                }
 
                for chan_msgs in resp_2.drain(..) {
-                       if pre_all_htlcs {
+                       if send_funding_locked.1 {
                                node_b.node.handle_funding_locked(&node_a.node.get_our_node_id(), &chan_msgs.0.unwrap()).unwrap();
                                let announcement_event = node_b.node.get_and_clear_pending_msg_events();
                                if !announcement_event.is_empty() {
@@ -6383,7 +6385,7 @@ mod tests {
 
                nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-               reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
 
                let payment_preimage_1 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).0;
                let payment_hash_2 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).1;
@@ -6392,7 +6394,7 @@ mod tests {
 
                nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-               reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
 
                let payment_preimage_3 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).0;
                let payment_preimage_4 = route_payment(&nodes[0], &vec!(&nodes[1], &nodes[2])[..], 1000000).0;
@@ -6405,7 +6407,7 @@ mod tests {
                claim_payment_along_route(&nodes[0], &vec!(&nodes[1], &nodes[2]), true, payment_preimage_3);
                fail_payment_along_route(&nodes[0], &[&nodes[1], &nodes[2]], true, payment_hash_5);
 
-               reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (1, 0), (1, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (1, 0), (1, 0), (false, false));
                {
                        let events = nodes[0].node.get_and_clear_pending_events();
                        assert_eq!(events.len(), 2);
@@ -6486,19 +6488,19 @@ mod tests {
                if messages_delivered < 3 {
                        // Even if the funding_locked messages get exchanged, as long as nothing further was
                        // received on either side, both sides will need to resend them.
-                       reconnect_nodes(&nodes[0], &nodes[1], true, (0, 1), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 1), (0, 0), (0, 0), (0, 0), (false, false));
                } else if messages_delivered == 3 {
                        // nodes[0] still wants its RAA + commitment_signed
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (-1, 0), (0, 0), (0, 0), (0, 0), (true, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (-1, 0), (0, 0), (0, 0), (0, 0), (true, false));
                } else if messages_delivered == 4 {
                        // nodes[0] still wants its commitment_signed
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (-1, 0), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (-1, 0), (0, 0), (0, 0), (0, 0), (false, false));
                } else if messages_delivered == 5 {
                        // nodes[1] still wants its final RAA
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, true));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, true));
                } else if messages_delivered == 6 {
                        // Everything was delivered...
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
                }
 
                let events_1 = nodes[1].node.get_and_clear_pending_events();
@@ -6510,7 +6512,7 @@ mod tests {
 
                nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-               reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
 
                nodes[1].node.channel_state.lock().unwrap().next_forward = Instant::now();
                nodes[1].node.process_pending_htlc_forwards();
@@ -6584,7 +6586,7 @@ mod tests {
                nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
                if messages_delivered < 2 {
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (1, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (1, 0), (0, 0), (0, 0), (false, false));
                        //TODO: Deduplicate PaymentSent events, then enable this if:
                        //if messages_delivered < 1 {
                                let events_4 = nodes[0].node.get_and_clear_pending_events();
@@ -6598,21 +6600,21 @@ mod tests {
                        //}
                } else if messages_delivered == 2 {
                        // nodes[0] still wants its RAA + commitment_signed
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, -1), (0, 0), (0, 0), (0, 0), (false, true));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, -1), (0, 0), (0, 0), (0, 0), (false, true));
                } else if messages_delivered == 3 {
                        // nodes[0] still wants its commitment_signed
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, -1), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, -1), (0, 0), (0, 0), (0, 0), (false, false));
                } else if messages_delivered == 4 {
                        // nodes[1] still wants its final RAA
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (true, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (true, false));
                } else if messages_delivered == 5 {
                        // Everything was delivered...
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
                }
 
                nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-               reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
 
                // Channel should still work fine...
                let payment_preimage_2 = send_along_route(&nodes[0], route, &[&nodes[1]], 1000000).0;
@@ -6653,20 +6655,28 @@ mod tests {
                        _ => panic!("Unexpected event"),
                }
 
+               reconnect_nodes(&nodes[0], &nodes[1], (false, true), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+
+               nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
+               nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
+
                confirm_transaction(&nodes[1].chain_monitor, &tx, tx.version);
                let events_2 = nodes[1].node.get_and_clear_pending_msg_events();
-               assert_eq!(events_2.len(), 1);
+               assert_eq!(events_2.len(), 2);
                match events_2[0] {
                        MessageSendEvent::SendFundingLocked { ref node_id, msg: _ } => {
                                assert_eq!(*node_id, nodes[0].node.get_our_node_id());
                        },
                        _ => panic!("Unexpected event"),
                }
+               match events_2[1] {
+                       MessageSendEvent::SendAnnouncementSignatures { ref node_id, msg: _ } => {
+                               assert_eq!(*node_id, nodes[0].node.get_our_node_id());
+                       },
+                       _ => panic!("Unexpected event"),
+               }
 
-               reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
-               nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
-               nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-               reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
 
                // TODO: We shouldn't need to manually pass list_usable_chanels here once we support
                // rebroadcasting announcement_signatures upon reconnect.
@@ -6869,7 +6879,7 @@ mod tests {
                if disconnect {
                        nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                        nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-                       reconnect_nodes(&nodes[0], &nodes[1], true, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (true, true), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
                }
 
                *nodes[0].chan_monitor.update_ret.lock().unwrap() = Ok(());
@@ -6910,7 +6920,7 @@ mod tests {
                if disconnect {
                        nodes[0].node.peer_disconnected(&nodes[1].node.get_our_node_id(), false);
                        nodes[1].node.peer_disconnected(&nodes[0].node.get_our_node_id(), false);
-                       reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+                       reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
                }
 
                // ...and make sure we can force-close a TemporaryFailure channel with a PermanentFailure
@@ -7470,7 +7480,7 @@ mod tests {
                nodes[0].node = Arc::new(nodes_0_deserialized);
                check_added_monitors!(nodes[0], 1);
 
-               reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
 
                fail_payment(&nodes[0], &[&nodes[1]], our_payment_hash);
                claim_payment(&nodes[0], &[&nodes[1]], our_payment_preimage);
@@ -7540,8 +7550,8 @@ mod tests {
                nodes[0].node = Arc::new(nodes_0_deserialized);
 
                // nodes[1] and nodes[2] have no lost state with nodes[0]...
-               reconnect_nodes(&nodes[0], &nodes[1], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
-               reconnect_nodes(&nodes[0], &nodes[2], false, (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[1], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
+               reconnect_nodes(&nodes[0], &nodes[2], (false, false), (0, 0), (0, 0), (0, 0), (0, 0), (false, false));
                //... and we can even still claim the payment!
                claim_payment(&nodes[2], &[&nodes[0], &nodes[1]], our_payment_preimage);
 
@@ -7552,4 +7562,467 @@ mod tests {
                        assert_eq!(msg.channel_id, channel_id);
                } else { panic!("Unexpected result"); }
        }
+
+       macro_rules! check_dynamic_output_p2wsh {
+               ($node: expr) => {
+                       {
+                               let events = $node.chan_monitor.simple_monitor.get_and_clear_pending_events();
+                               let mut txn = Vec::new();
+                               for event in events {
+                                       match event {
+                                               Event::SpendableOutputs { ref outputs } => {
+                                                       for outp in outputs {
+                                                               match *outp {
+                                                                       SpendableOutputDescriptor::DynamicOutputP2WSH { ref outpoint, ref key, ref witness_script, ref to_self_delay, ref output } => {
+                                                                               let input = TxIn {
+                                                                                       previous_output: outpoint.clone(),
+                                                                                       script_sig: Script::new(),
+                                                                                       sequence: *to_self_delay as u32,
+                                                                                       witness: Vec::new(),
+                                                                               };
+                                                                               let outp = TxOut {
+                                                                                       script_pubkey: Builder::new().push_opcode(opcodes::All::OP_RETURN).into_script(),
+                                                                                       value: output.value,
+                                                                               };
+                                                                               let mut spend_tx = Transaction {
+                                                                                       version: 2,
+                                                                                       lock_time: 0,
+                                                                                       input: vec![input],
+                                                                                       output: vec![outp],
+                                                                               };
+                                                                               let secp_ctx = Secp256k1::new();
+                                                                               let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], witness_script, output.value)[..]).unwrap();
+                                                                               let local_delaysig = secp_ctx.sign(&sighash, key);
+                                                                               spend_tx.input[0].witness.push(local_delaysig.serialize_der(&secp_ctx).to_vec());
+                                                                               spend_tx.input[0].witness[0].push(SigHashType::All as u8);
+                                                                               spend_tx.input[0].witness.push(vec!(0));
+                                                                               spend_tx.input[0].witness.push(witness_script.clone().into_bytes());
+                                                                               txn.push(spend_tx);
+                                                                       },
+                                                                       _ => panic!("Unexpected event"),
+                                                               }
+                                                       }
+                                               },
+                                               _ => panic!("Unexpected event"),
+                                       };
+                               }
+                               txn
+                       }
+               }
+       }
+
+       macro_rules! check_dynamic_output_p2wpkh {
+               ($node: expr) => {
+                       {
+                               let events = $node.chan_monitor.simple_monitor.get_and_clear_pending_events();
+                               let mut txn = Vec::new();
+                               for event in events {
+                                       match event {
+                                               Event::SpendableOutputs { ref outputs } => {
+                                                       for outp in outputs {
+                                                               match *outp {
+                                                                       SpendableOutputDescriptor::DynamicOutputP2WPKH { ref outpoint, ref key, ref output } => {
+                                                                               let input = TxIn {
+                                                                                       previous_output: outpoint.clone(),
+                                                                                       script_sig: Script::new(),
+                                                                                       sequence: 0,
+                                                                                       witness: Vec::new(),
+                                                                               };
+                                                                               let outp = TxOut {
+                                                                                       script_pubkey: Builder::new().push_opcode(opcodes::All::OP_RETURN).into_script(),
+                                                                                       value: output.value,
+                                                                               };
+                                                                               let mut spend_tx = Transaction {
+                                                                                       version: 2,
+                                                                                       lock_time: 0,
+                                                                                       input: vec![input],
+                                                                                       output: vec![outp],
+                                                                               };
+                                                                               let secp_ctx = Secp256k1::new();
+                                                                               let remotepubkey = PublicKey::from_secret_key(&secp_ctx, &key);
+                                                                               let witness_script = Address::p2pkh(&remotepubkey, Network::Testnet).script_pubkey();
+                                                                               let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], &witness_script, output.value)[..]).unwrap();
+                                                                               let remotesig = secp_ctx.sign(&sighash, key);
+                                                                               spend_tx.input[0].witness.push(remotesig.serialize_der(&secp_ctx).to_vec());
+                                                                               spend_tx.input[0].witness[0].push(SigHashType::All as u8);
+                                                                               spend_tx.input[0].witness.push(remotepubkey.serialize().to_vec());
+                                                                               txn.push(spend_tx);
+                                                                       },
+                                                                       _ => panic!("Unexpected event"),
+                                                               }
+                                                       }
+                                               },
+                                               _ => panic!("Unexpected event"),
+                                       };
+                               }
+                               txn
+                       }
+               }
+       }
+
+       macro_rules! check_static_output {
+               ($event: expr, $node: expr, $event_idx: expr, $output_idx: expr, $der_idx: expr, $idx_node: expr) => {
+                       match $event[$event_idx] {
+                               Event::SpendableOutputs { ref outputs } => {
+                                       match outputs[$output_idx] {
+                                               SpendableOutputDescriptor::StaticOutput { ref outpoint, ref output } => {
+                                                       let secp_ctx = Secp256k1::new();
+                                                       let input = TxIn {
+                                                               previous_output: outpoint.clone(),
+                                                               script_sig: Script::new(),
+                                                               sequence: 0,
+                                                               witness: Vec::new(),
+                                                       };
+                                                       let outp = TxOut {
+                                                               script_pubkey: Builder::new().push_opcode(opcodes::All::OP_RETURN).into_script(),
+                                                               value: output.value,
+                                                       };
+                                                       let mut spend_tx = Transaction {
+                                                               version: 2,
+                                                               lock_time: 0,
+                                                               input: vec![input],
+                                                               output: vec![outp.clone()],
+                                                       };
+                                                       let secret = {
+                                                               match ExtendedPrivKey::new_master(&secp_ctx, Network::Testnet, &$node[$idx_node].node_seed) {
+                                                                       Ok(master_key) => {
+                                                                               match master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx($der_idx)) {
+                                                                                       Ok(key) => key,
+                                                                                       Err(_) => panic!("Your RNG is busted"),
+                                                                               }
+                                                                       }
+                                                                       Err(_) => panic!("Your rng is busted"),
+                                                               }
+                                                       };
+                                                       let pubkey = ExtendedPubKey::from_private(&secp_ctx, &secret).public_key;
+                                                       let witness_script = Address::p2pkh(&pubkey, Network::Testnet).script_pubkey();
+                                                       let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], &witness_script, output.value)[..]).unwrap();
+                                                       let sig = secp_ctx.sign(&sighash, &secret.secret_key);
+                                                       spend_tx.input[0].witness.push(sig.serialize_der(&secp_ctx).to_vec());
+                                                       spend_tx.input[0].witness[0].push(SigHashType::All as u8);
+                                                       spend_tx.input[0].witness.push(pubkey.serialize().to_vec());
+                                                       spend_tx
+                                               },
+                                               _ => panic!("Unexpected event !"),
+                                       }
+                               },
+                               _ => panic!("Unexpected event !"),
+                       };
+               }
+       }
+
+       #[test]
+       fn test_claim_sizeable_push_msat() {
+               // Incidentally test SpendableOutput event generation due to detection of to_local output on commitment tx
+               let nodes = create_network(2);
+
+               let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000);
+               nodes[1].node.force_close_channel(&chan.2);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn.len(), 1);
+               check_spends!(node_txn[0], chan.3.clone());
+               assert_eq!(node_txn[0].output.len(), 2); // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
+
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![node_txn[0].clone()] }, 0);
+               let spend_txn = check_dynamic_output_p2wsh!(nodes[1]);
+               assert_eq!(spend_txn.len(), 1);
+               check_spends!(spend_txn[0], node_txn[0].clone());
+       }
+
+       #[test]
+       fn test_claim_on_remote_sizeable_push_msat() {
+               // Same test as precedent, just test on remote commitment tx, as per_commitment_point registration changes following you're funder/fundee and
+               // to_remote output is encumbered by a P2WPKH
+
+               let nodes = create_network(2);
+
+               let chan = create_announced_chan_between_nodes_with_value(&nodes, 0, 1, 100000, 99000000);
+               nodes[0].node.force_close_channel(&chan.2);
+               let events = nodes[0].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn.len(), 1);
+               check_spends!(node_txn[0], chan.3.clone());
+               assert_eq!(node_txn[0].output.len(), 2); // We can't force trimming of to_remote output as channel_reserve_satoshis block us to do so at channel opening
+
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![node_txn[0].clone()] }, 0);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let spend_txn = check_dynamic_output_p2wpkh!(nodes[1]);
+               assert_eq!(spend_txn.len(), 2);
+               assert_eq!(spend_txn[0], spend_txn[1]);
+               check_spends!(spend_txn[0], node_txn[0].clone());
+       }
+
+       #[test]
+       fn test_static_spendable_outputs_preimage_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
+
+               let commitment_tx = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
+               assert_eq!(commitment_tx[0].input.len(), 1);
+               assert_eq!(commitment_tx[0].input[0].previous_output.txid, chan_1.3.txid());
+
+               // Settle A's commitment tx on B's chain
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               assert!(nodes[1].node.claim_funds(payment_preimage));
+               check_added_monitors!(nodes[1], 1);
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![commitment_tx[0].clone()] }, 1);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::UpdateHTLCs { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               match events[1] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexepected event"),
+               }
+
+               // Check B's monitor was able to send back output descriptor event for preimage tx on A's commitment tx
+               let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap(); // ChannelManager : 1 (local commitment tx), ChannelMonitor: 2 (1 preimage tx) * 2 (block-rescan)
+               check_spends!(node_txn[0], commitment_tx[0].clone());
+               assert_eq!(node_txn[0], node_txn[2]);
+               assert_eq!(node_txn[0].input[0].witness.last().unwrap().len(), 133);
+               check_spends!(node_txn[1], chan_1.3.clone());
+
+               let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               let spend_tx = check_static_output!(events, nodes, 0, 0, 1, 1);
+               check_spends!(spend_tx, node_txn[0].clone());
+       }
+
+       #[test]
+       fn test_static_spendable_outputs_justice_tx_revoked_commitment_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
+               let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.iter().next().unwrap().1.last_local_commitment_txn.clone();
+               assert_eq!(revoked_local_txn[0].input.len(), 1);
+               assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
+
+               claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
+
+               let  header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let mut node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn.len(), 3);
+               assert_eq!(node_txn.pop().unwrap(), node_txn[0]);
+               assert_eq!(node_txn[0].input.len(), 2);
+               check_spends!(node_txn[0], revoked_local_txn[0].clone());
+
+               let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               let spend_tx = check_static_output!(events, nodes, 0, 0, 1, 1);
+               check_spends!(spend_tx, node_txn[0].clone());
+       }
+
+       #[test]
+       fn test_static_spendable_outputs_justice_tx_revoked_htlc_timeout_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
+               let revoked_local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
+               assert_eq!(revoked_local_txn[0].input.len(), 1);
+               assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
+
+               claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
+
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               // A will generate HTLC-Timeout from revoked commitment tx
+               nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
+               let events = nodes[0].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let revoked_htlc_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(revoked_htlc_txn.len(), 2);
+               assert_eq!(revoked_htlc_txn[0].input.len(), 1);
+               assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), 133);
+               check_spends!(revoked_htlc_txn[0], revoked_local_txn[0].clone());
+
+               // B will generate justice tx from A's revoked commitment/HTLC tx
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+
+               let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn.len(), 4);
+               assert_eq!(node_txn[3].input.len(), 1);
+               check_spends!(node_txn[3], revoked_htlc_txn[0].clone());
+
+               let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               // Check B's ChannelMonitor was able to generate the right spendable output descriptor
+               let spend_tx = check_static_output!(events, nodes, 1, 1, 1, 1);
+               check_spends!(spend_tx, node_txn[3].clone());
+       }
+
+       #[test]
+       fn test_static_spendable_outputs_justice_tx_revoked_htlc_success_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 3000000).0;
+               let revoked_local_txn = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
+               assert_eq!(revoked_local_txn[0].input.len(), 1);
+               assert_eq!(revoked_local_txn[0].input[0].previous_output.txid, chan_1.3.txid());
+
+               claim_payment(&nodes[0], &vec!(&nodes[1])[..], payment_preimage);
+
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               // B will generate HTLC-Success from revoked commitment tx
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone()] }, 1);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               let revoked_htlc_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+
+               assert_eq!(revoked_htlc_txn.len(), 2);
+               assert_eq!(revoked_htlc_txn[0].input.len(), 1);
+               assert_eq!(revoked_htlc_txn[0].input[0].witness.last().unwrap().len(), 138);
+               check_spends!(revoked_htlc_txn[0], revoked_local_txn[0].clone());
+
+               // A will generate justice tx from B's revoked commitment/HTLC tx
+               nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![revoked_local_txn[0].clone(), revoked_htlc_txn[0].clone()] }, 1);
+               let events = nodes[0].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+
+               let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn.len(), 4);
+               assert_eq!(node_txn[3].input.len(), 1);
+               check_spends!(node_txn[3], revoked_htlc_txn[0].clone());
+
+               let events = nodes[0].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               // Check A's ChannelMonitor was able to generate the right spendable output descriptor
+               let spend_tx = check_static_output!(events, nodes, 1, 2, 1, 0);
+               check_spends!(spend_tx, node_txn[3].clone());
+       }
+
+       #[test]
+       fn test_dynamic_spendable_outputs_local_htlc_success_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               let payment_preimage = route_payment(&nodes[0], &vec!(&nodes[1])[..], 9000000).0;
+               let local_txn = nodes[1].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
+               assert_eq!(local_txn[0].input.len(), 1);
+               check_spends!(local_txn[0], chan_1.3.clone());
+
+               // Give B knowledge of preimage to be able to generate a local HTLC-Success Tx
+               nodes[1].node.claim_funds(payment_preimage);
+               check_added_monitors!(nodes[1], 1);
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![local_txn[0].clone()] }, 1);
+               let events = nodes[1].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::UpdateHTLCs { .. } => {},
+                       _ => panic!("Unexpected event"),
+               }
+               match events[1] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexepected event"),
+               }
+               let node_txn = nodes[1].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn[0].input.len(), 1);
+               assert_eq!(node_txn[0].input[0].witness.last().unwrap().len(), 138);
+               check_spends!(node_txn[0], local_txn[0].clone());
+
+               // Verify that B is able to spend its own HTLC-Success tx thanks to spendable output event given back by its ChannelMonitor
+               let spend_txn = check_dynamic_output_p2wsh!(nodes[1]);
+               assert_eq!(spend_txn.len(), 1);
+               check_spends!(spend_txn[0], node_txn[0].clone());
+       }
+
+       #[test]
+       fn test_dynamic_spendable_outputs_local_htlc_timeout_tx() {
+               let nodes = create_network(2);
+
+               // Create some initial channels
+               let chan_1 = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               route_payment(&nodes[0], &vec!(&nodes[1])[..], 9000000).0;
+               let local_txn = nodes[0].node.channel_state.lock().unwrap().by_id.get(&chan_1.2).unwrap().last_local_commitment_txn.clone();
+               assert_eq!(local_txn[0].input.len(), 1);
+               check_spends!(local_txn[0], chan_1.3.clone());
+
+               // Timeout HTLC on A's chain and so it can generate a HTLC-Timeout tx
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![local_txn[0].clone()] }, 200);
+               let events = nodes[0].node.get_and_clear_pending_msg_events();
+               match events[0] {
+                       MessageSendEvent::BroadcastChannelUpdate { .. } => {},
+                       _ => panic!("Unexepected event"),
+               }
+               let node_txn = nodes[0].tx_broadcaster.txn_broadcasted.lock().unwrap();
+               assert_eq!(node_txn[0].input.len(), 1);
+               assert_eq!(node_txn[0].input[0].witness.last().unwrap().len(), 133);
+               check_spends!(node_txn[0], local_txn[0].clone());
+
+               // Verify that A is able to spend its own HTLC-Timeout tx thanks to spendable output event given back by its ChannelMonitor
+               let spend_txn = check_dynamic_output_p2wsh!(nodes[0]);
+               assert_eq!(spend_txn.len(), 4);
+               assert_eq!(spend_txn[0], spend_txn[2]);
+               assert_eq!(spend_txn[1], spend_txn[3]);
+               check_spends!(spend_txn[0], local_txn[0].clone());
+               check_spends!(spend_txn[1], node_txn[0].clone());
+       }
+
+       #[test]
+       fn test_static_output_closing_tx() {
+               let nodes = create_network(2);
+
+               let chan = create_announced_chan_between_nodes(&nodes, 0, 1);
+
+               send_payment(&nodes[0], &vec!(&nodes[1])[..], 8000000);
+               let closing_tx = close_channel(&nodes[0], &nodes[1], &chan.2, chan.3, true).2;
+
+               let header = BlockHeader { version: 0x20000000, prev_blockhash: Default::default(), merkle_root: Default::default(), time: 42, bits: 42, nonce: 42 };
+               nodes[0].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![closing_tx.clone()] }, 1);
+               let events = nodes[0].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               let spend_tx = check_static_output!(events, nodes, 0, 0, 2, 0);
+               check_spends!(spend_tx, closing_tx.clone());
+
+               nodes[1].chain_monitor.block_connected_with_filtering(&Block { header, txdata: vec![closing_tx.clone()] }, 1);
+               let events = nodes[1].chan_monitor.simple_monitor.get_and_clear_pending_events();
+               let spend_tx = check_static_output!(events, nodes, 0, 0, 2, 1);
+               check_spends!(spend_tx, closing_tx);
+       }
 }
index 5d1e4e09516b73200ed3834ae1190975ba28e2de..7f584aeba804e3b86ee3a12c18ee9aabb12ae61a 100644 (file)
 use bitcoin::blockdata::block::BlockHeader;
 use bitcoin::blockdata::transaction::{TxIn,TxOut,SigHashType,Transaction};
 use bitcoin::blockdata::transaction::OutPoint as BitcoinOutPoint;
-use bitcoin::blockdata::script::Script;
-use bitcoin::network::serialize;
-use bitcoin::network::serialize::BitcoinHash;
-use bitcoin::network::encodable::{ConsensusDecodable, ConsensusEncodable};
-use bitcoin::util::hash::Sha256dHash;
+use bitcoin::blockdata::script::{Script, Builder};
+use bitcoin::blockdata::opcodes;
+use bitcoin::consensus::encode::{self, Decodable, Encodable};
+use bitcoin::util::hash::{Hash160, BitcoinHash,Sha256dHash};
 use bitcoin::util::bip143;
 
 use crypto::digest::Digest;
@@ -221,6 +220,8 @@ enum KeyStorage {
                revocation_base_key: SecretKey,
                htlc_base_key: SecretKey,
                delayed_payment_base_key: SecretKey,
+               payment_base_key: SecretKey,
+               shutdown_pubkey: PublicKey,
                prev_latest_per_commitment_point: Option<PublicKey>,
                latest_per_commitment_point: Option<PublicKey>,
        },
@@ -340,7 +341,7 @@ impl PartialEq for ChannelMonitor {
 }
 
 impl ChannelMonitor {
-       pub(super) fn new(revocation_base_key: &SecretKey, delayed_payment_base_key: &SecretKey, htlc_base_key: &SecretKey, our_to_self_delay: u16, destination_script: Script, logger: Arc<Logger>) -> ChannelMonitor {
+       pub(super) fn new(revocation_base_key: &SecretKey, delayed_payment_base_key: &SecretKey, htlc_base_key: &SecretKey, payment_base_key: &SecretKey, shutdown_pubkey: &PublicKey, our_to_self_delay: u16, destination_script: Script, logger: Arc<Logger>) -> ChannelMonitor {
                ChannelMonitor {
                        funding_txo: None,
                        commitment_transaction_number_obscure_factor: 0,
@@ -349,6 +350,8 @@ impl ChannelMonitor {
                                revocation_base_key: revocation_base_key.clone(),
                                htlc_base_key: htlc_base_key.clone(),
                                delayed_payment_base_key: delayed_payment_base_key.clone(),
+                               payment_base_key: payment_base_key.clone(),
+                               shutdown_pubkey: shutdown_pubkey.clone(),
                                prev_latest_per_commitment_point: None,
                                latest_per_commitment_point: None,
                        },
@@ -402,12 +405,10 @@ impl ChannelMonitor {
                res
        }
 
-       /// Inserts a revocation secret into this channel monitor. Also optionally tracks the next
-       /// revocation point which may be required to claim HTLC outputs which we know the preimage of
-       /// in case the remote end force-closes using their latest state. Prunes old preimages if neither
+       /// Inserts a revocation secret into this channel monitor. Prunes old preimages if neither
        /// needed by local commitment transactions HTCLs nor by remote ones. Unless we haven't already seen remote
        /// commitment transaction's secret, they are de facto pruned (we can use revocation key).
-       pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32], their_next_revocation_point: Option<(u64, PublicKey)>) -> Result<(), HandleError> {
+       pub(super) fn provide_secret(&mut self, idx: u64, secret: [u8; 32]) -> Result<(), HandleError> {
                let pos = ChannelMonitor::place_secret(idx);
                for i in 0..pos {
                        let (old_secret, old_idx) = self.old_secrets[i as usize];
@@ -417,27 +418,6 @@ impl ChannelMonitor {
                }
                self.old_secrets[pos as usize] = (secret, idx);
 
-               if let Some(new_revocation_point) = their_next_revocation_point {
-                       match self.their_cur_revocation_points {
-                               Some(old_points) => {
-                                       if old_points.0 == new_revocation_point.0 + 1 {
-                                               self.their_cur_revocation_points = Some((old_points.0, old_points.1, Some(new_revocation_point.1)));
-                                       } else if old_points.0 == new_revocation_point.0 + 2 {
-                                               if let Some(old_second_point) = old_points.2 {
-                                                       self.their_cur_revocation_points = Some((old_points.0 - 1, old_second_point, Some(new_revocation_point.1)));
-                                               } else {
-                                                       self.their_cur_revocation_points = Some((new_revocation_point.0, new_revocation_point.1, None));
-                                               }
-                                       } else {
-                                               self.their_cur_revocation_points = Some((new_revocation_point.0, new_revocation_point.1, None));
-                                       }
-                               },
-                               None => {
-                                       self.their_cur_revocation_points = Some((new_revocation_point.0, new_revocation_point.1, None));
-                               }
-                       }
-               }
-
                if !self.payment_preimages.is_empty() {
                        let local_signed_commitment_tx = self.current_local_signed_commitment_tx.as_ref().expect("Channel needs at least an initial commitment tx !");
                        let prev_local_signed_commitment_tx = self.prev_local_signed_commitment_tx.as_ref();
@@ -473,6 +453,32 @@ impl ChannelMonitor {
                Ok(())
        }
 
+       /// Tracks the next revocation point which may be required to claim HTLC outputs which we know
+       /// the preimage of in case the remote end force-closes using their latest state. When called at
+       /// channel opening revocation point is the CURRENT one used for first commitment tx. Needed in case of sizeable push_msat.
+       pub(super) fn provide_their_next_revocation_point(&mut self, their_next_revocation_point: Option<(u64, PublicKey)>) {
+               if let Some(new_revocation_point) = their_next_revocation_point {
+                       match self.their_cur_revocation_points {
+                               Some(old_points) => {
+                                       if old_points.0 == new_revocation_point.0 + 1 {
+                                               self.their_cur_revocation_points = Some((old_points.0, old_points.1, Some(new_revocation_point.1)));
+                                       } else if old_points.0 == new_revocation_point.0 + 2 {
+                                               if let Some(old_second_point) = old_points.2 {
+                                                       self.their_cur_revocation_points = Some((old_points.0 - 1, old_second_point, Some(new_revocation_point.1)));
+                                               } else {
+                                                       self.their_cur_revocation_points = Some((new_revocation_point.0, new_revocation_point.1, None));
+                                               }
+                                       } else {
+                                               self.their_cur_revocation_points = Some((new_revocation_point.0, new_revocation_point.1, None));
+                                       }
+                               },
+                               None => {
+                                       self.their_cur_revocation_points = Some((new_revocation_point.0, new_revocation_point.1, None));
+                               }
+                       }
+               }
+       }
+
        /// Informs this monitor of the latest remote (ie non-broadcastable) commitment transaction.
        /// The monitor watches for it to be broadcasted and then uses the HTLC information (and
        /// possibly future revocation/preimage information) to claim outputs where possible.
@@ -509,11 +515,13 @@ impl ChannelMonitor {
                        feerate_per_kw,
                        htlc_outputs,
                });
-               self.key_storage = if let KeyStorage::PrivMode { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, prev_latest_per_commitment_point: _, ref latest_per_commitment_point } = self.key_storage {
+               self.key_storage = if let KeyStorage::PrivMode { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref latest_per_commitment_point, .. } = self.key_storage {
                        KeyStorage::PrivMode {
                                revocation_base_key: *revocation_base_key,
                                htlc_base_key: *htlc_base_key,
                                delayed_payment_base_key: *delayed_payment_base_key,
+                               payment_base_key: *payment_base_key,
+                               shutdown_pubkey: *shutdown_pubkey,
                                prev_latest_per_commitment_point: *latest_per_commitment_point,
                                latest_per_commitment_point: Some(local_keys.per_commitment_point),
                        }
@@ -542,7 +550,16 @@ impl ChannelMonitor {
                let other_min_secret = other.get_min_seen_secret();
                let our_min_secret = self.get_min_seen_secret();
                if our_min_secret > other_min_secret {
-                       self.provide_secret(other_min_secret, other.get_secret(other_min_secret).unwrap(), None)?;
+                       self.provide_secret(other_min_secret, other.get_secret(other_min_secret).unwrap())?;
+               }
+               if let Some(ref local_tx) = self.current_local_signed_commitment_tx {
+                       if let Some(ref other_local_tx) = other.current_local_signed_commitment_tx {
+                               let our_commitment_number = 0xffffffffffff - ((((local_tx.tx.input[0].sequence as u64 & 0xffffff) << 3*8) | (local_tx.tx.lock_time as u64 & 0xffffff)) ^ self.commitment_transaction_number_obscure_factor);
+                               let other_commitment_number = 0xffffffffffff - ((((other_local_tx.tx.input[0].sequence as u64 & 0xffffff) << 3*8) | (other_local_tx.tx.lock_time as u64 & 0xffffff)) ^ other.commitment_transaction_number_obscure_factor);
+                               if our_commitment_number >= other_commitment_number {
+                                       self.key_storage = other.key_storage;
+                               }
+                       }
                }
                // TODO: We should use current_remote_commitment_number and the commitment number out of
                // local transactions to decide how to merge
@@ -559,6 +576,7 @@ impl ChannelMonitor {
                        }
                        self.payment_preimages = other.payment_preimages;
                }
+
                self.current_remote_commitment_number = cmp::min(self.current_remote_commitment_number, other.current_remote_commitment_number);
                Ok(())
        }
@@ -639,11 +657,13 @@ impl ChannelMonitor {
                U48(self.commitment_transaction_number_obscure_factor).write(writer)?;
 
                match self.key_storage {
-                       KeyStorage::PrivMode { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref prev_latest_per_commitment_point, ref latest_per_commitment_point } => {
+                       KeyStorage::PrivMode { ref revocation_base_key, ref htlc_base_key, ref delayed_payment_base_key, ref payment_base_key, ref shutdown_pubkey, ref prev_latest_per_commitment_point, ref latest_per_commitment_point } => {
                                writer.write_all(&[0; 1])?;
                                writer.write_all(&revocation_base_key[..])?;
                                writer.write_all(&htlc_base_key[..])?;
                                writer.write_all(&delayed_payment_base_key[..])?;
+                               writer.write_all(&payment_base_key[..])?;
+                               writer.write_all(&shutdown_pubkey.serialize())?;
                                if let Some(ref prev_latest_per_commitment_point) = *prev_latest_per_commitment_point {
                                        writer.write_all(&[1; 1])?;
                                        writer.write_all(&prev_latest_per_commitment_point.serialize())?;
@@ -731,9 +751,9 @@ impl ChannelMonitor {
 
                macro_rules! serialize_local_tx {
                        ($local_tx: expr) => {
-                               if let Err(e) = $local_tx.tx.consensus_encode(&mut serialize::RawEncoder::new(WriterWriteAdaptor(writer))) {
+                               if let Err(e) = $local_tx.tx.consensus_encode(&mut WriterWriteAdaptor(writer)) {
                                        match e {
-                                               serialize::Error::Io(e) => return Err(e),
+                                               encode::Error::Io(e) => return Err(e),
                                                _ => panic!("local tx must have been well-formed!"),
                                        }
                                }
@@ -908,7 +928,23 @@ impl ChannelMonitor {
                                        htlc_idxs.push(None);
                                        values.push(outp.value);
                                        total_value += outp.value;
-                                       break; // There can only be one of these
+                               } else if outp.script_pubkey.is_v0_p2wpkh() {
+                                       match self.key_storage {
+                                               KeyStorage::PrivMode { ref payment_base_key, .. } => {
+                                                       let per_commitment_point = PublicKey::from_secret_key(&self.secp_ctx, &per_commitment_key);
+                                                       if let Ok(local_key) = chan_utils::derive_private_key(&self.secp_ctx, &per_commitment_point, &payment_base_key) {
+                                                               spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WPKH {
+                                                                       outpoint: BitcoinOutPoint { txid: commitment_txid, vout: idx as u32 },
+                                                                       key: local_key,
+                                                                       output: outp.clone(),
+                                                               });
+                                                       }
+                                               }
+                                               KeyStorage::SigsMode { .. } => {
+                                                       //TODO: we need to ensure an offline client will generate the event when it
+                                                       // cames back online after only the watchtower saw the transaction
+                                               }
+                                       }
                                }
                        }
 
@@ -1046,6 +1082,28 @@ impl ChannelMonitor {
                                                Some(their_htlc_base_key) => ignore_error!(chan_utils::derive_public_key(&self.secp_ctx, revocation_point, &their_htlc_base_key)),
                                        };
 
+
+                                       for (idx, outp) in tx.output.iter().enumerate() {
+                                               if outp.script_pubkey.is_v0_p2wpkh() {
+                                                       match self.key_storage {
+                                                               KeyStorage::PrivMode { ref payment_base_key, .. } => {
+                                                                       if let Ok(local_key) = chan_utils::derive_private_key(&self.secp_ctx, &revocation_point, &payment_base_key) {
+                                                                               spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WPKH {
+                                                                                       outpoint: BitcoinOutPoint { txid: commitment_txid, vout: idx as u32 },
+                                                                                       key: local_key,
+                                                                                       output: outp.clone(),
+                                                                               });
+                                                                       }
+                                                               }
+                                                               KeyStorage::SigsMode { .. } => {
+                                                                       //TODO: we need to ensure an offline client will generate the event when it
+                                                                       // cames back online after only the watchtower saw the transaction
+                                                               }
+                                                       }
+                                                       break; // Only to_remote ouput is claimable
+                                               }
+                                       }
+
                                        let mut total_value = 0;
                                        let mut values = Vec::new();
                                        let mut inputs = Vec::new();
@@ -1232,6 +1290,34 @@ impl ChannelMonitor {
                let mut res = Vec::with_capacity(local_tx.htlc_outputs.len());
                let mut spendable_outputs = Vec::with_capacity(local_tx.htlc_outputs.len());
 
+               macro_rules! add_dynamic_output {
+                       ($father_tx: expr, $vout: expr) => {
+                               if let Some(ref per_commitment_point) = *per_commitment_point {
+                                       if let Some(ref delayed_payment_base_key) = *delayed_payment_base_key {
+                                               if let Ok(local_delayedkey) = chan_utils::derive_private_key(&self.secp_ctx, per_commitment_point, delayed_payment_base_key) {
+                                                       spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WSH {
+                                                               outpoint: BitcoinOutPoint { txid: $father_tx.txid(), vout: $vout },
+                                                               key: local_delayedkey,
+                                                               witness_script: chan_utils::get_revokeable_redeemscript(&local_tx.revocation_key, self.our_to_self_delay, &local_tx.delayed_payment_key),
+                                                               to_self_delay: self.our_to_self_delay,
+                                                               output: $father_tx.output[$vout as usize].clone(),
+                                                       });
+                                               }
+                                       }
+                               }
+                       }
+               }
+
+
+               let redeemscript = chan_utils::get_revokeable_redeemscript(&local_tx.revocation_key, self.their_to_self_delay.unwrap(), &local_tx.delayed_payment_key);
+               let revokeable_p2wsh = redeemscript.to_v0_p2wsh();
+               for (idx, output) in local_tx.tx.output.iter().enumerate() {
+                       if output.script_pubkey == revokeable_p2wsh {
+                               add_dynamic_output!(local_tx.tx, idx as u32);
+                               break;
+                       }
+               }
+
                for &(ref htlc, ref their_sig, ref our_sig) in local_tx.htlc_outputs.iter() {
                        if htlc.offered {
                                let mut htlc_timeout_tx = chan_utils::build_htlc_transaction(&local_tx.txid, local_tx.feerate_per_kw, self.their_to_self_delay.unwrap(), htlc, &local_tx.delayed_payment_key, &local_tx.revocation_key);
@@ -1246,18 +1332,7 @@ impl ChannelMonitor {
                                htlc_timeout_tx.input[0].witness.push(Vec::new());
                                htlc_timeout_tx.input[0].witness.push(chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &local_tx.a_htlc_key, &local_tx.b_htlc_key, &local_tx.revocation_key).into_bytes());
 
-                               if let Some(ref per_commitment_point) = *per_commitment_point {
-                                       if let Some(ref delayed_payment_base_key) = *delayed_payment_base_key {
-                                               if let Ok(local_delayedkey) = chan_utils::derive_private_key(&self.secp_ctx, per_commitment_point, delayed_payment_base_key) {
-                                                       spendable_outputs.push(SpendableOutputDescriptor::DynamicOutput {
-                                                               outpoint: BitcoinOutPoint { txid: htlc_timeout_tx.txid(), vout: 0 },
-                                                               local_delayedkey,
-                                                               witness_script: chan_utils::get_revokeable_redeemscript(&local_tx.revocation_key, self.our_to_self_delay, &local_tx.delayed_payment_key),
-                                                               to_self_delay: self.our_to_self_delay
-                                                       });
-                                               }
-                                       }
-                               }
+                               add_dynamic_output!(htlc_timeout_tx, 0);
                                res.push(htlc_timeout_tx);
                        } else {
                                if let Some(payment_preimage) = self.payment_preimages.get(&htlc.payment_hash) {
@@ -1273,18 +1348,7 @@ impl ChannelMonitor {
                                        htlc_success_tx.input[0].witness.push(payment_preimage.to_vec());
                                        htlc_success_tx.input[0].witness.push(chan_utils::get_htlc_redeemscript_with_explicit_keys(htlc, &local_tx.a_htlc_key, &local_tx.b_htlc_key, &local_tx.revocation_key).into_bytes());
 
-                                       if let Some(ref per_commitment_point) = *per_commitment_point {
-                                               if let Some(ref delayed_payment_base_key) = *delayed_payment_base_key {
-                                                       if let Ok(local_delayedkey) = chan_utils::derive_private_key(&self.secp_ctx, per_commitment_point, delayed_payment_base_key) {
-                                                               spendable_outputs.push(SpendableOutputDescriptor::DynamicOutput {
-                                                                       outpoint: BitcoinOutPoint { txid: htlc_success_tx.txid(), vout: 0 },
-                                                                       local_delayedkey,
-                                                                       witness_script: chan_utils::get_revokeable_redeemscript(&local_tx.revocation_key, self.our_to_self_delay, &local_tx.delayed_payment_key),
-                                                                       to_self_delay: self.our_to_self_delay
-                                                               });
-                                                       }
-                                               }
-                                       }
+                                       add_dynamic_output!(htlc_success_tx, 0);
                                        res.push(htlc_success_tx);
                                }
                        }
@@ -1301,7 +1365,7 @@ impl ChannelMonitor {
                if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx {
                        if local_tx.txid == commitment_txid {
                                match self.key_storage {
-                                       KeyStorage::PrivMode { revocation_base_key: _, htlc_base_key: _, ref delayed_payment_base_key, prev_latest_per_commitment_point: _, ref latest_per_commitment_point } => {
+                                       KeyStorage::PrivMode { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
                                                return self.broadcast_by_local_state(local_tx, latest_per_commitment_point, &Some(*delayed_payment_base_key));
                                        },
                                        KeyStorage::SigsMode { .. } => {
@@ -1313,7 +1377,7 @@ impl ChannelMonitor {
                if let &Some(ref local_tx) = &self.prev_local_signed_commitment_tx {
                        if local_tx.txid == commitment_txid {
                                match self.key_storage {
-                                       KeyStorage::PrivMode { revocation_base_key: _, htlc_base_key: _, ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
+                                       KeyStorage::PrivMode { ref delayed_payment_base_key, ref prev_latest_per_commitment_point, .. } => {
                                                return self.broadcast_by_local_state(local_tx, prev_latest_per_commitment_point, &Some(*delayed_payment_base_key));
                                        },
                                        KeyStorage::SigsMode { .. } => {
@@ -1325,6 +1389,31 @@ impl ChannelMonitor {
                (Vec::new(), Vec::new())
        }
 
+       /// Generate a spendable output event when closing_transaction get registered onchain.
+       fn check_spend_closing_transaction(&self, tx: &Transaction) -> Option<SpendableOutputDescriptor> {
+               if tx.input[0].sequence == 0xFFFFFFFF && tx.input[0].witness.last().unwrap().len() == 71 {
+                       match self.key_storage {
+                               KeyStorage::PrivMode { ref shutdown_pubkey, .. } =>  {
+                                       let our_channel_close_key_hash = Hash160::from_data(&shutdown_pubkey.serialize());
+                                       let shutdown_script = Builder::new().push_opcode(opcodes::All::OP_PUSHBYTES_0).push_slice(&our_channel_close_key_hash[..]).into_script();
+                                       for (idx, output) in tx.output.iter().enumerate() {
+                                               if shutdown_script == output.script_pubkey {
+                                                       return Some(SpendableOutputDescriptor::StaticOutput {
+                                                               outpoint: BitcoinOutPoint { txid: tx.txid(), vout: idx as u32 },
+                                                               output: output.clone(),
+                                                       });
+                                               }
+                                       }
+                               }
+                               KeyStorage::SigsMode { .. } => {
+                                       //TODO: we need to ensure an offline client will generate the event when it
+                                       // cames back online after only the watchtower saw the transaction
+                               }
+                       }
+               }
+               None
+       }
+
        /// Used by ChannelManager deserialization to broadcast the latest local state if it's copy of
        /// the Channel was out-of-date.
        pub(super) fn get_latest_local_commitment_txn(&self) -> Vec<Transaction> {
@@ -1365,6 +1454,11 @@ impl ChannelMonitor {
                                                spendable_outputs.append(&mut outputs);
                                                txn = remote_txn;
                                        }
+                                       if !self.funding_txo.is_none() && txn.is_empty() {
+                                               if let Some(spendable_output) = self.check_spend_closing_transaction(tx) {
+                                                       spendable_outputs.push(spendable_output);
+                                               }
+                                       }
                                } else {
                                        if let Some(&(commitment_number, _)) = self.remote_commitment_txn_on_chain.get(&prevout.txid) {
                                                let (tx, spendable_output) = self.check_spend_remote_htlc(tx, commitment_number);
@@ -1385,7 +1479,7 @@ impl ChannelMonitor {
                        if self.would_broadcast_at_height(height) {
                                broadcaster.broadcast_transaction(&cur_local_tx.tx);
                                match self.key_storage {
-                                       KeyStorage::PrivMode { revocation_base_key: _, htlc_base_key: _, ref delayed_payment_base_key, prev_latest_per_commitment_point: _, ref latest_per_commitment_point } => {
+                                       KeyStorage::PrivMode { ref delayed_payment_base_key, ref latest_per_commitment_point, .. } => {
                                                let (txs, mut outputs) = self.broadcast_by_local_state(&cur_local_tx, latest_per_commitment_point, &Some(*delayed_payment_base_key));
                                                spendable_outputs.append(&mut outputs);
                                                for tx in txs {
@@ -1473,6 +1567,8 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                let revocation_base_key = Readable::read(reader)?;
                                let htlc_base_key = Readable::read(reader)?;
                                let delayed_payment_base_key = Readable::read(reader)?;
+                               let payment_base_key = Readable::read(reader)?;
+                               let shutdown_pubkey = Readable::read(reader)?;
                                let prev_latest_per_commitment_point = match <u8 as Readable<R>>::read(reader)? {
                                        0 => None,
                                        1 => Some(Readable::read(reader)?),
@@ -1487,6 +1583,8 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                                        revocation_base_key,
                                        htlc_base_key,
                                        delayed_payment_base_key,
+                                       payment_base_key,
+                                       shutdown_pubkey,
                                        prev_latest_per_commitment_point,
                                        latest_per_commitment_point,
                                }
@@ -1579,10 +1677,10 @@ impl<R: ::std::io::Read> ReadableArgs<R, Arc<Logger>> for (Sha256dHash, ChannelM
                macro_rules! read_local_tx {
                        () => {
                                {
-                                       let tx = match Transaction::consensus_decode(&mut serialize::RawDecoder::new(reader.by_ref())) {
+                                       let tx = match Transaction::consensus_decode(reader.by_ref()) {
                                                Ok(tx) => tx,
                                                Err(e) => match e {
-                                                       serialize::Error::Io(ioe) => return Err(DecodeError::Io(ioe)),
+                                                       encode::Error::Io(ioe) => return Err(DecodeError::Io(ioe)),
                                                        _ => return Err(DecodeError::InvalidValue),
                                                },
                                        };
@@ -1716,335 +1814,335 @@ mod tests {
 
                {
                        // insert_secret correct sequence
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
-                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
-                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
-                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
-                       monitor.provide_secret(281474976710648, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
                }
 
                {
                        // insert_secret #1 incorrect
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #2 incorrect (#1 derived from incorrect)
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("dddc3a8d14fddf2b68fa8c7fbad2748274937479dd0f8930d5ebb4ab6bd866a3").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #3 incorrect
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c51a18b13e8527e579ec56365482c62f180b7d5760b46e9477dae59e87ed423a").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #4 incorrect (1,2,3 derived from incorrect)
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("02a40c85b6f28da08dfdbe0926c53fab2de6d28c10301f8f7c4073d5e42e3148").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("dddc3a8d14fddf2b68fa8c7fbad2748274937479dd0f8930d5ebb4ab6bd866a3").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c51a18b13e8527e579ec56365482c62f180b7d5760b46e9477dae59e87ed423a").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("ba65d7b0ef55a3ba300d4e87af29868f394f8f138d78a7011669c79b37b936f4").unwrap());
-                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
-                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
-                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
-                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #5 incorrect
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("631373ad5f9ef654bb3dade742d09504c567edd24320d2fcd68e3cc47e2ff6a6").unwrap());
-                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710650, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #6 incorrect (5 derived from incorrect)
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("631373ad5f9ef654bb3dade742d09504c567edd24320d2fcd68e3cc47e2ff6a6").unwrap());
-                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("b7e76a83668bde38b373970155c868a653304308f9896692f904a23731224bb1").unwrap());
-                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
-                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #7 incorrect
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
-                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
-                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("e7971de736e01da8ed58b94c2fc216cb1dca9e326f3a96e7194fe8ea8af6c0a3").unwrap());
-                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("05cde6323d949933f7f7b78776bcc1ea6d9b31447732e3802e1f7ac44b650e17").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
 
                {
                        // insert_secret #8 incorrect
-                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+                       monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                        secrets.clear();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710655, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710654, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710653, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710652, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("c65716add7aa98ba7acb236352d665cab17345fe45b55fb879ff80e6bd0c41dd").unwrap());
-                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710651, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("969660042a28f32d9be17344e09374b379962d03db1574df5a8a5a47e19ce3f2").unwrap());
-                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710650, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a5a64476122ca0925fb344bdc1854c1c0a59fc614298e50a33e331980a220f32").unwrap());
-                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone(), None).unwrap();
+                       monitor.provide_secret(281474976710649, secrets.last().unwrap().clone()).unwrap();
                        test_secrets!();
 
                        secrets.push([0; 32]);
                        secrets.last_mut().unwrap()[0..32].clone_from_slice(&hex::decode("a7efbc61aac46d34f77778bac22c8a20c6a46ca460addc49009bda875ec88fa4").unwrap());
-                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone(), None).unwrap_err().err,
+                       assert_eq!(monitor.provide_secret(281474976710648, secrets.last().unwrap().clone()).unwrap_err().err,
                                        "Previous secret did not match new one");
                }
        }
@@ -2123,7 +2221,7 @@ mod tests {
 
                // Prune with one old state and a local commitment tx holding a few overlaps with the
                // old state.
-               let mut monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), 0, Script::new(), logger.clone());
+               let mut monitor = ChannelMonitor::new(&SecretKey::from_slice(&secp_ctx, &[42; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[43; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &SecretKey::from_slice(&secp_ctx, &[44; 32]).unwrap(), &PublicKey::from_secret_key(&secp_ctx, &SecretKey::from_slice(&secp_ctx, &[45; 32]).unwrap()), 0, Script::new(), logger.clone());
                monitor.set_their_to_self_delay(10);
 
                monitor.provide_latest_local_commitment_tx_info(dummy_tx.clone(), dummy_keys!(), 0, preimages_to_local_htlcs!(preimages[0..10]));
@@ -2138,14 +2236,14 @@ mod tests {
                // Now provide a secret, pruning preimages 10-15
                let mut secret = [0; 32];
                secret[0..32].clone_from_slice(&hex::decode("7cc854b54e3e0dcdb010d7a3fee464a9687be6e8db3be6854c475621e007a5dc").unwrap());
-               monitor.provide_secret(281474976710655, secret.clone(), None).unwrap();
+               monitor.provide_secret(281474976710655, secret.clone()).unwrap();
                assert_eq!(monitor.payment_preimages.len(), 15);
                test_preimages_exist!(&preimages[0..10], monitor);
                test_preimages_exist!(&preimages[15..20], monitor);
 
                // Now provide a further secret, pruning preimages 15-17
                secret[0..32].clone_from_slice(&hex::decode("c7518c8ae4660ed02894df8976fa1a3659c1a8b4b5bec0c4b872abeba4cb8964").unwrap());
-               monitor.provide_secret(281474976710654, secret.clone(), None).unwrap();
+               monitor.provide_secret(281474976710654, secret.clone()).unwrap();
                assert_eq!(monitor.payment_preimages.len(), 13);
                test_preimages_exist!(&preimages[0..10], monitor);
                test_preimages_exist!(&preimages[17..20], monitor);
@@ -2154,7 +2252,7 @@ mod tests {
                // previous commitment tx's preimages too
                monitor.provide_latest_local_commitment_tx_info(dummy_tx.clone(), dummy_keys!(), 0, preimages_to_local_htlcs!(preimages[0..5]));
                secret[0..32].clone_from_slice(&hex::decode("2273e227a5b7449b6e70f1fb4652864038b1cbf9cd7c043a7d6456b7fc275ad8").unwrap());
-               monitor.provide_secret(281474976710653, secret.clone(), None).unwrap();
+               monitor.provide_secret(281474976710653, secret.clone()).unwrap();
                assert_eq!(monitor.payment_preimages.len(), 12);
                test_preimages_exist!(&preimages[0..10], monitor);
                test_preimages_exist!(&preimages[18..20], monitor);
@@ -2162,7 +2260,7 @@ mod tests {
                // But if we do it again, we'll prune 5-10
                monitor.provide_latest_local_commitment_tx_info(dummy_tx.clone(), dummy_keys!(), 0, preimages_to_local_htlcs!(preimages[0..3]));
                secret[0..32].clone_from_slice(&hex::decode("27cddaa5624534cb6cb9d7da077cf2b22ab21e9b506fd4998a51d54502e99116").unwrap());
-               monitor.provide_secret(281474976710652, secret.clone(), None).unwrap();
+               monitor.provide_secret(281474976710652, secret.clone()).unwrap();
                assert_eq!(monitor.payment_preimages.len(), 5);
                test_preimages_exist!(&preimages[0..5], monitor);
        }