Skip to content

Commit 1cda8ad

Browse files
Remove redundant check, add comment, fix indentation, small refactor
1 parent 01a730d commit 1cda8ad

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,14 +1736,6 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
17361736
pub fn update_add_htlc<F>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_state: PendingHTLCStatus, create_pending_htlc_status: F) -> Result<(), ChannelError>
17371737
where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus {
17381738
if !self.is_usable() {
1739-
// TODO: Note that |20 is defined as "channel FROM the processing
1740-
// node has been disabled" (emphasis mine), which seems to imply
1741-
// that we can't return |20 for an inbound channel being disabled.
1742-
// This probably needs a spec update but should definitely be
1743-
// allowed.
1744-
pending_forward_state = create_pending_htlc_status(self, pending_forward_state, 0x1000|20);
1745-
}
1746-
if (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32) {
17471739
return Err(ChannelError::Close("Got add HTLC message when channel was not in an operational state"));
17481740
}
17491741
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
@@ -1815,6 +1807,8 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
18151807
// but should help protect us from stuck channels).
18161808
let remote_fee_cost_incl_stuck_buffer_msat = 2 * self.next_remote_commit_tx_fee_msat(1 + 1);
18171809
if pending_remote_value_msat - msg.amount_msat - chan_reserve_msat < remote_fee_cost_incl_stuck_buffer_msat {
1810+
// Note that if we get None here, it's because we're already failing the HTLC, i.e. its
1811+
// status is already set to failing.
18181812
pending_forward_state = create_pending_htlc_status(self, pending_forward_state, 0x1000|7);
18191813
}
18201814
} else {

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2510,21 +2510,22 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
25102510
// want to reject the new HTLC and fail it backwards instead of forwarding.
25112511
match pending_forward_info {
25122512
PendingHTLCStatus::Forward(PendingHTLCInfo { ref incoming_shared_secret, .. }) => {
2513-
let mut reason = onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[]);
25142513
// The only case where we'd be unable to successfully get a channel
25152514
// update here is if the channel isn't in the fully-funded
25162515
// state yet, implying our counterparty is trying to route payments
25172516
// over the channel back to themselves (cause no one else should
25182517
// know the short_id is a lightning channel yet). We should have no
25192518
// problem just calling this unknown_next_peer, as above (0x4000|10).
2520-
if let Ok(upd) = self.get_channel_update(chan) {
2521-
reason = onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
2519+
let reason = if let Ok(upd) = self.get_channel_update(chan) {
2520+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, error_code, &{
25222521
let mut res = Vec::with_capacity(8 + 128);
25232522
res.extend_from_slice(&byte_utils::be16_to_array(upd.contents.flags));
25242523
res.extend_from_slice(&upd.encode_with_len()[..]);
25252524
res
2526-
}[..]);
2527-
}
2525+
}[..])
2526+
} else {
2527+
onion_utils::build_first_hop_failure_packet(incoming_shared_secret, 0x4000|10, &[])
2528+
};
25282529
let msg = msgs::UpdateFailHTLC {
25292530
channel_id: msg.channel_id,
25302531
htlc_id: msg.htlc_id,
@@ -2535,7 +2536,7 @@ impl<ChanSigner: ChannelKeys, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref>
25352536
_ => pending_forward_info
25362537
}
25372538
};
2538-
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status), channel_state, chan);
2539+
try_chan_entry!(self, chan.get_mut().update_add_htlc(&msg, pending_forward_info, create_pending_htlc_status), channel_state, chan);
25392540
},
25402541
hash_map::Entry::Vacant(_) => return Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel", msg.channel_id))
25412542
}

0 commit comments

Comments
 (0)