Skip to content

Commit edc2ede

Browse files
Fix update_add_htlc check for shutdowns sent on either side
1 parent 1cda8ad commit edc2ede

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1735,7 +1735,18 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
17351735

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 {
1738-
if !self.is_usable() {
1738+
// If only we have sent a shutdown, then fail the HTLC but no need to close the channel.
1739+
if (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) == (ChannelState::ChannelFunded as u32)
1740+
&& (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelFunded as u32){
1741+
// TODO: Note that |20 is defined as "channel FROM the processing
1742+
// node has been disabled" (emphasis mine), which seems to imply
1743+
// that we can't return |20 for an inbound channel being disabled.
1744+
// This probably needs a spec update but should definitely be
1745+
// allowed.
1746+
pending_forward_state = create_pending_htlc_status(self, pending_forward_state, 0x1000|20);
1747+
}
1748+
// If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
1749+
if (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32) {
17391750
return Err(ChannelError::Close("Got add HTLC message when channel was not in an operational state"));
17401751
}
17411752
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {

0 commit comments

Comments
 (0)