Skip to content

Commit 527d036

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 78232f2 commit 527d036

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/ln/channel.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2382,7 +2382,8 @@ impl Channel {
23822382
fn maybe_propose_first_closing_signed(&mut self, fee_estimator: &FeeEstimator) -> Option<msgs::ClosingSigned> {
23832383
if !self.channel_outbound || !self.pending_inbound_htlcs.is_empty() || !self.pending_outbound_htlcs.is_empty() ||
23842384
self.channel_state & (BOTH_SIDES_SHUTDOWN_MASK | ChannelState::AwaitingRemoteRevoke as u32) != BOTH_SIDES_SHUTDOWN_MASK ||
2385-
self.last_sent_closing_fee.is_some() {
2385+
self.last_sent_closing_fee.is_some() ||
2386+
self.cur_remote_commitment_transaction_number != self.cur_local_commitment_transaction_number{
23862387
return None;
23872388
}
23882389

@@ -2452,6 +2453,7 @@ impl Channel {
24522453
// We can't send our shutdown until we've committed all of our pending HTLCs, but the
24532454
// remote side is unlikely to accept any new HTLCs, so we go ahead and "free" any holding
24542455
// cell HTLCs and return them to fail the payment.
2456+
self.holding_cell_update_fee = None;
24552457
let mut dropped_outbound_htlcs = Vec::with_capacity(self.holding_cell_htlc_updates.len());
24562458
self.holding_cell_htlc_updates.retain(|htlc_update| {
24572459
match htlc_update {
@@ -3260,9 +3262,9 @@ impl Channel {
32603262
}
32613263
self.channel_update_count += 1;
32623264

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.
3265+
// Go ahead and drop holding cell updates as we'd rather fail payments than wait to send
3266+
// our shutdown until we've committed all of the pending changes.
3267+
self.holding_cell_update_fee = None;
32663268
let mut dropped_outbound_htlcs = Vec::with_capacity(self.holding_cell_htlc_updates.len());
32673269
self.holding_cell_htlc_updates.retain(|htlc_update| {
32683270
match htlc_update {

0 commit comments

Comments
 (0)