Skip to content

Commit bac091c

Browse files
committed
Stop needlessly returning &HTLCSource out of Channel.
This moves a clone() inside Channel from ChannelManager making references simpler for the coming refactors.
1 parent 6032099 commit bac091c

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

src/ln/channel.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ impl Channel {
16041604
Err(ChannelError::Close("Remote tried to fulfill/fail an HTLC we couldn't find"))
16051605
}
16061606

1607-
pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<&HTLCSource, ChannelError> {
1607+
pub fn update_fulfill_htlc(&mut self, msg: &msgs::UpdateFulfillHTLC) -> Result<HTLCSource, ChannelError> {
16081608
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
16091609
return Err(ChannelError::Close("Got fulfill HTLC message when channel was not in an operational state"));
16101610
}
@@ -1617,29 +1617,31 @@ impl Channel {
16171617
let mut payment_hash = [0; 32];
16181618
sha.result(&mut payment_hash);
16191619

1620-
self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None)
1620+
self.mark_outbound_htlc_removed(msg.htlc_id, Some(payment_hash), None).map(|source| source.clone())
16211621
}
16221622

1623-
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<&HTLCSource, ChannelError> {
1623+
pub fn update_fail_htlc(&mut self, msg: &msgs::UpdateFailHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> {
16241624
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
16251625
return Err(ChannelError::Close("Got fail HTLC message when channel was not in an operational state"));
16261626
}
16271627
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
16281628
return Err(ChannelError::Close("Peer sent update_fail_htlc when we needed a channel_reestablish"));
16291629
}
16301630

1631-
self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))
1631+
self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))?;
1632+
Ok(())
16321633
}
16331634

1634-
pub fn update_fail_malformed_htlc<'a>(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<&HTLCSource, ChannelError> {
1635+
pub fn update_fail_malformed_htlc<'a>(&mut self, msg: &msgs::UpdateFailMalformedHTLC, fail_reason: HTLCFailReason) -> Result<(), ChannelError> {
16351636
if (self.channel_state & (ChannelState::ChannelFunded as u32)) != (ChannelState::ChannelFunded as u32) {
16361637
return Err(ChannelError::Close("Got fail malformed HTLC message when channel was not in an operational state"));
16371638
}
16381639
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
16391640
return Err(ChannelError::Close("Peer sent update_fail_malformed_htlc when we needed a channel_reestablish"));
16401641
}
16411642

1642-
self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))
1643+
self.mark_outbound_htlc_removed(msg.htlc_id, None, Some(fail_reason))?;
1644+
Ok(())
16431645
}
16441646

16451647
pub fn commitment_signed(&mut self, msg: &msgs::CommitmentSigned, fee_estimator: &FeeEstimator) -> Result<(msgs::RevokeAndACK, Option<msgs::CommitmentSigned>, Option<msgs::ClosingSigned>, ChannelMonitor), ChannelError> {

src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2016,7 +2016,7 @@ impl ChannelManager {
20162016
return Err(MsgHandleErrInternal::send_err_msg_no_close("Got a message for a channel from the wrong node!", msg.channel_id));
20172017
}
20182018
chan.update_fulfill_htlc(&msg)
2019-
.map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.channel_id))?.clone()
2019+
.map_err(|e| MsgHandleErrInternal::from_chan_maybe_close(e, msg.channel_id))?
20202020
},
20212021
None => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))
20222022
};

0 commit comments

Comments
 (0)