@@ -1529,6 +1529,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1529
1529
1530
1530
// We track whether we already emitted a `ChannelPending` event.
1531
1531
channel_pending_event_emitted: bool,
1532
+
1533
+ // We track whether we already emitted a `FundingSigned` event.
1534
+ funding_signed_event_emitted: bool,
1532
1535
1533
1536
// We track whether we already emitted a `ChannelReady` event.
1534
1537
channel_ready_event_emitted: bool,
@@ -1546,6 +1549,16 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1546
1549
/// If we can't release a [`ChannelMonitorUpdate`] until some external action completes, we
1547
1550
/// store it here and only release it to the `ChannelManager` once it asks for it.
1548
1551
blocked_monitor_updates: Vec<PendingChannelMonitorUpdate>,
1552
+
1553
+ /// Upon receving a `FundingSigned` message, if the channel is
1554
+ /// outbound and we are ready to broadcast the funding
1555
+ /// transaction, LDK will broadcast it and set the channel state
1556
+ /// to `ChannelPending`.
1557
+ ///
1558
+ /// Using this flag will allow you to halt the broadcast of the
1559
+ /// funding transaction and the channel state will be set to
1560
+ /// `FundingSigned`.
1561
+ manually_broadcast_outbound_channels: Option<()>,
1549
1562
}
1550
1563
1551
1564
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
@@ -1866,6 +1879,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1866
1879
outbound_scid_alias: 0,
1867
1880
1868
1881
channel_pending_event_emitted: false,
1882
+ funding_signed_event_emitted: false,
1869
1883
channel_ready_event_emitted: false,
1870
1884
1871
1885
#[cfg(any(test, fuzzing))]
@@ -1877,6 +1891,8 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1877
1891
local_initiated_shutdown: None,
1878
1892
1879
1893
blocked_monitor_updates: Vec::new(),
1894
+
1895
+ manually_broadcast_outbound_channels: None,
1880
1896
};
1881
1897
1882
1898
Ok(channel_context)
@@ -2087,6 +2103,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2087
2103
outbound_scid_alias,
2088
2104
2089
2105
channel_pending_event_emitted: false,
2106
+ funding_signed_event_emitted: false,
2090
2107
channel_ready_event_emitted: false,
2091
2108
2092
2109
#[cfg(any(test, fuzzing))]
@@ -2097,6 +2114,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2097
2114
2098
2115
blocked_monitor_updates: Vec::new(),
2099
2116
local_initiated_shutdown: None,
2117
+ manually_broadcast_outbound_channels: None,
2100
2118
})
2101
2119
}
2102
2120
@@ -2117,6 +2135,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2117
2135
self.channel_transaction_parameters.is_outbound_from_holder
2118
2136
}
2119
2137
2138
+ pub fn get_funding_transaction(&self) -> Option<&Transaction> {
2139
+ self.funding_transaction.as_ref()
2140
+ }
2141
+
2120
2142
/// Gets the fee we'd want to charge for adding an HTLC output to this Channel
2121
2143
/// Allowed in any state (including after shutdown)
2122
2144
pub fn get_outbound_forwarding_fee_base_msat(&self) -> u32 {
@@ -2338,6 +2360,10 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2338
2360
self.config.options.forwarding_fee_proportional_millionths
2339
2361
}
2340
2362
2363
+ pub fn get_manually_broadcast_outbound_channels(&self) -> Option<()> {
2364
+ self.manually_broadcast_outbound_channels
2365
+ }
2366
+
2341
2367
pub fn get_cltv_expiry_delta(&self) -> u16 {
2342
2368
cmp::max(self.config.options.cltv_expiry_delta, MIN_CLTV_EXPIRY_DELTA)
2343
2369
}
@@ -2364,13 +2390,25 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2364
2390
2365
2391
// Checks whether we should emit a `ChannelPending` event.
2366
2392
pub(crate) fn should_emit_channel_pending_event(&mut self) -> bool {
2367
- self.is_funding_broadcast() && !self.channel_pending_event_emitted
2393
+ self.is_funding_broadcast() && !self.channel_pending_event_emitted && self.manually_broadcast_outbound_channels.is_none()
2394
+ }
2395
+
2396
+ // Checks whether we should emit a `FundingSigned` event.
2397
+ pub(crate) fn should_emit_funding_signed_event(&self) -> bool {
2398
+ self.get_funding_transaction().is_some()
2399
+ && self.manually_broadcast_outbound_channels.is_some()
2400
+ && !self.funding_signed_event_emitted
2368
2401
}
2369
2402
2370
2403
// Returns whether we already emitted a `ChannelPending` event.
2371
2404
pub(crate) fn channel_pending_event_emitted(&self) -> bool {
2372
2405
self.channel_pending_event_emitted
2373
2406
}
2407
+
2408
+ // Returns whether we already emitted a `FundingSigned` event.
2409
+ pub(crate) fn funding_signed_event_emitted(&self) -> bool {
2410
+ self.funding_signed_event_emitted
2411
+ }
2374
2412
2375
2413
// Remembers that we already emitted a `ChannelPending` event.
2376
2414
pub(crate) fn set_channel_pending_event_emitted(&mut self) {
@@ -2387,6 +2425,11 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2387
2425
self.channel_ready_event_emitted = true;
2388
2426
}
2389
2427
2428
+ // Remembers that we already emitted a `FundingSigned` event.
2429
+ pub(crate) fn set_funding_signed_event_emitted(&mut self) {
2430
+ self.funding_signed_event_emitted = true;
2431
+ }
2432
+
2390
2433
/// Tracks the number of ticks elapsed since the previous [`ChannelConfig`] was updated. Once
2391
2434
/// [`EXPIRE_PREV_CONFIG_TICKS`] is reached, the previous config is considered expired and will
2392
2435
/// no longer be considered when forwarding HTLCs.
@@ -2423,11 +2466,17 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2423
2466
did_channel_update
2424
2467
}
2425
2468
2469
+ /// Fix It
2470
+ pub fn update_manual_channel(&mut self) {
2471
+ self.manually_broadcast_outbound_channels = Some(());
2472
+ }
2473
+
2426
2474
/// Returns true if funding_signed was sent/received and the
2427
2475
/// funding transaction has been broadcast if necessary.
2428
2476
pub fn is_funding_broadcast(&self) -> bool {
2429
- !self.channel_state.is_pre_funded_state() &&
2430
- !matches!(self.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH))
2477
+ !self.channel_state.is_pre_funded_state()
2478
+ && !matches!(self.channel_state, ChannelState::AwaitingChannelReady(flags) if
2479
+ flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH))
2431
2480
}
2432
2481
2433
2482
/// Transaction nomenclature is somewhat confusing here as there are many different cases - a
@@ -4131,7 +4180,7 @@ impl<SP: Deref> Channel<SP> where
4131
4180
// If we reconnected before sending our `channel_ready` they may still resend theirs.
4132
4181
check_reconnection = true;
4133
4182
} else if flags.clone().clear(AwaitingChannelReadyFlags::WAITING_FOR_BATCH).is_empty() {
4134
- self.context.channel_state.set_their_channel_ready();
4183
+ self.context.channel_state.set_their_channel_ready();
4135
4184
} else if flags == AwaitingChannelReadyFlags::OUR_CHANNEL_READY {
4136
4185
self.context.channel_state = ChannelState::ChannelReady(self.context.channel_state.with_funded_state_flags_mask().into());
4137
4186
self.context.update_time_counter += 1;
@@ -5222,10 +5271,13 @@ impl<SP: Deref> Channel<SP> where
5222
5271
(matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
5223
5272
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
5224
5273
{
5225
- self.context.funding_transaction.take()
5274
+ // this clone is added so the value can still be accessed after the take
5275
+ // (which is necessary for the FundingSigned event)
5276
+ self.context.funding_transaction.clone().take()
5226
5277
} else { None };
5227
5278
// That said, if the funding transaction is already confirmed (ie we're active with a
5228
5279
// minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
5280
+
5229
5281
if matches!(self.context.channel_state, ChannelState::ChannelReady(_)) && self.context.minimum_depth != Some(0) {
5230
5282
funding_broadcastable = None;
5231
5283
}
@@ -8766,6 +8818,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8766
8818
8767
8819
let channel_pending_event_emitted = Some(self.context.channel_pending_event_emitted);
8768
8820
let channel_ready_event_emitted = Some(self.context.channel_ready_event_emitted);
8821
+ let funding_signed_event_emitted = Some(self.context.funding_signed_event_emitted);
8769
8822
8770
8823
// `user_id` used to be a single u64 value. In order to remain backwards compatible with
8771
8824
// versions prior to 0.0.113, the u128 is serialized as two separate u64 values. Therefore,
@@ -8817,6 +8870,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8817
8870
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
8818
8871
// 45 and 47 are reserved for async signing
8819
8872
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8873
+ (51, self.context.manually_broadcast_outbound_channels, option),
8874
+ (53, funding_signed_event_emitted, option)
8820
8875
});
8821
8876
8822
8877
Ok(())
@@ -9105,6 +9160,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9105
9160
let mut outbound_scid_alias = None;
9106
9161
let mut channel_pending_event_emitted = None;
9107
9162
let mut channel_ready_event_emitted = None;
9163
+ let mut funding_signed_event_emitted = None;
9108
9164
9109
9165
let mut user_id_high_opt: Option<u64> = None;
9110
9166
let mut channel_keys_id: Option<[u8; 32]> = None;
@@ -9117,6 +9173,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9117
9173
let mut holding_cell_skimmed_fees_opt: Option<Vec<Option<u64>>> = None;
9118
9174
9119
9175
let mut is_batch_funding: Option<()> = None;
9176
+ let mut manually_broadcast_outbound_channels: Option<()> = None;
9120
9177
9121
9178
let mut local_initiated_shutdown: Option<()> = None;
9122
9179
@@ -9158,6 +9215,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9158
9215
(43, malformed_htlcs, optional_vec), // Added in 0.0.119
9159
9216
// 45 and 47 are reserved for async signing
9160
9217
(49, local_initiated_shutdown, option),
9218
+ (51, manually_broadcast_outbound_channels, option),
9219
+ (53, funding_signed_event_emitted, option),
9161
9220
});
9162
9221
9163
9222
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9381,6 +9440,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9381
9440
outbound_scid_alias: outbound_scid_alias.unwrap_or(0),
9382
9441
9383
9442
channel_pending_event_emitted: channel_pending_event_emitted.unwrap_or(true),
9443
+ funding_signed_event_emitted: funding_signed_event_emitted.unwrap_or(true),
9384
9444
channel_ready_event_emitted: channel_ready_event_emitted.unwrap_or(true),
9385
9445
9386
9446
#[cfg(any(test, fuzzing))]
@@ -9392,6 +9452,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9392
9452
local_initiated_shutdown,
9393
9453
9394
9454
blocked_monitor_updates: blocked_monitor_updates.unwrap(),
9455
+ manually_broadcast_outbound_channels,
9395
9456
},
9396
9457
#[cfg(any(dual_funding, splicing))]
9397
9458
dual_funding_channel_context: None,
0 commit comments