Skip to content

Commit a2f9d35

Browse files
committed
Delay closing_signed until update_fee exchanges complete
See lightning/bolts#499 for a bit more about the ambiguity we're addressing here. Also drop holding cell update_fee the same way we drop holding cell update_add_htlcs when sending shutdown, resolving a bug.
1 parent 65f23de commit a2f9d35

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/ln/channel.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,6 +2181,9 @@ impl Channel {
21812181
if self.channel_outbound {
21822182
return Err(ChannelError::Close("Non-funding remote tried to update channel fee"));
21832183
}
2184+
if (self.channel_state & (ChannelState::ChannelFunded as u32 | ChannelState::RemoteShutdownSent as u32)) != (ChannelState::ChannelFunded as u32) {
2185+
return Err(ChannelError::Close("Got update_fee message when channel was not in an operational state"));
2186+
}
21842187
if self.channel_state & (ChannelState::PeerDisconnected as u32) == ChannelState::PeerDisconnected as u32 {
21852188
return Err(ChannelError::Close("Peer sent update_fee when we needed a channel_reestablish"));
21862189
}
@@ -2382,7 +2385,8 @@ impl Channel {
23822385
fn maybe_propose_first_closing_signed(&mut self, fee_estimator: &FeeEstimator) -> Option<msgs::ClosingSigned> {
23832386
if !self.channel_outbound || !self.pending_inbound_htlcs.is_empty() || !self.pending_outbound_htlcs.is_empty() ||
23842387
self.channel_state & (BOTH_SIDES_SHUTDOWN_MASK | ChannelState::AwaitingRemoteRevoke as u32) != BOTH_SIDES_SHUTDOWN_MASK ||
2385-
self.last_sent_closing_fee.is_some() {
2388+
self.last_sent_closing_fee.is_some() ||
2389+
self.cur_remote_commitment_transaction_number != self.cur_local_commitment_transaction_number{
23862390
return None;
23872391
}
23882392

@@ -2452,6 +2456,7 @@ impl Channel {
24522456
// We can't send our shutdown until we've committed all of our pending HTLCs, but the
24532457
// remote side is unlikely to accept any new HTLCs, so we go ahead and "free" any holding
24542458
// cell HTLCs and return them to fail the payment.
2459+
self.holding_cell_update_fee = None;
24552460
let mut dropped_outbound_htlcs = Vec::with_capacity(self.holding_cell_htlc_updates.len());
24562461
self.holding_cell_htlc_updates.retain(|htlc_update| {
24572462
match htlc_update {
@@ -3260,9 +3265,9 @@ impl Channel {
32603265
}
32613266
self.channel_update_count += 1;
32623267

3263-
// We can't send our shutdown until we've committed all of our pending HTLCs, but the
3264-
// remote side is unlikely to accept any new HTLCs, so we go ahead and "free" any holding
3265-
// cell HTLCs and return them to fail the payment.
3268+
// Go ahead and drop holding cell updates as we'd rather fail payments than wait to send
3269+
// our shutdown until we've committed all of the pending changes.
3270+
self.holding_cell_update_fee = None;
32663271
let mut dropped_outbound_htlcs = Vec::with_capacity(self.holding_cell_htlc_updates.len());
32673272
self.holding_cell_htlc_updates.retain(|htlc_update| {
32683273
match htlc_update {

0 commit comments

Comments
 (0)