Skip to content

Commit bfb503e

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 973de6f commit bfb503e

File tree

2 files changed

+6
-30
lines changed

2 files changed

+6
-30
lines changed

lightning/src/ln/channel.rs

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

57365736
/// Begins the shutdown process, getting a message for the remote peer and returning all
57375737
/// holding cell HTLCs for payment failure.
5738-
///
5739-
/// May jump to the channel being fully shutdown (see [`Self::is_shutdown`]) in which case no
5740-
/// [`ChannelMonitorUpdate`] will be returned).
57415738
pub fn get_shutdown(&mut self, signer_provider: &SP, their_features: &InitFeatures,
57425739
target_feerate_sats_per_kw: Option<u32>, override_shutdown_script: Option<ShutdownScript>)
5743-
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>, Option<ShutdownResult>), APIError>
5740+
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>), APIError>
57445741
{
57455742
for htlc in self.context.pending_outbound_htlcs.iter() {
57465743
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
@@ -5763,16 +5760,9 @@ impl<SP: Deref> Channel<SP> where
57635760
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()});
57645761
}
57655762

5766-
// If we haven't funded the channel yet, we don't need to bother ensuring the shutdown
5767-
// script is set, we just force-close and call it a day.
5768-
let mut chan_closed = false;
5769-
if self.context.channel_state & !STATE_FLAGS < ChannelState::FundingSent as u32 {
5770-
chan_closed = true;
5771-
}
5772-
57735763
let update_shutdown_script = match self.context.shutdown_scriptpubkey {
57745764
Some(_) => false,
5775-
None if !chan_closed => {
5765+
None => {
57765766
// use override shutdown script if provided
57775767
let shutdown_scriptpubkey = match override_shutdown_script {
57785768
Some(script) => script,
@@ -5790,25 +5780,11 @@ impl<SP: Deref> Channel<SP> where
57905780
self.context.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
57915781
true
57925782
},
5793-
None => false,
57945783
};
57955784

57965785
// From here on out, we may not fail!
57975786
self.context.target_closing_feerate_sats_per_kw = target_feerate_sats_per_kw;
5798-
let shutdown_result = if self.context.channel_state & !STATE_FLAGS < ChannelState::FundingSent as u32 {
5799-
let shutdown_result = ShutdownResult {
5800-
monitor_update: None,
5801-
dropped_outbound_htlcs: Vec::new(),
5802-
unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
5803-
channel_id: self.context.channel_id,
5804-
counterparty_node_id: self.context.counterparty_node_id,
5805-
};
5806-
self.context.channel_state = ChannelState::ShutdownComplete as u32;
5807-
Some(shutdown_result)
5808-
} else {
5809-
self.context.channel_state |= ChannelState::LocalShutdownSent as u32;
5810-
None
5811-
};
5787+
self.context.channel_state |= ChannelState::LocalShutdownSent as u32;
58125788
self.context.update_time_counter += 1;
58135789

58145790
let monitor_update = if update_shutdown_script {
@@ -5844,7 +5820,7 @@ impl<SP: Deref> Channel<SP> where
58445820
debug_assert!(!self.is_shutdown() || monitor_update.is_none(),
58455821
"we can't both complete shutdown and return a monitor update");
58465822

5847-
Ok((shutdown, monitor_update, dropped_outbound_htlcs, shutdown_result))
5823+
Ok((shutdown, monitor_update, dropped_outbound_htlcs))
58485824
}
58495825

58505826
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
@@ -2679,10 +2679,10 @@ where
26792679
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
26802680
let funding_txo_opt = chan.context.get_funding_txo();
26812681
let their_features = &peer_state.latest_features;
2682-
let (shutdown_msg, mut monitor_update_opt, htlcs, local_shutdown_result) =
2682+
let (shutdown_msg, mut monitor_update_opt, htlcs) =
26832683
chan.get_shutdown(&self.signer_provider, their_features, target_feerate_sats_per_1000_weight, override_shutdown_script)?;
26842684
failed_htlcs = htlcs;
2685-
shutdown_result = local_shutdown_result;
2685+
shutdown_result = None;
26862686
debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown());
26872687

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

0 commit comments

Comments
 (0)