Skip to content

Commit 1503cef

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 4fc3a17 commit 1503cef

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
@@ -5792,12 +5792,9 @@ impl<SP: Deref> Channel<SP> where
57925792

57935793
/// Begins the shutdown process, getting a message for the remote peer and returning all
57945794
/// holding cell HTLCs for payment failure.
5795-
///
5796-
/// May jump to the channel being fully shutdown (see [`Self::is_shutdown`]) in which case no
5797-
/// [`ChannelMonitorUpdate`] will be returned).
57985795
pub fn get_shutdown(&mut self, signer_provider: &SP, their_features: &InitFeatures,
57995796
target_feerate_sats_per_kw: Option<u32>, override_shutdown_script: Option<ShutdownScript>)
5800-
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>, Option<ShutdownResult>), APIError>
5797+
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>), APIError>
58015798
{
58025799
for htlc in self.context.pending_outbound_htlcs.iter() {
58035800
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
@@ -5820,16 +5817,9 @@ impl<SP: Deref> Channel<SP> where
58205817
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()});
58215818
}
58225819

5823-
// If we haven't funded the channel yet, we don't need to bother ensuring the shutdown
5824-
// script is set, we just force-close and call it a day.
5825-
let mut chan_closed = false;
5826-
if self.context.channel_state & !STATE_FLAGS < ChannelState::FundingSent as u32 {
5827-
chan_closed = true;
5828-
}
5829-
58305820
let update_shutdown_script = match self.context.shutdown_scriptpubkey {
58315821
Some(_) => false,
5832-
None if !chan_closed => {
5822+
None => {
58335823
// use override shutdown script if provided
58345824
let shutdown_scriptpubkey = match override_shutdown_script {
58355825
Some(script) => script,
@@ -5847,23 +5837,11 @@ impl<SP: Deref> Channel<SP> where
58475837
self.context.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
58485838
true
58495839
},
5850-
None => false,
58515840
};
58525841

58535842
// From here on out, we may not fail!
58545843
self.context.target_closing_feerate_sats_per_kw = target_feerate_sats_per_kw;
5855-
let shutdown_result = if self.context.channel_state & !STATE_FLAGS < ChannelState::FundingSent as u32 {
5856-
let shutdown_result = ShutdownResult {
5857-
monitor_update: None,
5858-
dropped_outbound_htlcs: Vec::new(),
5859-
unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
5860-
};
5861-
self.context.channel_state = ChannelState::ShutdownComplete as u32;
5862-
Some(shutdown_result)
5863-
} else {
5864-
self.context.channel_state |= ChannelState::LocalShutdownSent as u32;
5865-
None
5866-
};
5844+
self.context.channel_state |= ChannelState::LocalShutdownSent as u32;
58675845
self.context.update_time_counter += 1;
58685846

58695847
let monitor_update = if update_shutdown_script {
@@ -5899,7 +5877,7 @@ impl<SP: Deref> Channel<SP> where
58995877
debug_assert!(!self.is_shutdown() || monitor_update.is_none(),
59005878
"we can't both complete shutdown and return a monitor update");
59015879

5902-
Ok((shutdown, monitor_update, dropped_outbound_htlcs, shutdown_result))
5880+
Ok((shutdown, monitor_update, dropped_outbound_htlcs))
59035881
}
59045882

59055883
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)