@@ -1331,7 +1331,12 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1331
1331
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
1332
1332
1333
1333
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.
1334
1336
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,
1335
1340
is_batch_funding: Option<()>,
1336
1341
1337
1342
counterparty_cur_commitment_point: Option<PublicKey>,
@@ -1419,6 +1424,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1419
1424
// We track whether we already emitted a `ChannelPending` event.
1420
1425
channel_pending_event_emitted: bool,
1421
1426
1427
+ // We track whether we already emitted a `FundingTxBroadcastSafe` event.
1428
+ funding_tx_broadcast_safe_event_emitted: bool,
1429
+
1422
1430
// We track whether we already emitted a `ChannelReady` event.
1423
1431
channel_ready_event_emitted: bool,
1424
1432
@@ -1758,6 +1766,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1758
1766
outbound_scid_alias: 0,
1759
1767
1760
1768
channel_pending_event_emitted: false,
1769
+ funding_tx_broadcast_safe_event_emitted: false,
1761
1770
channel_ready_event_emitted: false,
1762
1771
1763
1772
#[cfg(any(test, fuzzing))]
@@ -1769,6 +1778,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1769
1778
local_initiated_shutdown: None,
1770
1779
1771
1780
blocked_monitor_updates: Vec::new(),
1781
+
1782
+ is_manual_broadcast: false,
1772
1783
};
1773
1784
1774
1785
Ok(channel_context)
@@ -1982,6 +1993,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1982
1993
outbound_scid_alias,
1983
1994
1984
1995
channel_pending_event_emitted: false,
1996
+ funding_tx_broadcast_safe_event_emitted: false,
1985
1997
channel_ready_event_emitted: false,
1986
1998
1987
1999
#[cfg(any(test, fuzzing))]
@@ -1992,6 +2004,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1992
2004
1993
2005
blocked_monitor_updates: Vec::new(),
1994
2006
local_initiated_shutdown: None,
2007
+ is_manual_broadcast: false,
1995
2008
})
1996
2009
}
1997
2010
@@ -2370,6 +2383,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2370
2383
self.config.options.forwarding_fee_proportional_millionths
2371
2384
}
2372
2385
2386
+ pub fn is_manual_broadcast(&self) -> bool {
2387
+ self.is_manual_broadcast
2388
+ }
2389
+
2373
2390
pub fn get_cltv_expiry_delta(&self) -> u16 {
2374
2391
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
2375
2392
}
@@ -2404,6 +2421,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2404
2421
self.channel_pending_event_emitted
2405
2422
}
2406
2423
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
+
2407
2429
// Remembers that we already emitted a `ChannelPending` event.
2408
2430
pub(crate) fn set_channel_pending_event_emitted(&mut self) {
2409
2431
self.channel_pending_event_emitted = true;
@@ -2419,6 +2441,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2419
2441
self.channel_ready_event_emitted = true;
2420
2442
}
2421
2443
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
+
2422
2449
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
2423
2450
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
2424
2451
/// no longer be considered when forwarding HTLCs.
@@ -2455,6 +2482,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2455
2482
did_channel_update
2456
2483
}
2457
2484
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
+
2458
2496
/// Returns true if funding_signed was sent/received and the
2459
2497
/// funding transaction has been broadcast if necessary.
2460
2498
pub fn is_funding_broadcast(&self) -> bool {
@@ -8705,6 +8743,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8705
8743
8706
8744
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
8707
8745
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8746
+ let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
8708
8747
8709
8748
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
8710
8749
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8717,6 +8756,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8717
8756
if !self.context.monitor_pending_update_adds.is_empty() {
8718
8757
monitor_pending_update_adds = Some(&self.context.monitor_pending_update_adds);
8719
8758
}
8759
+ let is_manual_broadcast = Some(self.context.is_manual_broadcast);
8720
8760
8721
8761
// `current_point` will become optional when async signing is implemented.
8722
8762
let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
@@ -8761,6 +8801,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8761
8801
(45, cur_holder_commitment_point, option),
8762
8802
(47, next_holder_commitment_point, option),
8763
8803
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8804
+ (51, is_manual_broadcast, option), // Added in 0.0.124
8805
+ (53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
8764
8806
});
8765
8807
8766
8808
Ok(())
@@ -9049,6 +9091,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9049
9091
let mut outbound_scid_alias = None;
9050
9092
let mut channel_pending_event_emitted = None;
9051
9093
let mut channel_ready_event_emitted = None;
9094
+ let mut funding_tx_broadcast_safe_event_emitted = None;
9052
9095
9053
9096
let mut user_id_high_opt: Option<u64> = None;
9054
9097
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9072,6 +9115,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9072
9115
9073
9116
let mut cur_holder_commitment_point_opt: Option<PublicKey> = None;
9074
9117
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
9118
+ let mut is_manual_broadcast = None;
9075
9119
9076
9120
read_tlv_fields!(reader, {
9077
9121
(0, announcement_sigs, option),
@@ -9106,6 +9150,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9106
9150
(45, cur_holder_commitment_point_opt, option),
9107
9151
(47, next_holder_commitment_point_opt, option),
9108
9152
(49, local_initiated_shutdown, option),
9153
+ (51, is_manual_broadcast, option),
9154
+ (53, funding_tx_broadcast_safe_event_emitted, option),
9109
9155
});
9110
9156
9111
9157
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9346,6 +9392,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9346
9392
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
9347
9393
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
9348
9394
9395
+ funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
9349
9396
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
9350
9397
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
9351
9398
@@ -9358,6 +9405,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9358
9405
local_initiated_shutdown,
9359
9406
9360
9407
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9408
+ is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
9361
9409
},
9362
9410
#[cfg(any(dual_funding, splicing))]
9363
9411
dual_funding_channel_context: None,
0 commit comments