Skip to content

Commit 0e264f9

Browse files
committed
Drop unreachable shutdown code in Channel::get_shutdown
`Channel` is only a thing for funded channels. Thus, checking if a channel has not yet been funded is dead code and can simply be elided.
1 parent fc8daa3 commit 0e264f9

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5661,12 +5661,9 @@ impl<SP: Deref> Channel<SP> where
56615661

56625662
/// Begins the shutdown process, getting a message for the remote peer and returning all
56635663
/// holding cell HTLCs for payment failure.
5664-
///
5665-
/// May jump to the channel being fully shutdown (see [`Self::is_shutdown`]) in which case no
5666-
/// [`ChannelMonitorUpdate`] will be returned).
56675664
pub fn get_shutdown(&mut self, signer_provider: &SP, their_features: &InitFeatures,
56685665
target_feerate_sats_per_kw: Option<u32>, override_shutdown_script: Option<ShutdownScript>)
5669-
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>, Option<ShutdownResult>), APIError>
5666+
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>), APIError>
56705667
{
56715668
for htlc in self.context.pending_outbound_htlcs.iter() {
56725669
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
@@ -5689,16 +5686,9 @@ impl<SP: Deref> Channel<SP> where
56895686
return Err(APIError::ChannelUnavailable{err: "Cannot begin shutdown while peer is disconnected or we're waiting on a monitor update, maybe force-close instead?".to_owned()});
56905687
}
56915688

5692-
// If we haven't funded the channel yet, we don't need to bother ensuring the shutdown
5693-
// script is set, we just force-close and call it a day.
5694-
let mut chan_closed = false;
5695-
if self.context.channel_state & !STATE_FLAGS < ChannelState::FundingSent as u32 {
5696-
chan_closed = true;
5697-
}
5698-
56995689
let update_shutdown_script = match self.context.shutdown_scriptpubkey {
57005690
Some(_) => false,
5701-
None if !chan_closed => {
5691+
None => {
57025692
// use override shutdown script if provided
57035693
let shutdown_scriptpubkey = match override_shutdown_script {
57045694
Some(script) => script,
@@ -5716,23 +5706,11 @@ impl<SP: Deref> Channel<SP> where
57165706
self.context.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
57175707
true
57185708
},
5719-
None => false,
57205709
};
57215710

57225711
// From here on out, we may not fail!
57235712
self.context.target_closing_feerate_sats_per_kw = target_feerate_sats_per_kw;
5724-
let shutdown_result = if self.context.channel_state & !STATE_FLAGS < ChannelState::FundingSent as u32 {
5725-
let shutdown_result = ShutdownResult {
5726-
monitor_update: None,
5727-
dropped_outbound_htlcs: Vec::new(),
5728-
unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
5729-
};
5730-
self.context.channel_state = ChannelState::ShutdownComplete as u32;
5731-
Some(shutdown_result)
5732-
} else {
5733-
self.context.channel_state |= ChannelState::LocalShutdownSent as u32;
5734-
None
5735-
};
5713+
self.context.channel_state |= ChannelState::LocalShutdownSent as u32;
57365714
self.context.update_time_counter += 1;
57375715

57385716
let monitor_update = if update_shutdown_script {
@@ -5768,7 +5746,7 @@ impl<SP: Deref> Channel<SP> where
57685746
debug_assert!(!self.is_shutdown() || monitor_update.is_none(),
57695747
"we can't both complete shutdown and return a monitor update");
57705748

5771-
Ok((shutdown, monitor_update, dropped_outbound_htlcs, shutdown_result))
5749+
Ok((shutdown, monitor_update, dropped_outbound_htlcs))
57725750
}
57735751

57745752
pub fn inflight_htlc_sources(&self) -> impl Iterator<Item=(&HTLCSource, &PaymentHash)> {

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,10 +2650,10 @@ where
26502650
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
26512651
let funding_txo_opt = chan.context.get_funding_txo();
26522652
let their_features = &peer_state.latest_features;
2653-
let (shutdown_msg, mut monitor_update_opt, htlcs, local_shutdown_result) =
2653+
let (shutdown_msg, mut monitor_update_opt, htlcs) =
26542654
chan.get_shutdown(&self.signer_provider, their_features, target_feerate_sats_per_1000_weight, override_shutdown_script)?;
26552655
failed_htlcs = htlcs;
2656-
shutdown_result = local_shutdown_result;
2656+
shutdown_result = None;
26572657
debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown());
26582658

26592659
// We can send the `shutdown` message before updating the `ChannelMonitor`

0 commit comments

Comments
 (0)