Skip to content

Commit 4565398

Browse files
committed
Misc ClosureReason generation cleanups
Here we fix a few cases of swallowing appropriate `ClosureReason`s and expand `ClosureReason::FundingTimedOut` to include when we didn't get a channel funded in time, rather than using `HolderForceClosed`.
1 parent 738ccfb commit 4565398

File tree

4 files changed

+12
-15
lines changed

4 files changed

+12
-15
lines changed

lightning/src/events/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,8 @@ pub enum ClosureReason {
356356
/// commitment transaction came from our counterparty, but it may also have come from
357357
/// a copy of our own `ChannelMonitor`.
358358
CommitmentTxConfirmed,
359-
/// The funding transaction failed to confirm in a timely manner on an inbound channel.
359+
/// The funding transaction failed to confirm in a timely manner on an inbound channel or the
360+
/// counterparty failed to fund the channel in a timely manner.
360361
FundingTimedOut,
361362
/// Closure generated from processing an event, likely a HTLC forward/relay/reception.
362363
ProcessingError {

lightning/src/ln/channel.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2957,9 +2957,9 @@ where
29572957
let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
29582958
let commitment_signed = match commitment_signed {
29592959
Ok(commitment_signed) => commitment_signed,
2960-
Err(err) => {
2960+
Err(e) => {
29612961
self.funding.channel_transaction_parameters.funding_outpoint = None;
2962-
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2962+
return Err(e)
29632963
},
29642964
};
29652965

lightning/src/ln/channelmanager.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7139,7 +7139,7 @@ where
71397139
log_error!(logger,
71407140
"Force-closing pending channel with ID {} for not establishing in a timely manner",
71417141
context.channel_id());
7142-
let mut close_res = chan.force_shutdown(false, ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) });
7142+
let mut close_res = chan.force_shutdown(false, ClosureReason::FundingTimedOut);
71437143
let (funding, context) = chan.funding_and_context_mut();
71447144
locked_close_channel!(self, peer_state, context, funding, close_res);
71457145
shutdown_channels.push(close_res);
@@ -8368,14 +8368,10 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
83688368
&open_channel_msg,
83698369
user_channel_id, &config, best_block_height,
83708370
&self.logger,
8371-
).map_err(|_| MsgHandleErrInternal::from_chan_no_close(
8372-
ChannelError::Close(
8373-
(
8374-
"V2 channel rejected due to sender error".into(),
8375-
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
8376-
)
8377-
), *temporary_channel_id)
8378-
).map(|channel| {
8371+
).map_err(|e| {
8372+
let channel_id = open_channel_msg.common_fields.temporary_channel_id;
8373+
MsgHandleErrInternal::from_chan_no_close(e, channel_id)
8374+
}).map(|channel| {
83798375
let message_send_event = MessageSendEvent::SendAcceptChannelV2 {
83808376
node_id: channel.context.get_counterparty_node_id(),
83818377
msg: channel.accept_inbound_dual_funded_channel()

lightning/src/ln/functional_tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11003,7 +11003,7 @@ pub fn test_remove_expired_outbound_unfunded_channels() {
1100311003
},
1100411004
_ => panic!("Unexpected event"),
1100511005
}
11006-
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) };
11006+
let reason = ClosureReason::FundingTimedOut;
1100711007
check_closed_event(&nodes[0], 1, reason, false, &[node_b_id], 100000);
1100811008
}
1100911009

@@ -11067,7 +11067,7 @@ pub fn test_remove_expired_inbound_unfunded_channels() {
1106711067
},
1106811068
_ => panic!("Unexpected event"),
1106911069
}
11070-
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) };
11070+
let reason = ClosureReason::FundingTimedOut;
1107111071
check_closed_event(&nodes[1], 1, reason, false, &[node_a_id], 100000);
1107211072
}
1107311073

@@ -11106,7 +11106,7 @@ pub fn test_channel_close_when_not_timely_accepted() {
1110611106

1110711107
// Since we disconnected from peer and did not connect back within time,
1110811108
// we should have forced-closed the channel by now.
11109-
let reason = ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) };
11109+
let reason = ClosureReason::FundingTimedOut;
1111011110
check_closed_event!(nodes[0], 1, reason, [node_b_id], 100000);
1111111111
assert_eq!(nodes[0].node.list_channels().len(), 0);
1111211112

0 commit comments

Comments
 (0)