@@ -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
@@ -2118,6 +2134,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2118
2134
self.channel_transaction_parameters.is_outbound_from_holder
2119
2135
}
2120
2136
2137
+ pub fn get_funding_transaction(&self) -> Option<&Transaction> {
2138
+ self.funding_transaction.as_ref()
2139
+ }
2140
+
2121
2141
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
2122
2142
/// Allowed in any state (including after shutdown)
2123
2143
pub fn get_outbound_forwarding_fee_base_msat(&self) -> u32 {
@@ -2339,6 +2359,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2339
2359
self.config.options.forwarding_fee_proportional_millionths
2340
2360
}
2341
2361
2362
+ pub fn get_manually_broadcast_outbound_channels(&self) -> Option<()> {
2363
+ self.manually_broadcast_outbound_channels
2364
+ }
2365
+
2342
2366
pub fn get_cltv_expiry_delta(&self) -> u16 {
2343
2367
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
2344
2368
}
@@ -2365,13 +2389,25 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2365
2389
2366
2390
// Checks whether we should emit a `ChannelPending` event.
2367
2391
pub(crate) fn should_emit_channel_pending_event(&mut self) -> bool {
2368
- self.is_funding_broadcast() && !self.channel_pending_event_emitted
2392
+ self.is_funding_broadcast() && !self.channel_pending_event_emitted && self.manually_broadcast_outbound_channels.is_none()
2393
+ }
2394
+
2395
+ // Checks whether we should emit a `FundingSigned` event.
2396
+ pub(crate) fn should_emit_funding_signed_event(&self) -> bool {
2397
+ self.get_funding_transaction().is_some()
2398
+ && self.manually_broadcast_outbound_channels.is_some()
2399
+ && !self.funding_signed_event_emitted
2369
2400
}
2370
2401
2371
2402
// Returns whether we already emitted a `ChannelPending` event.
2372
2403
pub(crate) fn channel_pending_event_emitted(&self) -> bool {
2373
2404
self.channel_pending_event_emitted
2374
2405
}
2406
+
2407
+ // Returns whether we already emitted a `FundingSigned` event.
2408
+ pub(crate) fn funding_signed_event_emitted(&self) -> bool {
2409
+ self.funding_signed_event_emitted
2410
+ }
2375
2411
2376
2412
// Remembers that we already emitted a `ChannelPending` event.
2377
2413
pub(crate) fn set_channel_pending_event_emitted(&mut self) {
@@ -2388,6 +2424,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2388
2424
self.channel_ready_event_emitted = true;
2389
2425
}
2390
2426
2427
+ // Remembers that we already emitted a `FundingSigned` event.
2428
+ pub(crate) fn set_funding_signed_event_emitted(&mut self) {
2429
+ self.funding_signed_event_emitted = true;
2430
+ }
2431
+
2391
2432
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
2392
2433
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
2393
2434
/// no longer be considered when forwarding HTLCs.
@@ -2424,11 +2465,23 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2424
2465
did_channel_update
2425
2466
}
2426
2467
2468
+ /// Marking the channel as manual broadcast is used in order to prevent LDK from automatically
2469
+ /// broadcasting the funding transaction.
2470
+ ///
2471
+ /// This is useful if you wish to get hold of the funding transaction before it is broadcasted
2472
+ /// via [`Events::FundingSigned`] event.
2473
+ ///
2474
+ /// [`Event::FundingSigned`]: crate::events::Event::FundingSigned
2475
+ pub fn mark_channel_as_manual_broadcast(&mut self) {
2476
+ self.manually_broadcast_outbound_channels = Some(());
2477
+ }
2478
+
2427
2479
/// Returns true if funding_signed was sent/received and the
2428
2480
/// funding transaction has been broadcast if necessary.
2429
2481
pub fn is_funding_broadcast(&self) -> bool {
2430
- !self.channel_state.is_pre_funded_state() &&
2431
- !matches!(self.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH))
2482
+ !self.channel_state.is_pre_funded_state()
2483
+ && !matches!(self.channel_state, ChannelState::AwaitingChannelReady(flags) if
2484
+ flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH))
2432
2485
}
2433
2486
2434
2487
/// Transaction nomenclature is somewhat confusing here as there are many different cases - a
@@ -5219,10 +5272,11 @@ impl<SP: Deref> Channel<SP> where
5219
5272
// (re-)broadcast the funding transaction as we may have declined to broadcast it when we
5220
5273
// first received the funding_signed.
5221
5274
let mut funding_broadcastable =
5222
- if self.context.is_outbound() &&
5223
- (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
5224
- matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
5225
- {
5275
+ if self.context.manually_broadcast_outbound_channels.is_none()
5276
+ && self.context.is_outbound()
5277
+ && (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags)
5278
+ if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH))
5279
+ || matches!(self.context.channel_state, ChannelState::ChannelReady(_))) {
5226
5280
self.context.funding_transaction.take()
5227
5281
} else { None };
5228
5282
// That said, if the funding transaction is already confirmed (ie we're active with a
@@ -8767,6 +8821,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8767
8821
8768
8822
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
8769
8823
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8824
+ let funding_signed_event_emitted = Some(self.context.funding_signed_event_emitted);
8770
8825
8771
8826
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
8772
8827
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8818,6 +8873,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8818
8873
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
8819
8874
// 45 and 47 are reserved for async signing
8820
8875
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8876
+ (51, self.context.manually_broadcast_outbound_channels, option),
8877
+ (53, funding_signed_event_emitted, option)
8821
8878
});
8822
8879
8823
8880
Ok(())
@@ -9106,6 +9163,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9106
9163
let mut outbound_scid_alias = None;
9107
9164
let mut channel_pending_event_emitted = None;
9108
9165
let mut channel_ready_event_emitted = None;
9166
+ let mut funding_signed_event_emitted = None;
9109
9167
9110
9168
let mut user_id_high_opt: Option<u64> = None;
9111
9169
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9118,6 +9176,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9118
9176
let mut holding_cell_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
9119
9177
9120
9178
let mut is_batch_funding: Option<()> = None;
9179
+ let mut manually_broadcast_outbound_channels: Option<()> = None;
9121
9180
9122
9181
let mut local_initiated_shutdown: Option<()> = None;
9123
9182
@@ -9159,6 +9218,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9159
9218
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
9160
9219
// 45 and 47 are reserved for async signing
9161
9220
(49, local_initiated_shutdown, option),
9221
+ (51, manually_broadcast_outbound_channels, option),
9222
+ (53, funding_signed_event_emitted, option),
9162
9223
});
9163
9224
9164
9225
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9382,6 +9443,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9382
9443
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
9383
9444
9384
9445
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
9446
+ funding_signed_event_emitted: funding_signed_event_emitted.unwrap_or(true),
9385
9447
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
9386
9448
9387
9449
#[cfg(any(test, fuzzing))]
@@ -9393,6 +9455,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9393
9455
local_initiated_shutdown,
9394
9456
9395
9457
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9458
+ manually_broadcast_outbound_channels,
9396
9459
},
9397
9460
#[cfg(any(dual_funding, splicing))]
9398
9461
dual_funding_channel_context: None,
0 commit comments