Skip to content

Commit 683aa83

Browse files
committed
Correct manual shutdown detection on channel closure
In 5e874c3 we'd intended to not reveal the dummy funding transaction in `Event::DiscardFunding`. However, instead of looking at the channel that was just closed, the logic only looks at any other channels which were funded as a part of the same batch. Because manually-funded transactions cannot currently be done for batch funding, this was actually dead code, preventing the new changes from taking effect.
1 parent 6a81d5d commit 683aa83

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

lightning/src/ln/channel.rs

+4
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,7 @@ pub(crate) struct ShutdownResult {
936936
pub(crate) user_channel_id: u128,
937937
pub(crate) channel_capacity_satoshis: u64,
938938
pub(crate) counterparty_node_id: PublicKey,
939+
pub(crate) is_manual_broadcast: bool,
939940
pub(crate) unbroadcasted_funding_tx: Option<Transaction>,
940941
pub(crate) channel_funding_txo: Option<OutPoint>,
941942
}
@@ -3540,6 +3541,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35403541
channel_capacity_satoshis: self.channel_value_satoshis,
35413542
counterparty_node_id: self.counterparty_node_id,
35423543
unbroadcasted_funding_tx,
3544+
is_manual_broadcast: self.is_manual_broadcast,
35433545
channel_funding_txo: self.get_funding_txo(),
35443546
}
35453547
}
@@ -6243,6 +6245,7 @@ impl<SP: Deref> Channel<SP> where
62436245
channel_capacity_satoshis: self.context.channel_value_satoshis,
62446246
counterparty_node_id: self.context.counterparty_node_id,
62456247
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
6248+
is_manual_broadcast: self.context.is_manual_broadcast,
62466249
channel_funding_txo: self.context.get_funding_txo(),
62476250
};
62486251
let tx = self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig);
@@ -6275,6 +6278,7 @@ impl<SP: Deref> Channel<SP> where
62756278
channel_capacity_satoshis: self.context.channel_value_satoshis,
62766279
counterparty_node_id: self.context.counterparty_node_id,
62776280
unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
6281+
is_manual_broadcast: self.context.is_manual_broadcast,
62786282
channel_funding_txo: self.context.get_funding_txo(),
62796283
};
62806284
if closing_signed.is_some() {

lightning/src/ln/channelmanager.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -3510,7 +3510,6 @@ where
35103510
let _ = self.chain_monitor.update_channel(funding_txo, &monitor_update);
35113511
}
35123512
let mut shutdown_results = Vec::new();
3513-
let mut is_manual_broadcast = false;
35143513
if let Some(txid) = shutdown_res.unbroadcasted_batch_funding_txid {
35153514
let mut funding_batch_states = self.funding_batch_states.lock().unwrap();
35163515
let affected_channels = funding_batch_states.remove(&txid).into_iter().flatten();
@@ -3520,10 +3519,6 @@ where
35203519
if let Some(peer_state_mutex) = per_peer_state.get(&counterparty_node_id) {
35213520
let mut peer_state = peer_state_mutex.lock().unwrap();
35223521
if let Some(mut chan) = peer_state.channel_by_id.remove(&channel_id) {
3523-
// We override the previous value, so we could change from true -> false,
3524-
// but this is fine because if a channel has manual_broadcast set to false
3525-
// we should choose the safier condition.
3526-
is_manual_broadcast = chan.context().is_manual_broadcast();
35273522
update_maps_on_chan_removal!(self, &chan.context());
35283523
shutdown_results.push(chan.context_mut().force_shutdown(false, ClosureReason::FundingBatchClosure));
35293524
}
@@ -3548,7 +3543,7 @@ where
35483543
}, None));
35493544

35503545
if let Some(transaction) = shutdown_res.unbroadcasted_funding_tx {
3551-
let funding_info = if is_manual_broadcast {
3546+
let funding_info = if shutdown_res.is_manual_broadcast {
35523547
FundingInfo::OutPoint {
35533548
outpoint: shutdown_res.channel_funding_txo
35543549
.expect("We had an unbroadcasted funding tx, so should also have had a funding outpoint"),

0 commit comments

Comments
 (0)