@@ -814,6 +814,7 @@ pub(super) struct ReestablishResponses {
814
814
/// The result of a shutdown that should be handled.
815
815
#[must_use]
816
816
pub(crate) struct ShutdownResult {
817
+ pub(crate) closure_reason: ClosureReason,
817
818
/// A channel monitor update to apply.
818
819
pub(crate) monitor_update: Option<(PublicKey, OutPoint, ChannelMonitorUpdate)>,
819
820
/// A list of dropped outbound HTLCs that can safely be failed backwards immediately.
@@ -822,7 +823,10 @@ pub(crate) struct ShutdownResult {
822
823
/// propagated to the remainder of the batch.
823
824
pub(crate) unbroadcasted_batch_funding_txid: Option<Txid>,
824
825
pub(crate) channel_id: ChannelId,
826
+ pub(crate) user_channel_id: u128,
827
+ pub(crate) channel_capacity_satoshis: u64,
825
828
pub(crate) counterparty_node_id: PublicKey,
829
+ pub(crate) unbroadcasted_funding_tx: Option<Transaction>,
826
830
}
827
831
828
832
/// If the majority of the channels funds are to the fundee and the initiator holds only just
@@ -2311,15 +2315,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2311
2315
res
2312
2316
}
2313
2317
2314
- fn if_unbroadcasted_funding<F, O>(&self, f: F) -> Option<O>
2315
- where F: Fn() -> Option<O> {
2318
+ fn if_unbroadcasted_funding<F, O>(&self, f: F) -> Option<O> where F: Fn() -> Option<O> {
2316
2319
match self.channel_state {
2317
2320
ChannelState::FundingNegotiated => f(),
2318
- ChannelState::AwaitingChannelReady(flags) => if flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH) {
2319
- f()
2320
- } else {
2321
- None
2322
- },
2321
+ ChannelState::AwaitingChannelReady(flags) =>
2322
+ if flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH) ||
2323
+ flags.is_set(FundedStateFlags::MONITOR_UPDATE_IN_PROGRESS.into())
2324
+ {
2325
+ f()
2326
+ } else {
2327
+ None
2328
+ },
2323
2329
_ => None,
2324
2330
}
2325
2331
}
@@ -2354,7 +2360,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2354
2360
/// those explicitly stated to be allowed after shutdown completes, eg some simple getters).
2355
2361
/// Also returns the list of payment_hashes for channels which we can safely fail backwards
2356
2362
/// immediately (others we will have to allow to time out).
2357
- pub fn force_shutdown(&mut self, should_broadcast: bool) -> ShutdownResult {
2363
+ pub fn force_shutdown(&mut self, should_broadcast: bool, closure_reason: ClosureReason ) -> ShutdownResult {
2358
2364
// Note that we MUST only generate a monitor update that indicates force-closure - we're
2359
2365
// called during initialization prior to the chain_monitor in the encompassing ChannelManager
2360
2366
// being fully configured in some cases. Thus, its likely any monitor events we generate will
@@ -2395,15 +2401,20 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2395
2401
} else { None }
2396
2402
} else { None };
2397
2403
let unbroadcasted_batch_funding_txid = self.unbroadcasted_batch_funding_txid();
2404
+ let unbroadcasted_funding_tx = self.unbroadcasted_funding();
2398
2405
2399
2406
self.channel_state = ChannelState::ShutdownComplete;
2400
2407
self.update_time_counter += 1;
2401
2408
ShutdownResult {
2409
+ closure_reason,
2402
2410
monitor_update,
2403
2411
dropped_outbound_htlcs,
2404
2412
unbroadcasted_batch_funding_txid,
2405
2413
channel_id: self.channel_id,
2414
+ user_channel_id: self.user_id,
2415
+ channel_capacity_satoshis: self.channel_value_satoshis,
2406
2416
counterparty_node_id: self.counterparty_node_id,
2417
+ unbroadcasted_funding_tx,
2407
2418
}
2408
2419
}
2409
2420
@@ -4931,11 +4942,15 @@ impl<SP: Deref> Channel<SP> where
4931
4942
if let Some((last_fee, sig)) = self.context.last_sent_closing_fee {
4932
4943
if last_fee == msg.fee_satoshis {
4933
4944
let shutdown_result = ShutdownResult {
4945
+ closure_reason: ClosureReason::CooperativeClosure,
4934
4946
monitor_update: None,
4935
4947
dropped_outbound_htlcs: Vec::new(),
4936
4948
unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
4937
4949
channel_id: self.context.channel_id,
4950
+ user_channel_id: self.context.user_id,
4951
+ channel_capacity_satoshis: self.context.channel_value_satoshis,
4938
4952
counterparty_node_id: self.context.counterparty_node_id,
4953
+ unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
4939
4954
};
4940
4955
let tx = self.build_signed_closing_transaction(&mut closing_tx, &msg.signature, &sig);
4941
4956
self.context.channel_state = ChannelState::ShutdownComplete;
@@ -4961,11 +4976,15 @@ impl<SP: Deref> Channel<SP> where
4961
4976
.map_err(|_| ChannelError::Close("External signer refused to sign closing transaction".to_owned()))?;
4962
4977
let (signed_tx, shutdown_result) = if $new_fee == msg.fee_satoshis {
4963
4978
let shutdown_result = ShutdownResult {
4979
+ closure_reason: ClosureReason::CooperativeClosure,
4964
4980
monitor_update: None,
4965
4981
dropped_outbound_htlcs: Vec::new(),
4966
4982
unbroadcasted_batch_funding_txid: self.context.unbroadcasted_batch_funding_txid(),
4967
4983
channel_id: self.context.channel_id,
4984
+ user_channel_id: self.context.user_id,
4985
+ channel_capacity_satoshis: self.context.channel_value_satoshis,
4968
4986
counterparty_node_id: self.context.counterparty_node_id,
4987
+ unbroadcasted_funding_tx: self.context.unbroadcasted_funding(),
4969
4988
};
4970
4989
self.context.channel_state = ChannelState::ShutdownComplete;
4971
4990
self.context.update_time_counter += 1;
0 commit comments