Skip to content

Commit fcf5072

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

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,9 +1733,19 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
17331733
self.commit_tx_fee_msat(their_acked_htlcs + addl_htlcs)
17341734
}
17351735

1736-
pub fn update_add_htlc<F>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_state: PendingHTLCStatus, create_pending_htlc_status: F) -> Result<(), ChannelError>
1737-
where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus {
1736+
pub fn update_add_htlc<F>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_state: PendingHTLCStatus, create_pending_htlc_status: F) -> Result<(), ChannelError>
1737+
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 the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
1747+
let remote_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
1748+
if remote_sent_shutdown {
17391749
return Err(ChannelError::Close("Got add HTLC message when channel was not in an operational state"));
17401750
}
17411751
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {

0 commit comments

Comments
 (0)