From: Antoine Riard Date: Thu, 1 Nov 2018 03:22:56 +0000 (+0000) Subject: Add test_static_spendable_outputs_preimage_tx X-Git-Tag: v0.0.12~271^2~7 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3518f1f85d8a3daff451b3fe56cc7854b833e2bd;p=rust-lightning Add test_static_spendable_outputs_preimage_tx Aims to covered both keysinterace preimage tx case and detection of second remote commitment tx Split DynamicDescriptor between *P2WSH and *P2WKH --- diff --git a/src/chain/keysinterface.rs b/src/chain/keysinterface.rs index 7d669d9d7..8e71625df 100644 --- a/src/chain/keysinterface.rs +++ b/src/chain/keysinterface.rs @@ -37,21 +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 : /// 0 /// 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 : + /// + /// 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, } } diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 9f4932321..6172c5fff 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -436,7 +436,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, BREAKDOWN_TIMEOUT, keys_provider.get_destination_script(), logger.clone()); Ok(Channel { @@ -624,7 +624,7 @@ 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, 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))); diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 34077d1b1..ee689d532 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -3225,6 +3225,8 @@ mod tests { 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, TxIn, SigHashType}; use bitcoin::blockdata::script::{Builder, Script}; @@ -7536,7 +7538,7 @@ mod tests { } else { panic!("Unexpected result"); } } - macro_rules! check_dynamic_output { + macro_rules! check_dynamic_output_p2wsh { ($node: expr) => { { let events = $node.chan_monitor.simple_monitor.get_and_clear_pending_events(); @@ -7546,7 +7548,7 @@ mod tests { Event::SpendableOutputs { ref outputs } => { for outp in outputs { match *outp { - SpendableOutputDescriptor::DynamicOutput { ref outpoint, ref local_delayedkey, ref witness_script, ref to_self_delay, ref output } => { + 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(), @@ -7563,9 +7565,9 @@ mod tests { input: vec![input], output: vec![outp], }; - let sighash = Message::from_slice(&bip143::SighashComponents::new(&spend_tx).sighash_all(&spend_tx.input[0], witness_script, output.value)[..]).unwrap(); let secp_ctx = Secp256k1::new(); - let local_delaysig = secp_ctx.sign(&sighash, local_delayedkey); + 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)); @@ -7584,6 +7586,106 @@ mod tests { } } + 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 @@ -7603,8 +7705,48 @@ mod tests { 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!(nodes[1]); + 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_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()); + } } diff --git a/src/ln/channelmonitor.rs b/src/ln/channelmonitor.rs index 714e737de..dc390f5dd 100644 --- a/src/ln/channelmonitor.rs +++ b/src/ln/channelmonitor.rs @@ -219,6 +219,7 @@ enum KeyStorage { revocation_base_key: SecretKey, htlc_base_key: SecretKey, delayed_payment_base_key: SecretKey, + payment_base_key: SecretKey, prev_latest_per_commitment_point: Option, latest_per_commitment_point: Option, }, @@ -338,7 +339,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) -> ChannelMonitor { + pub(super) fn new(revocation_base_key: &SecretKey, delayed_payment_base_key: &SecretKey, htlc_base_key: &SecretKey, payment_base_key: &SecretKey, our_to_self_delay: u16, destination_script: Script, logger: Arc) -> ChannelMonitor { ChannelMonitor { funding_txo: None, commitment_transaction_number_obscure_factor: 0, @@ -347,6 +348,7 @@ 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(), prev_latest_per_commitment_point: None, latest_per_commitment_point: None, }, @@ -510,11 +512,12 @@ 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 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, prev_latest_per_commitment_point: *latest_per_commitment_point, latest_per_commitment_point: Some(local_keys.per_commitment_point), } @@ -640,11 +643,12 @@ 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 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[..])?; 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())?; @@ -909,7 +913,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 + } + } } } @@ -1047,6 +1067,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(); @@ -1238,9 +1280,9 @@ impl ChannelMonitor { 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 { + spendable_outputs.push(SpendableOutputDescriptor::DynamicOutputP2WSH { outpoint: BitcoinOutPoint { txid: $father_tx.txid(), vout: $vout }, - local_delayedkey, + 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(), @@ -1308,7 +1350,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 { .. } => { @@ -1320,7 +1362,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 { .. } => { @@ -1392,7 +1434,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 { @@ -1480,6 +1522,7 @@ impl ReadableArgs> 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 prev_latest_per_commitment_point = match >::read(reader)? { 0 => None, 1 => Some(Readable::read(reader)?), @@ -1494,6 +1537,7 @@ impl ReadableArgs> for (Sha256dHash, ChannelM revocation_base_key, htlc_base_key, delayed_payment_base_key, + payment_base_key, prev_latest_per_commitment_point, latest_per_commitment_point, } @@ -1723,7 +1767,7 @@ 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1769,7 +1813,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1785,7 +1829,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1811,7 +1855,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1837,7 +1881,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1883,7 +1927,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1919,7 +1963,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -1965,7 +2009,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -2011,7 +2055,7 @@ mod tests { { // 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(), 0, Script::new(), logger.clone()); secrets.clear(); secrets.push([0; 32]); @@ -2130,7 +2174,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(), 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]));