@@ -1377,7 +1377,12 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1377
1377
counterparty_forwarding_info: Option<CounterpartyForwardingInfo>,
1378
1378
1379
1379
pub(crate) channel_transaction_parameters: ChannelTransactionParameters,
1380
+ /// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
1381
+ /// is_manual_broadcast is true) this will be a dummy empty transaction.
1380
1382
funding_transaction: Option<Transaction>,
1383
+ /// This flag indicates that it is the user's responsibility to validated and broadcast the
1384
+ /// funding transaction.
1385
+ is_manual_broadcast: bool,
1381
1386
is_batch_funding: Option<()>,
1382
1387
1383
1388
counterparty_cur_commitment_point: Option<PublicKey>,
@@ -1465,6 +1470,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1465
1470
// We track whether we already emitted a `ChannelPending` event.
1466
1471
channel_pending_event_emitted: bool,
1467
1472
1473
+ // We track whether we already emitted a `FundingTxBroadcastSafe` event.
1474
+ funding_tx_broadcast_safe_event_emitted: bool,
1475
+
1468
1476
// We track whether we already emitted a `ChannelReady` event.
1469
1477
channel_ready_event_emitted: bool,
1470
1478
@@ -1805,6 +1813,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1805
1813
outbound_scid_alias: 0,
1806
1814
1807
1815
channel_pending_event_emitted: false,
1816
+ funding_tx_broadcast_safe_event_emitted: false,
1808
1817
channel_ready_event_emitted: false,
1809
1818
1810
1819
#[cfg(any(test, fuzzing))]
@@ -1816,6 +1825,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1816
1825
local_initiated_shutdown: None,
1817
1826
1818
1827
blocked_monitor_updates: Vec::new(),
1828
+
1829
+ is_manual_broadcast: false,
1819
1830
};
1820
1831
1821
1832
Ok(channel_context)
@@ -2032,6 +2043,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2032
2043
outbound_scid_alias,
2033
2044
2034
2045
channel_pending_event_emitted: false,
2046
+ funding_tx_broadcast_safe_event_emitted: false,
2035
2047
channel_ready_event_emitted: false,
2036
2048
2037
2049
#[cfg(any(test, fuzzing))]
@@ -2042,6 +2054,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2042
2054
2043
2055
blocked_monitor_updates: Vec::new(),
2044
2056
local_initiated_shutdown: None,
2057
+ is_manual_broadcast: false,
2045
2058
})
2046
2059
}
2047
2060
@@ -2420,6 +2433,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2420
2433
self.config.options.forwarding_fee_proportional_millionths
2421
2434
}
2422
2435
2436
+ pub fn is_manual_broadcast(&self) -> bool {
2437
+ self.is_manual_broadcast
2438
+ }
2439
+
2423
2440
pub fn get_cltv_expiry_delta(&self) -> u16 {
2424
2441
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
2425
2442
}
@@ -2454,6 +2471,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2454
2471
self.channel_pending_event_emitted
2455
2472
}
2456
2473
2474
+ // Returns whether we already emitted a `FundingTxBroadcastSafe` event.
2475
+ pub(crate) fn funding_tx_broadcast_safe_event_emitted(&self) -> bool {
2476
+ self.funding_tx_broadcast_safe_event_emitted
2477
+ }
2478
+
2457
2479
// Remembers that we already emitted a `ChannelPending` event.
2458
2480
pub(crate) fn set_channel_pending_event_emitted(&mut self) {
2459
2481
self.channel_pending_event_emitted = true;
@@ -2469,6 +2491,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2469
2491
self.channel_ready_event_emitted = true;
2470
2492
}
2471
2493
2494
+ // Remembers that we already emitted a `FundingTxBroadcastSafe` event.
2495
+ pub(crate) fn set_funding_tx_broadcast_safe_event_emitted(&mut self) {
2496
+ self.funding_tx_broadcast_safe_event_emitted = true;
2497
+ }
2498
+
2472
2499
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
2473
2500
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
2474
2501
/// no longer be considered when forwarding HTLCs.
@@ -2505,6 +2532,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2505
2532
did_channel_update
2506
2533
}
2507
2534
2535
+ /// Marking the channel as manual broadcast is used in order to prevent LDK from automatically
2536
+ /// broadcasting the funding transaction.
2537
+ ///
2538
+ /// This is useful if you wish to get hold of the funding transaction before it is broadcasted
2539
+ /// via [`Event::FundingTxBroadcastSafe`] event.
2540
+ ///
2541
+ /// [`Event::FundingTxBroadcastSafe`]: crate::events::Event::FundingTxBroadcastSafe
2542
+ pub fn set_manual_broadcast(&mut self) {
2543
+ self.is_manual_broadcast = true;
2544
+ }
2545
+
2508
2546
/// Returns true if funding_signed was sent/received and the
2509
2547
/// funding transaction has been broadcast if necessary.
2510
2548
pub fn is_funding_broadcast(&self) -> bool {
@@ -8871,6 +8909,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8871
8909
8872
8910
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
8873
8911
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8912
+ let funding_tx_broadcast_safe_event_emitted = Some(self.context.funding_tx_broadcast_safe_event_emitted);
8874
8913
8875
8914
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
8876
8915
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8883,6 +8922,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8883
8922
if !self.context.monitor_pending_update_adds.is_empty() {
8884
8923
monitor_pending_update_adds = Some(&self.context.monitor_pending_update_adds);
8885
8924
}
8925
+ let is_manual_broadcast = Some(self.context.is_manual_broadcast);
8886
8926
8887
8927
// `current_point` will become optional when async signing is implemented.
8888
8928
let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
@@ -8927,6 +8967,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8927
8967
(45, cur_holder_commitment_point, option),
8928
8968
(47, next_holder_commitment_point, option),
8929
8969
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8970
+ (51, is_manual_broadcast, option), // Added in 0.0.124
8971
+ (53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
8930
8972
});
8931
8973
8932
8974
Ok(())
@@ -9215,6 +9257,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9215
9257
let mut outbound_scid_alias = None;
9216
9258
let mut channel_pending_event_emitted = None;
9217
9259
let mut channel_ready_event_emitted = None;
9260
+ let mut funding_tx_broadcast_safe_event_emitted = None;
9218
9261
9219
9262
let mut user_id_high_opt: Option<u64> = None;
9220
9263
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9238,6 +9281,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9238
9281
9239
9282
let mut cur_holder_commitment_point_opt: Option<PublicKey> = None;
9240
9283
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
9284
+ let mut is_manual_broadcast = None;
9241
9285
9242
9286
read_tlv_fields!(reader, {
9243
9287
(0, announcement_sigs, option),
@@ -9272,6 +9316,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9272
9316
(45, cur_holder_commitment_point_opt, option),
9273
9317
(47, next_holder_commitment_point_opt, option),
9274
9318
(49, local_initiated_shutdown, option),
9319
+ (51, is_manual_broadcast, option),
9320
+ (53, funding_tx_broadcast_safe_event_emitted, option),
9275
9321
});
9276
9322
9277
9323
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9515,6 +9561,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9515
9561
// Later in the ChannelManager deserialization phase we scan for channels and assign scid aliases if its missing
9516
9562
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
9517
9563
9564
+ funding_tx_broadcast_safe_event_emitted: funding_tx_broadcast_safe_event_emitted.unwrap_or(false),
9518
9565
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
9519
9566
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
9520
9567
@@ -9527,6 +9574,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9527
9574
local_initiated_shutdown,
9528
9575
9529
9576
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9577
+ is_manual_broadcast: is_manual_broadcast.unwrap_or(false),
9530
9578
},
9531
9579
#[cfg(any(dual_funding, splicing))]
9532
9580
dual_funding_channel_context: None,
0 commit comments