@@ -1419,6 +1419,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1419
1419
// We track whether we already emitted a `ChannelPending` event.
1420
1420
channel_pending_event_emitted: bool,
1421
1421
1422
+ // We track whether we already emitted a `FundingTxBroadcastSafe` event.
1423
+ funding_tx_broadcast_safe_event_emitted: bool,
1424
+
1422
1425
// We track whether we already emitted a `ChannelReady` event.
1423
1426
channel_ready_event_emitted: bool,
1424
1427
@@ -1435,6 +1438,14 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1435
1438
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
1436
1439
/// store it here and only release it to the `ChannelManager` once it asks for it.
1437
1440
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1441
+
1442
+ /// Using this flag will prevent the funding transaction from being broadcasted
1443
+ /// and will allow the user to manually broadcast it.
1444
+ ///
1445
+ /// The funding transaction can be accessed through the [`Event::FundingTxBroadcastSafe`] event.
1446
+ ///
1447
+ /// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe
1448
+ is_manual_broadcast: bool,
1438
1449
}
1439
1450
1440
1451
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
@@ -1758,6 +1769,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1758
1769
outbound_scid_alias: 0,
1759
1770
1760
1771
channel_pending_event_emitted: false,
1772
+ funding_tx_broadcast_safe_event_emitted: false,
1761
1773
channel_ready_event_emitted: false,
1762
1774
1763
1775
#[cfg(any(test, fuzzing))]
@@ -1769,6 +1781,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1769
1781
local_initiated_shutdown: None,
1770
1782
1771
1783
blocked_monitor_updates: Vec::new(),
1784
+
1785
+ is_manual_broadcast: false,
1772
1786
};
1773
1787
1774
1788
Ok(channel_context)
@@ -1982,6 +1996,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1982
1996
outbound_scid_alias,
1983
1997
1984
1998
channel_pending_event_emitted: false,
1999
+ funding_tx_broadcast_safe_event_emitted: false,
1985
2000
channel_ready_event_emitted: false,
1986
2001
1987
2002
#[cfg(any(test, fuzzing))]
@@ -1992,6 +2007,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1992
2007
1993
2008
blocked_monitor_updates: Vec::new(),
1994
2009
local_initiated_shutdown: None,
2010
+ is_manual_broadcast: false,
1995
2011
})
1996
2012
}
1997
2013
@@ -2370,6 +2386,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2370
2386
self.config.options.forwarding_fee_proportional_millionths
2371
2387
}
2372
2388
2389
+ pub fn is_manual_broadcast(&self) -> bool {
2390
+ self.is_manual_broadcast
2391
+ }
2392
+
2373
2393
pub fn get_cltv_expiry_delta(&self) -> u16 {
2374
2394
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
2375
2395
}
@@ -2404,6 +2424,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2404
2424
self.channel_pending_event_emitted
2405
2425
}
2406
2426
2427
+ // Returns whether we already emitted a `FundingTxBroadcastSafe` event.
2428
+ pub(crate) fn funding_tx_broadcast_safe_event_emitted(&self) -> bool {
2429
+ self.funding_tx_broadcast_safe_event_emitted
2430
+ }
2431
+
2407
2432
// Remembers that we already emitted a `ChannelPending` event.
2408
2433
pub(crate) fn set_channel_pending_event_emitted(&mut self) {
2409
2434
self.channel_pending_event_emitted = true;
@@ -2419,6 +2444,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2419
2444
self.channel_ready_event_emitted = true;
2420
2445
}
2421
2446
2447
+ // Remembers that we already emitted a `FundingTxBroadcastSafe` event.
2448
+ pub(crate) fn set_funding_tx_broadcast_safe_event_emitted(&mut self) {
2449
+ self.funding_tx_broadcast_safe_event_emitted = true;
2450
+ }
2451
+
2422
2452
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
2423
2453
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
2424
2454
/// no longer be considered when forwarding HTLCs.
@@ -2455,6 +2485,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2455
2485
did_channel_update
2456
2486
}
2457
2487
2488
+ /// Marking the channel as manual broadcast is used in order to prevent LDK from automatically
2489
+ /// broadcasting the funding transaction.
2490
+ ///
2491
+ /// This is useful if you wish to get hold of the funding transaction before it is broadcasted
2492
+ /// via [`Event::FundingTxBroadcastSafe`] event.
2493
+ ///
2494
+ /// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe
2495
+ pub fn set_manual_broadcast(&mut self) {
2496
+ self.is_manual_broadcast = true;
2497
+ }
2498
+
2458
2499
/// Returns true if funding_signed was sent/received and the
2459
2500
/// funding transaction has been broadcast if necessary.
2460
2501
pub fn is_funding_broadcast(&self) -> bool {
@@ -8705,6 +8746,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8705
8746
8706
8747
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
8707
8748
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8749
+ let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
8708
8750
8709
8751
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
8710
8752
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8717,6 +8759,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8717
8759
if !self.context.monitor_pending_update_adds.is_empty() {
8718
8760
monitor_pending_update_adds = Some(&self.context.monitor_pending_update_adds);
8719
8761
}
8762
+ let is_manual_broadcast = Some(self.context.is_manual_broadcast);
8720
8763
8721
8764
// `current_point` will become optional when async signing is implemented.
8722
8765
let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
@@ -8761,6 +8804,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8761
8804
(45, cur_holder_commitment_point, option),
8762
8805
(47, next_holder_commitment_point, option),
8763
8806
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8807
+ (51, is_manual_broadcast, option),
8808
+ (53, funding_tx_broadcast_safe_event_emitted, option)
8764
8809
});
8765
8810
8766
8811
Ok(())
@@ -9049,6 +9094,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9049
9094
let mut outbound_scid_alias = None;
9050
9095
let mut channel_pending_event_emitted = None;
9051
9096
let mut channel_ready_event_emitted = None;
9097
+ let mut funding_tx_broadcast_safe_event_emitted = None;
9052
9098
9053
9099
let mut user_id_high_opt: Option<u64> = None;
9054
9100
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9072,6 +9118,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9072
9118
9073
9119
let mut cur_holder_commitment_point_opt: Option<PublicKey> = None;
9074
9120
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
9121
+ let mut is_manual_broadcast = None;
9075
9122
9076
9123
read_tlv_fields!(reader, {
9077
9124
(0, announcement_sigs, option),
@@ -9106,6 +9153,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9106
9153
(45, cur_holder_commitment_point_opt, option),
9107
9154
(47, next_holder_commitment_point_opt, option),
9108
9155
(49, local_initiated_shutdown, option),
9156
+ (51, is_manual_broadcast, option),
9157
+ (53, funding_tx_broadcast_safe_event_emitted, option),
9109
9158
});
9110
9159
9111
9160
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9346,6 +9395,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9346
9395
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
9347
9396
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
9348
9397
9398
+ funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
9349
9399
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
9350
9400
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
9351
9401
@@ -9358,6 +9408,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9358
9408
local_initiated_shutdown,
9359
9409
9360
9410
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9411
+ is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
9361
9412
},
9362
9413
#[cfg(any(dual_funding, splicing))]
9363
9414
dual_funding_channel_context: None,
0 commit comments