Skip to content

Commit

Permalink
f Antoine feedback: rename pending_forward_state and remove comment
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Jun 9, 2020
1 parent a8e5da0 commit 74c5e03
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1733,17 +1733,12 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
self.commit_tx_fee_msat(their_acked_htlcs + addl_htlcs)
}

pub fn update_add_htlc<F>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_state: PendingHTLCStatus, create_pending_htlc_status: F) -> Result<(), ChannelError>
pub fn update_add_htlc<F>(&mut self, msg: &msgs::UpdateAddHTLC, mut pending_forward_status: PendingHTLCStatus, create_pending_htlc_status: F) -> Result<(), ChannelError>
where F: for<'a> Fn(&'a Self, PendingHTLCStatus, u16) -> PendingHTLCStatus {
// We can't accept HTLCs sent after we've sent a shutdown.
let local_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::LocalShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
if local_sent_shutdown {
// TODO: Note that |20 is defined as "channel FROM the processing
// node has been disabled" (emphasis mine), which seems to imply
// that we can't return |20 for an inbound channel being disabled.
// This probably needs a spec update but should definitely be
// allowed.
pending_forward_state = create_pending_htlc_status(self, pending_forward_state, 0x1000|20);
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|20);
}
// If the remote has sent a shutdown prior to adding this HTLC, then they are in violation of the spec.
let remote_sent_shutdown = (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32);
Expand Down Expand Up @@ -1823,9 +1818,9 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
// being sensitive to fee spikes.
let remote_fee_cost_incl_stuck_buffer_msat = 2 * self.next_remote_commit_tx_fee_msat(1 + 1);
if pending_remote_value_msat - msg.amount_msat - chan_reserve_msat < remote_fee_cost_incl_stuck_buffer_msat {
// Note that if the pending_forward_state is not updated here, then it's because we're already failing
// Note that if the pending_forward_status is not updated here, then it's because we're already failing
// the HTLC, i.e. its status is already set to failing.
pending_forward_state = create_pending_htlc_status(self, pending_forward_state, 0x1000|7);
pending_forward_status = create_pending_htlc_status(self, pending_forward_status, 0x1000|7);
}
} else {
// Check that they won't violate our local required channel reserve by adding this HTLC.
Expand All @@ -1845,7 +1840,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
}

if self.channel_state & ChannelState::LocalShutdownSent as u32 != 0 {
if let PendingHTLCStatus::Forward(_) = pending_forward_state {
if let PendingHTLCStatus::Forward(_) = pending_forward_status {
panic!("ChannelManager shouldn't be trying to add a forwardable HTLC after we've started closing");
}
}
Expand All @@ -1857,7 +1852,7 @@ impl<ChanSigner: ChannelKeys> Channel<ChanSigner> {
amount_msat: msg.amount_msat,
payment_hash: msg.payment_hash,
cltv_expiry: msg.cltv_expiry,
state: InboundHTLCState::RemoteAnnounced(pending_forward_state),
state: InboundHTLCState::RemoteAnnounced(pending_forward_status),
});
Ok(())
}
Expand Down

0 comments on commit 74c5e03

Please sign in to comment.