@@ -1377,7 +1377,12 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13771377	counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
13781378
13791379	pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
1380+ 	/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
1381+ 	/// is_manual_broadcast is true) this will be a dummy empty transaction.
13801382	funding_transaction: Option<Transaction>,
1383+ 	/// This flag indicates that it is the user's responsibility to validated and broadcast the
1384+ 	/// funding transaction.
1385+ 	is_manual_broadcast: bool,
13811386	is_batch_funding: Option<()>,
13821387
13831388	counterparty_cur_commitment_point: Option<PublicKey>,
@@ -1465,6 +1470,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14651470	// We track whether we already emitted a `ChannelPending` event.
14661471	channel_pending_event_emitted: bool,
14671472
1473+ 	// We track whether we already emitted a `FundingTxBroadcastSafe` event.
1474+ 	funding_tx_broadcast_safe_event_emitted: bool,
1475+ 
14681476	// We track whether we already emitted a `ChannelReady` event.
14691477	channel_ready_event_emitted: bool,
14701478
@@ -1805,6 +1813,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
18051813			outbound_scid_alias: 0,
18061814
18071815			channel_pending_event_emitted: false,
1816+ 			funding_tx_broadcast_safe_event_emitted: false,
18081817			channel_ready_event_emitted: false,
18091818
18101819			#[cfg(any(test, fuzzing))]
@@ -1816,6 +1825,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
18161825			local_initiated_shutdown: None,
18171826
18181827			blocked_monitor_updates: Vec::new(),
1828+ 
1829+ 			is_manual_broadcast: false,
18191830		};
18201831
18211832		Ok(channel_context)
@@ -2032,6 +2043,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
20322043			outbound_scid_alias,
20332044
20342045			channel_pending_event_emitted: false,
2046+ 			funding_tx_broadcast_safe_event_emitted: false,
20352047			channel_ready_event_emitted: false,
20362048
20372049			#[cfg(any(test, fuzzing))]
@@ -2042,6 +2054,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
20422054
20432055			blocked_monitor_updates: Vec::new(),
20442056			local_initiated_shutdown: None,
2057+ 			is_manual_broadcast: false,
20452058		})
20462059	}
20472060
@@ -2420,6 +2433,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
24202433		self.config.options.forwarding_fee_proportional_millionths
24212434	}
24222435
2436+ 	pub fn is_manual_broadcast(&self) -> bool {
2437+ 		self.is_manual_broadcast
2438+ 	}
2439+ 
24232440	pub fn get_cltv_expiry_delta(&self) -> u16 {
24242441		cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
24252442	}
@@ -2454,6 +2471,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
24542471		self.channel_pending_event_emitted
24552472	}
24562473
2474+ 	// Returns whether we already emitted a `FundingTxBroadcastSafe` event.
2475+ 	pub(crate) fn funding_tx_broadcast_safe_event_emitted(&self) -> bool {
2476+ 		self.funding_tx_broadcast_safe_event_emitted
2477+ 	}
2478+ 
24572479	// Remembers that we already emitted a `ChannelPending` event.
24582480	pub(crate) fn set_channel_pending_event_emitted(&mut self) {
24592481		self.channel_pending_event_emitted = true;
@@ -2469,6 +2491,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
24692491		self.channel_ready_event_emitted = true;
24702492	}
24712493
2494+ 	// Remembers that we already emitted a `FundingTxBroadcastSafe` event.
2495+ 	pub(crate) fn set_funding_tx_broadcast_safe_event_emitted(&mut self) {
2496+ 		self.funding_tx_broadcast_safe_event_emitted = true;
2497+ 	}
2498+ 
24722499	/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
24732500	/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
24742501	/// no longer be considered when forwarding HTLCs.
@@ -2505,6 +2532,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider  {
25052532		did_channel_update
25062533	}
25072534
2535+ 	/// Marking the channel as manual broadcast is used in order to prevent LDK from automatically
2536+ 	/// broadcasting the funding transaction.
2537+ 	///
2538+ 	/// This is useful if you wish to get hold of the funding transaction before it is broadcasted
2539+ 	/// via [`Event::FundingTxBroadcastSafe`] event.
2540+ 	///
2541+ 	/// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe
2542+ 	pub fn set_manual_broadcast(&mut self) {
2543+ 		self.is_manual_broadcast = true;
2544+ 	}
2545+ 
25082546	/// Returns true if funding_signed was sent/received and the
25092547	/// funding transaction has been broadcast if necessary.
25102548	pub fn is_funding_broadcast(&self) -> bool {
@@ -8871,6 +8909,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
88718909
88728910		let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
88738911		let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8912+ 		let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
88748913
88758914		// `user_id` used to be a single u64 value. In order to remain backwards compatible with
88768915		// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8883,6 +8922,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
88838922		if !self.context.monitor_pending_update_adds.is_empty() {
88848923			monitor_pending_update_adds = Some(&self.context.monitor_pending_update_adds);
88858924		}
8925+ 		let is_manual_broadcast = Some(self.context.is_manual_broadcast);
88868926
88878927		// `current_point` will become optional when async signing is implemented.
88888928		let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
@@ -8927,6 +8967,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
89278967			(45, cur_holder_commitment_point, option),
89288968			(47, next_holder_commitment_point, option),
89298969			(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8970+ 			(51, is_manual_broadcast, option), // Added in 0.0.124
8971+ 			(53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
89308972		});
89318973
89328974		Ok(())
@@ -9215,6 +9257,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
92159257		let mut outbound_scid_alias = None;
92169258		let mut channel_pending_event_emitted = None;
92179259		let mut channel_ready_event_emitted = None;
9260+ 		let mut funding_tx_broadcast_safe_event_emitted = None;
92189261
92199262		let mut user_id_high_opt: Option<u64> = None;
92209263		let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9238,6 +9281,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
92389281
92399282		let mut cur_holder_commitment_point_opt: Option<PublicKey> = None;
92409283		let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
9284+ 		let mut is_manual_broadcast = None;
92419285
92429286		read_tlv_fields!(reader, {
92439287			(0, announcement_sigs, option),
@@ -9272,6 +9316,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
92729316			(45, cur_holder_commitment_point_opt, option),
92739317			(47, next_holder_commitment_point_opt, option),
92749318			(49, local_initiated_shutdown, option),
9319+ 			(51, is_manual_broadcast, option),
9320+ 			(53, funding_tx_broadcast_safe_event_emitted, option),
92759321		});
92769322
92779323		let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9515,6 +9561,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95159561				// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
95169562				outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
95179563
9564+ 				funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
95189565				channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
95199566				channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
95209567
@@ -9527,6 +9574,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95279574				local_initiated_shutdown,
95289575
95299576				blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9577+ 				is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
95309578			},
95319579			#[cfg(any(dual_funding, splicing))]
95329580			dual_funding_channel_context: None,
0 commit comments