X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fln%2Fchannelmonitor.rs;h=d24a5f528c0a2c45339bd8c537c29a051970a72a;hb=ba75b3ecd7f88a79ff6392a5229c4ab6c14a8591;hp=7a6bac9c7fba4bf30da188ef8842a569f986c4da;hpb=5a2ed0324738e170e0b3b4dab3431242c7221a13;p=rust-lightning diff --git a/lightning/src/ln/channelmonitor.rs b/lightning/src/ln/channelmonitor.rs index 7a6bac9c7..d24a5f528 100644 --- a/lightning/src/ln/channelmonitor.rs +++ b/lightning/src/ln/channelmonitor.rs @@ -833,8 +833,14 @@ impl PartialEq for ChannelMonitor { } impl ChannelMonitor { - /// Serializes into a vec, with various modes for the exposed pub fns - fn write(&self, writer: &mut W, for_local_storage: bool) -> Result<(), ::std::io::Error> { + /// Writes this monitor into the given writer, suitable for writing to disk. + /// + /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which + /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along + /// the "reorg path" (ie disconnecting blocks until you find a common ancestor from both the + /// returned block hash and the the current chain and then reconnecting blocks to get to the + /// best chain) upon deserializing the object! + pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { //TODO: We still write out all the serialization here manually instead of using the fancy //serialization framework we have, we should migrate things over to it. writer.write_all(&[SERIALIZATION_VERSION; 1])?; @@ -929,14 +935,10 @@ impl ChannelMonitor { } } - if for_local_storage { - writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?; - for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() { - writer.write_all(&payment_hash.0[..])?; - writer.write_all(&byte_utils::be48_to_array(*commitment_number))?; - } - } else { - writer.write_all(&byte_utils::be64_to_array(0))?; + writer.write_all(&byte_utils::be64_to_array(self.remote_hash_commitment_number.len() as u64))?; + for (ref payment_hash, commitment_number) in self.remote_hash_commitment_number.iter() { + writer.write_all(&payment_hash.0[..])?; + writer.write_all(&byte_utils::be48_to_array(*commitment_number))?; } macro_rules! serialize_local_tx { @@ -977,17 +979,8 @@ impl ChannelMonitor { writer.write_all(&[0; 1])?; } - if for_local_storage { - writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?; - } else { - writer.write_all(&byte_utils::be48_to_array(0))?; - } - - if for_local_storage { - writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?; - } else { - writer.write_all(&byte_utils::be48_to_array(0))?; - } + writer.write_all(&byte_utils::be48_to_array(self.current_remote_commitment_number))?; + writer.write_all(&byte_utils::be48_to_array(self.current_local_commitment_number))?; writer.write_all(&byte_utils::be64_to_array(self.payment_preimages.len() as u64))?; for payment_preimage in self.payment_preimages.values() { @@ -1039,28 +1032,6 @@ impl ChannelMonitor { Ok(()) } - - /// Writes this monitor into the given writer, suitable for writing to disk. - /// - /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which - /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - /// the "reorg path" (ie not just starting at the same height but starting at the highest - /// common block that appears on your best chain as well as on the chain which contains the - /// last block hash returned) upon deserializing the object! - pub fn write_for_disk(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, true) - } - - /// Encodes this monitor into the given writer, suitable for sending to a remote watchtower - /// - /// Note that the deserializer is only implemented for (Sha256dHash, ChannelMonitor), which - /// tells you the last block hash which was block_connect()ed. You MUST rescan any blocks along - /// the "reorg path" (ie not just starting at the same height but starting at the highest - /// common block that appears on your best chain as well as on the chain which contains the - /// last block hash returned) upon deserializing the object! - pub fn write_for_watchtower(&self, writer: &mut W) -> Result<(), ::std::io::Error> { - self.write(writer, false) - } } impl ChannelMonitor { @@ -1115,7 +1086,7 @@ impl ChannelMonitor { onchain_events_waiting_threshold_conf: HashMap::new(), outputs_to_watch: HashMap::new(), - onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, funding_redeemscript, their_to_self_delay, logger.clone()), + onchain_tx_handler: OnchainTxHandler::new(destination_script.clone(), keys, their_to_self_delay, logger.clone()), lockdown_from_offchain: false, @@ -1772,7 +1743,7 @@ impl ChannelMonitor { /// In any-case, choice is up to the user. pub fn get_latest_local_commitment_txn(&mut self) -> Vec { log_trace!(self, "Getting signed latest local commitment transaction!"); - if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_local_tx(self.channel_value_satoshis) { + if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_local_tx() { let txid = commitment_tx.txid(); let mut res = vec![commitment_tx]; if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx { @@ -1798,7 +1769,7 @@ impl ChannelMonitor { #[cfg(test)] pub fn unsafe_get_latest_local_commitment_txn(&mut self) -> Vec { log_trace!(self, "Getting signed copy of latest local commitment transaction!"); - if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_copy_local_tx(self.channel_value_satoshis) { + if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_copy_local_tx() { let txid = commitment_tx.txid(); let mut res = vec![commitment_tx]; if let &Some(ref local_tx) = &self.current_local_signed_commitment_tx { @@ -1884,7 +1855,7 @@ impl ChannelMonitor { } if let Some(ref cur_local_tx) = self.current_local_signed_commitment_tx { if should_broadcast { - if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_local_tx(self.channel_value_satoshis) { + if let Some(commitment_tx) = self.onchain_tx_handler.get_fully_signed_local_tx() { let (mut new_outpoints, new_outputs, _) = self.broadcast_by_local_state(&commitment_tx, cur_local_tx); if !new_outputs.is_empty() { watch_outputs.push((cur_local_tx.txid.clone(), new_outputs));