@@ -1331,7 +1331,12 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13311331 counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
13321332
13331333 pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
1334+ /// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
1335+ /// is_manual_broadcast is true) this will be a dummy empty transaction.
13341336 funding_transaction: Option<Transaction>,
1337+ /// This flag indicates that it is the user's responsibility to validated and broadcast the
1338+ /// funding transaction.
1339+ is_manual_broadcast: bool,
13351340 is_batch_funding: Option<()>,
13361341
13371342 counterparty_cur_commitment_point: Option<PublicKey>,
@@ -1419,6 +1424,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
14191424 // We track whether we already emitted a `ChannelPending` event.
14201425 channel_pending_event_emitted: bool,
14211426
1427+ // We track whether we already emitted a `FundingTxBroadcastSafe` event.
1428+ funding_tx_broadcast_safe_event_emitted: bool,
1429+
14221430 // We track whether we already emitted a `ChannelReady` event.
14231431 channel_ready_event_emitted: bool,
14241432
@@ -1758,6 +1766,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17581766 outbound_scid_alias: 0,
17591767
17601768 channel_pending_event_emitted: false,
1769+ funding_tx_broadcast_safe_event_emitted: false,
17611770 channel_ready_event_emitted: false,
17621771
17631772 #[cfg(any(test, fuzzing))]
@@ -1769,6 +1778,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17691778 local_initiated_shutdown: None,
17701779
17711780 blocked_monitor_updates: Vec::new(),
1781+
1782+ is_manual_broadcast: false,
17721783 };
17731784
17741785 Ok(channel_context)
@@ -1982,6 +1993,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19821993 outbound_scid_alias,
19831994
19841995 channel_pending_event_emitted: false,
1996+ funding_tx_broadcast_safe_event_emitted: false,
19851997 channel_ready_event_emitted: false,
19861998
19871999 #[cfg(any(test, fuzzing))]
@@ -1992,6 +2004,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19922004
19932005 blocked_monitor_updates: Vec::new(),
19942006 local_initiated_shutdown: None,
2007+ is_manual_broadcast: false,
19952008 })
19962009 }
19972010
@@ -2370,6 +2383,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
23702383 self.config.options.forwarding_fee_proportional_millionths
23712384 }
23722385
2386+ pub fn is_manual_broadcast(&self) -> bool {
2387+ self.is_manual_broadcast
2388+ }
2389+
23732390 pub fn get_cltv_expiry_delta(&self) -> u16 {
23742391 cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
23752392 }
@@ -2404,6 +2421,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24042421 self.channel_pending_event_emitted
24052422 }
24062423
2424+ // Returns whether we already emitted a `FundingTxBroadcastSafe` event.
2425+ pub(crate) fn funding_tx_broadcast_safe_event_emitted(&self) -> bool {
2426+ self.funding_tx_broadcast_safe_event_emitted
2427+ }
2428+
24072429 // Remembers that we already emitted a `ChannelPending` event.
24082430 pub(crate) fn set_channel_pending_event_emitted(&mut self) {
24092431 self.channel_pending_event_emitted = true;
@@ -2419,6 +2441,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24192441 self.channel_ready_event_emitted = true;
24202442 }
24212443
2444+ // Remembers that we already emitted a `FundingTxBroadcastSafe` event.
2445+ pub(crate) fn set_funding_tx_broadcast_safe_event_emitted(&mut self) {
2446+ self.funding_tx_broadcast_safe_event_emitted = true;
2447+ }
2448+
24222449 /// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
24232450 /// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
24242451 /// no longer be considered when forwarding HTLCs.
@@ -2455,6 +2482,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
24552482 did_channel_update
24562483 }
24572484
2485+ /// Marking the channel as manual broadcast is used in order to prevent LDK from automatically
2486+ /// broadcasting the funding transaction.
2487+ ///
2488+ /// This is useful if you wish to get hold of the funding transaction before it is broadcasted
2489+ /// via [`Event::FundingTxBroadcastSafe`] event.
2490+ ///
2491+ /// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe
2492+ pub fn set_manual_broadcast(&mut self) {
2493+ self.is_manual_broadcast = true;
2494+ }
2495+
24582496 /// Returns true if funding_signed was sent/received and the
24592497 /// funding transaction has been broadcast if necessary.
24602498 pub fn is_funding_broadcast(&self) -> bool {
@@ -8706,6 +8744,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
87068744
87078745 let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
87088746 let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8747+ let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
87098748
87108749 // `user_id` used to be a single u64 value. In order to remain backwards compatible with
87118750 // versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8718,6 +8757,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
87188757 if !self.context.monitor_pending_update_adds.is_empty() {
87198758 monitor_pending_update_adds = Some(&self.context.monitor_pending_update_adds);
87208759 }
8760+ let is_manual_broadcast = Some(self.context.is_manual_broadcast);
87218761
87228762 // `current_point` will become optional when async signing is implemented.
87238763 let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
@@ -8762,6 +8802,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
87628802 (45, cur_holder_commitment_point, option),
87638803 (47, next_holder_commitment_point, option),
87648804 (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8805+ (51, is_manual_broadcast, option), // Added in 0.0.124
8806+ (53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
87658807 });
87668808
87678809 Ok(())
@@ -9050,6 +9092,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
90509092 let mut outbound_scid_alias = None;
90519093 let mut channel_pending_event_emitted = None;
90529094 let mut channel_ready_event_emitted = None;
9095+ let mut funding_tx_broadcast_safe_event_emitted = None;
90539096
90549097 let mut user_id_high_opt: Option<u64> = None;
90559098 let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9073,6 +9116,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
90739116
90749117 let mut cur_holder_commitment_point_opt: Option<PublicKey> = None;
90759118 let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
9119+ let mut is_manual_broadcast = None;
90769120
90779121 read_tlv_fields!(reader, {
90789122 (0, announcement_sigs, option),
@@ -9107,6 +9151,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
91079151 (45, cur_holder_commitment_point_opt, option),
91089152 (47, next_holder_commitment_point_opt, option),
91099153 (49, local_initiated_shutdown, option),
9154+ (51, is_manual_broadcast, option),
9155+ (53, funding_tx_broadcast_safe_event_emitted, option),
91109156 });
91119157
91129158 let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9347,6 +9393,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93479393 // Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
93489394 outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
93499395
9396+ funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
93509397 channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
93519398 channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
93529399
@@ -9359,6 +9406,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93599406 local_initiated_shutdown,
93609407
93619408 blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9409+ is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
93629410 },
93639411 #[cfg(any(dual_funding, splicing))]
93649412 dual_funding_channel_context: None,
0 commit comments