From: Matt Corallo Date: Sat, 28 Jul 2018 22:32:58 +0000 (-0400) Subject: Stop adding remote's payment_preimages to our channel monitor X-Git-Tag: v0.0.12~358^2 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=refs%2Fheads%2F2018-07-no-useless-preimages;p=rust-lightning Stop adding remote's payment_preimages to our channel monitor --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 6fdc1462a..3a442091c 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -1356,7 +1356,7 @@ impl Channel { Err(HandleError{err: "Remote tried to fulfill/fail an HTLC we couldn't find", action: None}) } - pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result { + pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<(), HandleError> { if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) { return Err(HandleError{err: "Got add HTLC message when channel was not in an operational state", action: None}); } @@ -1366,9 +1366,8 @@ impl Channel { let mut payment_hash = [0; 32]; sha.result(&mut payment_hash); - self.channel_monitor.provide_payment_preimage(&payment_hash, &msg.payment_preimage); self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None)?; - Ok(self.channel_monitor.clone()) + Ok(()) } pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<[u8; 32], HandleError> { diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index b1013ad12..6c349fd0e 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -1682,22 +1682,16 @@ impl ChannelMessageHandler for ChannelManager { // is broken, we may have enough info to get our own money! self.claim_funds_internal(msg.payment_preimage.clone(), false); - let monitor = { - let mut channel_state = self.channel_state.lock().unwrap(); - match channel_state.by_id.get_mut(&msg.channel_id) { - Some(chan) => { - if chan.get_their_node_id() != *their_node_id { - return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None}) - } - chan.update_fulfill_htlc(&msg)? - }, - None => return Err(HandleError{err: "Failed to find corresponding channel", action: None}) - } - }; - if let Err(_e) = self.monitor.add_update_monitor(monitor.get_funding_txo().unwrap(), monitor) { - unimplemented!(); + let mut channel_state = self.channel_state.lock().unwrap(); + match channel_state.by_id.get_mut(&msg.channel_id) { + Some(chan) => { + if chan.get_their_node_id() != *their_node_id { + return Err(HandleError{err: "Got a message for a channel from the wrong node!", action: None}) + } + chan.update_fulfill_htlc(&msg) + }, + None => return Err(HandleError{err: "Failed to find corresponding channel", action: None}) } - Ok(()) } fn handle_update_fail_htlc(&self, their_node_id: &PublicKey, msg: &msgs::UpdateFailHTLC) -> Result, HandleError> { @@ -2492,10 +2486,9 @@ mod tests { { let mut added_monitors = $node.chan_monitor.added_monitors.lock().unwrap(); if $last_node { - assert_eq!(added_monitors.len(), 1); + assert_eq!(added_monitors.len(), 0); } else { - assert_eq!(added_monitors.len(), 2); - assert!(added_monitors[0].0 != added_monitors[1].0); + assert_eq!(added_monitors.len(), 1); } added_monitors.clear(); }