Skip to content

Commit 1667b4d

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 8e519b5 commit 1667b4d

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

59735973
/// Begins the shutdown process, getting a message for the remote peer and returning all
59745974
/// holding cell HTLCs for payment failure.
5975-
///
5976-
/// May jump to the channel being fully shutdown (see [`Self::is_shutdown`]) in which case no
5977-
/// [`ChannelMonitorUpdate`] will be returned).
59785975
pub fn get_shutdown(&mut self, signer_provider: &SP, their_features: &InitFeatures,
59795976
target_feerate_sats_per_kw: Option<u32>, override_shutdown_script: Option<ShutdownScript>)
5980-
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>, Option<ShutdownResult>), APIError>
5977+
-> Result<(msgs::Shutdown, Option<ChannelMonitorUpdate>, Vec<(HTLCSource, PaymentHash)>), APIError>
59815978
{
59825979
for htlc in self.context.pending_outbound_htlcs.iter() {
59835980
if let OutboundHTLCState::LocalAnnounced(_) = htlc.state {
@@ -5998,16 +5995,9 @@ impl<SP: Deref> Channel<SP> where
59985995
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()});
59995996
}
60005997

6001-
// If we haven't funded the channel yet, we don't need to bother ensuring the shutdown
6002-
// script is set, we just force-close and call it a day.
6003-
let mut chan_closed = false;
6004-
if self.context.channel_state.is_pre_funded_state() {
6005-
chan_closed = true;
6006-
}
6007-
60085998
let update_shutdown_script = match self.context.shutdown_scriptpubkey {
60095999
Some(_) => false,
6010-
None if !chan_closed => {
6000+
None => {
60116001
// use override shutdown script if provided
60126002
let shutdown_scriptpubkey = match override_shutdown_script {
60136003
Some(script) => script,
@@ -6025,25 +6015,11 @@ impl<SP: Deref> Channel<SP> where
60256015
self.context.shutdown_scriptpubkey = Some(shutdown_scriptpubkey);
60266016
true
60276017
},
6028-
None => false,
60296018
};
60306019

60316020
// From here on out, we may not fail!
60326021
self.context.target_closing_feerate_sats_per_kw = target_feerate_sats_per_kw;
6033-
let shutdown_result = if self.context.channel_state.is_pre_funded_state() {
6034-
let shutdown_result = ShutdownResult {
6035-
monitor_update: None,
6036-
dropped_outbound_htlcs: Vec::new(),
6037-
unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
6038-
channel_id: self.context.channel_id,
6039-
counterparty_node_id: self.context.counterparty_node_id,
6040-
};
6041-
self.context.channel_state = ChannelState::ShutdownComplete;
6042-
Some(shutdown_result)
6043-
} else {
6044-
self.context.channel_state.set_local_shutdown_sent();
6045-
None
6046-
};
6022+
self.context.channel_state.set_local_shutdown_sent();
60476023
self.context.update_time_counter += 1;
60486024

60496025
let monitor_update = if update_shutdown_script {
@@ -6079,7 +6055,7 @@ impl<SP: Deref> Channel<SP> where
60796055
debug_assert!(!self.is_shutdown() || monitor_update.is_none(),
60806056
"we can't both complete shutdown and return a monitor update");
60816057

6082-
Ok((shutdown, monitor_update, dropped_outbound_htlcs, shutdown_result))
6058+
Ok((shutdown, monitor_update, dropped_outbound_htlcs))
60836059
}
60846060

60856061
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
@@ -2730,10 +2730,10 @@ where
27302730
if let ChannelPhase::Funded(chan) = chan_phase_entry.get_mut() {
27312731
let funding_txo_opt = chan.context.get_funding_txo();
27322732
let their_features = &peer_state.latest_features;
2733-
let (shutdown_msg, mut monitor_update_opt, htlcs, local_shutdown_result) =
2733+
let (shutdown_msg, mut monitor_update_opt, htlcs) =
27342734
chan.get_shutdown(&self.signer_provider, their_features, target_feerate_sats_per_1000_weight, override_shutdown_script)?;
27352735
failed_htlcs = htlcs;
2736-
shutdown_result = local_shutdown_result;
2736+
shutdown_result = None;
27372737
debug_assert_eq!(shutdown_result.is_some(), chan.is_shutdown());
27382738

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

0 commit comments

Comments
 (0)