Stop needlessly returning &HTLCSource out of Channel.
authorMatt Corallo <git@bluematt.me>
Thu, 22 Nov 2018 21:17:46 +0000 (16:17 -0500)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Nov 2018 04:57:54 +0000 (23:57 -0500)
This moves a clone() inside Channel from ChannelManager making
references simpler for the coming refactors.

src/ln/channel.rs
src/ln/channelmanager.rs

index 3ddf44afa6a195981f870548d03de7078e4b690c..1ae3333c1aa862c9262375008003d47f9cc70681 100644 (file)
@@ -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<HTLCSource, ChannelError> {
                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<msgs::CommitmentSigned>, Option<msgs::ClosingSigned>, ChannelMonitor), ChannelError> {
index 32dc72f9cb43ffb22be64620a57e6b94071e25eb..d920825cb5e1e8facd44c6340ed9fae620b676fd 100644 (file)
@@ -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))
                };