Skip to content

Commit 54255c5

Browse files
committed
Add a ClosureReason::LocallyCoopClosedUnfundedChannel
When a channel is "coop" closed prior to it being funded, it is closed immediately. Instead of reporting `ClosureReason::*InitiatedCooperativeClosure` (which would be somewhat misleading), we report `ClosureReason::CounterpartyCoopClosedUnfundedCHannel` when our counterparty does it. However, when we do it, we report `ClosureReason::HolderForceClosed`, which is highly confusing given the user did *not* call a force-closure method. Instead, here, we add a `ClosureReason::LocallyCoopClosedUnfundedChannel` to match the `CounterpartyCoopClosedUnfundedCHannel` variant and use it.
1 parent dcaf0b3 commit 54255c5

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

lightning/src/events/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,12 @@ pub enum ClosureReason {
383383
/// The counterparty requested a cooperative close of a channel that had not been funded yet.
384384
/// The channel has been immediately closed.
385385
CounterpartyCoopClosedUnfundedChannel,
386+
/// We requested a cooperative close of a channel that had not been funded yet.
387+
/// The channel has been immediately closed.
388+
///
389+
/// Note that events containing this variant will be lost on downgrade to a version of LDK
390+
/// prior to 0.2.
391+
LocallyCoopClosedUnfundedChannel,
386392
/// Another channel in the same funding batch closed before the funding transaction
387393
/// was ready to be broadcast.
388394
FundingBatchClosure,
@@ -454,6 +460,9 @@ impl core::fmt::Display for ClosureReason {
454460
ClosureReason::CounterpartyCoopClosedUnfundedChannel => {
455461
f.write_str("the peer requested the unfunded channel be closed")
456462
},
463+
ClosureReason::LocallyCoopClosedUnfundedChannel => {
464+
f.write_str("we requested the unfunded channel be closed")
465+
},
457466
ClosureReason::FundingBatchClosure => {
458467
f.write_str("another channel in the same funding batch closed")
459468
},
@@ -487,6 +496,7 @@ impl_writeable_tlv_based_enum_upgradable!(ClosureReason,
487496
(0, peer_feerate_sat_per_kw, required),
488497
(2, required_feerate_sat_per_kw, required),
489498
},
499+
(25, LocallyCoopClosedUnfundedChannel) => {},
490500
);
491501

492502
/// The type of HTLC handling performed in [`Event::HTLCHandlingFailed`].

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4126,7 +4126,7 @@ where
41264126
}
41274127
} else {
41284128
let mut shutdown_res = chan_entry.get_mut()
4129-
.force_shutdown(false, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) });
4129+
.force_shutdown(false, ClosureReason::LocallyCoopClosedUnfundedChannel);
41304130
remove_channel_entry!(self, peer_state, chan_entry, shutdown_res);
41314131
shutdown_result = Some(shutdown_res);
41324132
}

lightning/src/ln/shutdown_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn close_on_unfunded_channel() {
337337
let _open_chan = get_event_msg!(nodes[0], MessageSendEvent::SendOpenChannel, node_b_id);
338338

339339
nodes[0].node.close_channel(&chan_id, &node_b_id).unwrap();
340-
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) };
340+
let reason = ClosureReason::LocallyCoopClosedUnfundedChannel;
341341
check_closed_event!(nodes[0], 1, reason, [node_b_id], 1_000_000);
342342
}
343343

0 commit comments

Comments
 (0)