@@ -1530,6 +1530,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1530
1530
1531
1531
// We track whether we already emitted a `ChannelPending` event.
1532
1532
channel_pending_event_emitted: bool,
1533
+
1534
+ // We track whether we already emitted a `FundingSigned` event.
1535
+ funding_signed_event_emitted: bool,
1533
1536
1534
1537
// We track whether we already emitted a `ChannelReady` event.
1535
1538
channel_ready_event_emitted: bool,
@@ -1547,6 +1550,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1547
1550
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
1548
1551
/// store it here and only release it to the `ChannelManager` once it asks for it.
1549
1552
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1553
+
1554
+ /// Using this flag will prevent the funding transaction from being broadcasted
1555
+ /// and will allow the user to manually broadcast it.
1556
+ ///
1557
+ /// The funding transaction can be accessed through the [`Event::FundingSigned`] event.
1558
+ ///
1559
+ /// [`Event::FundingSigned`]: crate::events::Event::FundingSigned
1560
+ manually_broadcast_outbound_channels: Option<()>,
1550
1561
}
1551
1562
1552
1563
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
@@ -1867,6 +1878,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1867
1878
outbound_scid_alias: 0,
1868
1879
1869
1880
channel_pending_event_emitted: false,
1881
+ funding_signed_event_emitted: false,
1870
1882
channel_ready_event_emitted: false,
1871
1883
1872
1884
#[cfg(any(test, fuzzing))]
@@ -1878,6 +1890,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1878
1890
local_initiated_shutdown: None,
1879
1891
1880
1892
blocked_monitor_updates: Vec::new(),
1893
+
1894
+ manually_broadcast_outbound_channels: None,
1881
1895
};
1882
1896
1883
1897
Ok(channel_context)
@@ -2088,6 +2102,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2088
2102
outbound_scid_alias,
2089
2103
2090
2104
channel_pending_event_emitted: false,
2105
+ funding_signed_event_emitted: false,
2091
2106
channel_ready_event_emitted: false,
2092
2107
2093
2108
#[cfg(any(test, fuzzing))]
@@ -2098,6 +2113,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2098
2113
2099
2114
blocked_monitor_updates: Vec::new(),
2100
2115
local_initiated_shutdown: None,
2116
+ manually_broadcast_outbound_channels: None,
2101
2117
})
2102
2118
}
2103
2119
@@ -2339,6 +2355,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2339
2355
self.config.options.forwarding_fee_proportional_millionths
2340
2356
}
2341
2357
2358
+ pub fn get_manually_broadcast_outbound_channels(&self) -> Option<()> {
2359
+ self.manually_broadcast_outbound_channels
2360
+ }
2361
+
2342
2362
pub fn get_cltv_expiry_delta(&self) -> u16 {
2343
2363
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
2344
2364
}
@@ -2373,6 +2393,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2373
2393
self.channel_pending_event_emitted
2374
2394
}
2375
2395
2396
+ // Returns whether we already emitted a `FundingSigned` event.
2397
+ pub(crate) fn funding_signed_event_emitted(&self) -> bool {
2398
+ self.funding_signed_event_emitted
2399
+ }
2400
+
2376
2401
// Remembers that we already emitted a `ChannelPending` event.
2377
2402
pub(crate) fn set_channel_pending_event_emitted(&mut self) {
2378
2403
self.channel_pending_event_emitted = true;
@@ -2388,6 +2413,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2388
2413
self.channel_ready_event_emitted = true;
2389
2414
}
2390
2415
2416
+ // Remembers that we already emitted a `FundingSigned` event.
2417
+ pub(crate) fn set_funding_signed_event_emitted(&mut self) {
2418
+ self.funding_signed_event_emitted = true;
2419
+ }
2420
+
2391
2421
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
2392
2422
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
2393
2423
/// no longer be considered when forwarding HTLCs.
@@ -2424,6 +2454,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2424
2454
did_channel_update
2425
2455
}
2426
2456
2457
+ /// Marking the channel as manual broadcast is used in order to prevent LDK from automatically
2458
+ /// broadcasting the funding transaction.
2459
+ ///
2460
+ /// This is useful if you wish to get hold of the funding transaction before it is broadcasted
2461
+ /// via [`Event::FundingSigned`] event.
2462
+ ///
2463
+ /// [`Event::FundingSigned`]: crate::events::Event::FundingSigned
2464
+ pub fn mark_channel_as_manual_broadcast(&mut self) {
2465
+ self.manually_broadcast_outbound_channels = Some(());
2466
+ }
2467
+
2427
2468
/// Returns true if funding_signed was sent/received and the
2428
2469
/// funding transaction has been broadcast if necessary.
2429
2470
pub fn is_funding_broadcast(&self) -> bool {
@@ -8767,6 +8808,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8767
8808
8768
8809
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
8769
8810
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8811
+ let funding_signed_event_emitted = Some(self.context.funding_signed_event_emitted);
8770
8812
8771
8813
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
8772
8814
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8818,6 +8860,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8818
8860
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
8819
8861
// 45 and 47 are reserved for async signing
8820
8862
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8863
+ (51, self.context.manually_broadcast_outbound_channels, option),
8864
+ (53, funding_signed_event_emitted, option)
8821
8865
});
8822
8866
8823
8867
Ok(())
@@ -9106,6 +9150,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9106
9150
let mut outbound_scid_alias = None;
9107
9151
let mut channel_pending_event_emitted = None;
9108
9152
let mut channel_ready_event_emitted = None;
9153
+ let mut funding_signed_event_emitted = None;
9109
9154
9110
9155
let mut user_id_high_opt: Option<u64> = None;
9111
9156
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9118,6 +9163,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9118
9163
let mut holding_cell_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
9119
9164
9120
9165
let mut is_batch_funding: Option<()> = None;
9166
+ let mut manually_broadcast_outbound_channels: Option<()> = None;
9121
9167
9122
9168
let mut local_initiated_shutdown: Option<()> = None;
9123
9169
@@ -9159,6 +9205,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9159
9205
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
9160
9206
// 45 and 47 are reserved for async signing
9161
9207
(49, local_initiated_shutdown, option),
9208
+ (51, manually_broadcast_outbound_channels, option),
9209
+ (53, funding_signed_event_emitted, option),
9162
9210
});
9163
9211
9164
9212
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9382,6 +9430,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9382
9430
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
9383
9431
9384
9432
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
9433
+ funding_signed_event_emitted: funding_signed_event_emitted.unwrap_or(true),
9385
9434
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
9386
9435
9387
9436
#[cfg(any(test, fuzzing))]
@@ -9393,6 +9442,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9393
9442
local_initiated_shutdown,
9394
9443
9395
9444
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9445
+ manually_broadcast_outbound_channels,
9396
9446
},
9397
9447
#[cfg(any(dual_funding, splicing))]
9398
9448
dual_funding_channel_context: None,
0 commit comments