From: Matt Corallo Date: Thu, 22 Nov 2018 21:17:46 +0000 (-0500) Subject: Stop needlessly returning &HTLCSource out of Channel. X-Git-Tag: v0.0.12~264^2~5 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=bac091cdb9cc01a7962dee3bdbc977e3bea0af0d;p=rust-lightning Stop needlessly returning &HTLCSource out of Channel. This moves a clone() inside Channel from ChannelManager making references simpler for the coming refactors. --- diff --git a/src/ln/channel.rs b/src/ln/channel.rs index 3ddf44af..1ae3333c 100644 --- a/src/ln/channel.rs +++ b/src/ln/channel.rs @@ -1604,7 +1604,7 @@ impl Channel { Err(ChannelError::Close("Remote tried to fulfill/fail an HTLC we couldn't find")) } - pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<&HTLCSource, ChannelError> { + pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result { if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) { return Err(ChannelError::Close("Got fulfill HTLC message when channel was not in an operational state")); } @@ -1617,10 +1617,10 @@ impl Channel { let mut payment_hash = [0; 32]; sha.result(&mut payment_hash); - self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None) + self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None).map(|source| source.clone()) } - pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<&HTLCSource, ChannelError> { + pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> { if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) { return Err(ChannelError::Close("Got fail HTLC message when channel was not in an operational state")); } @@ -1628,10 +1628,11 @@ impl Channel { return Err(ChannelError::Close("Peer sent update_fail_htlc when we needed a channel_reestablish")); } - self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason)) + self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))?; + Ok(()) } - pub fn update_fail_malformed_htlc<'a>(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<&HTLCSource, ChannelError> { + pub fn update_fail_malformed_htlc<'a>(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> { if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) { return Err(ChannelError::Close("Got fail malformed HTLC message when channel was not in an operational state")); } @@ -1639,7 +1640,8 @@ impl Channel { return Err(ChannelError::Close("Peer sent update_fail_malformed_htlc when we needed a channel_reestablish")); } - self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason)) + self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))?; + Ok(()) } pub fn commitment_signed(&mut self, msg: &msgs::CommitmentSigned, fee_estimator: &FeeEstimator) -> Result<(msgs::RevokeAndACK, Option, Option, ChannelMonitor), ChannelError> { diff --git a/src/ln/channelmanager.rs b/src/ln/channelmanager.rs index 32dc72f9..d920825c 100644 --- a/src/ln/channelmanager.rs +++ b/src/ln/channelmanager.rs @@ -2016,7 +2016,7 @@ impl ChannelManager { return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id)); } chan.update_fulfill_htlc(&msg) - .map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.channel_id))?.clone() + .map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.channel_id))? }, None => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id)) };