@@ -1383,6 +1383,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
1383
1383
/// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
1384
1384
/// is_manual_broadcast is true) this will be a dummy empty transaction.
1385
1385
funding_transaction: Option<Transaction>,
1386
+ /// Rememeber whether the funding transaction has been (re)broadcast (legacy)
1387
+ funding_transaction_rebroadcast_flag: bool,
1386
1388
/// This flag indicates that it is the user's responsibility to validated and broadcast the
1387
1389
/// funding transaction.
1388
1390
is_manual_broadcast: bool,
@@ -1791,6 +1793,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
1791
1793
channel_type_features: channel_type.clone()
1792
1794
},
1793
1795
funding_transaction: None,
1796
+ funding_transaction_rebroadcast_flag: false,
1794
1797
is_batch_funding: None,
1795
1798
1796
1799
counterparty_cur_commitment_point: Some(open_channel_fields.first_per_commitment_point),
@@ -2024,6 +2027,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2024
2027
channel_type_features: channel_type.clone()
2025
2028
},
2026
2029
funding_transaction: None,
2030
+ funding_transaction_rebroadcast_flag: false,
2027
2031
is_batch_funding: None,
2028
2032
2029
2033
counterparty_cur_commitment_point: None,
@@ -3445,13 +3449,22 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
3445
3449
}
3446
3450
}
3447
3451
3452
+ /// Returns funding_transaction unless it has been broadcast already
3453
+ pub fn funding_transaction_unless_rebroadcast(&self) -> Option<Transaction> {
3454
+ if !self.funding_transaction_rebroadcast_flag {
3455
+ self.funding_transaction.clone()
3456
+ } else {
3457
+ None
3458
+ }
3459
+ }
3460
+
3448
3461
/// Returns the transaction if there is a pending funding transaction that is yet to be
3449
3462
/// broadcast.
3450
3463
///
3451
3464
/// Note that if [`Self::is_manual_broadcast`] is true the transaction will be a dummy
3452
3465
/// transaction.
3453
3466
pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
3454
- self.if_unbroadcasted_funding(|| self.funding_transaction.clone ())
3467
+ self.if_unbroadcasted_funding(|| self.funding_transaction_unless_rebroadcast ())
3455
3468
}
3456
3469
3457
3470
/// Returns the transaction ID if there is a pending funding transaction that is yet to be
@@ -5336,7 +5349,10 @@ impl<SP: Deref> Channel<SP> where
5336
5349
(matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
5337
5350
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
5338
5351
{
5339
- self.context.funding_transaction.take()
5352
+ let res = self.context.funding_transaction_unless_rebroadcast();
5353
+ // Note: this is legacy logic, prevents (re)broadcasting twice, unclear if needed
5354
+ self.context.funding_transaction_rebroadcast_flag = true;
5355
+ res
5340
5356
} else { None };
5341
5357
// That said, if the funding transaction is already confirmed (ie we're active with a
5342
5358
// minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
@@ -6594,7 +6610,9 @@ impl<SP: Deref> Channel<SP> where
6594
6610
// Because deciding we're awaiting initial broadcast spuriously could result in
6595
6611
// funds-loss (as we don't have a monitor, but have the funding transaction confirmed),
6596
6612
// we hard-assert here, even in production builds.
6597
- if self.context.is_outbound() { assert!(self.context.funding_transaction.is_some()); }
6613
+ if self.context.is_outbound() {
6614
+ assert!(self.context.funding_transaction_unless_rebroadcast().is_some());
6615
+ }
6598
6616
assert!(self.context.monitor_pending_channel_ready);
6599
6617
assert_eq!(self.context.latest_monitor_update_id, 0);
6600
6618
return true;
@@ -7740,7 +7758,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7740
7758
self.context.minimum_depth = Some(COINBASE_MATURITY);
7741
7759
}
7742
7760
7761
+ debug_assert!(self.context.funding_transaction.is_none());
7743
7762
self.context.funding_transaction = Some(funding_transaction);
7763
+ self.context.funding_transaction_rebroadcast_flag = false;
7744
7764
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
7745
7765
7746
7766
let funding_created = self.get_funding_created_msg(logger);
@@ -8934,6 +8954,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8934
8954
let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
8935
8955
let next_holder_commitment_point = self.context.holder_commitment_point.next_point();
8936
8956
8957
+ let funding_transaction_rebroadcast_flag = Some(self.context.funding_transaction_rebroadcast_flag);
8958
+
8937
8959
write_tlv_fields!(writer, {
8938
8960
(0, self.context.announcement_sigs, option),
8939
8961
// minimum_depth and counterparty_selected_channel_reserve_satoshis used to have a
@@ -8974,7 +8996,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8974
8996
(47, next_holder_commitment_point, option),
8975
8997
(49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
8976
8998
(51, is_manual_broadcast, option), // Added in 0.0.124
8977
- (53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
8999
+ (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9000
+ (55, funding_transaction_rebroadcast_flag, option), // Added in 0.1
8978
9001
});
8979
9002
8980
9003
Ok(())
@@ -9289,6 +9312,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9289
9312
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
9290
9313
let mut is_manual_broadcast = None;
9291
9314
9315
+ let mut funding_transaction_rebroadcast_flag: Option<bool> = None;
9316
+
9292
9317
read_tlv_fields!(reader, {
9293
9318
(0, announcement_sigs, option),
9294
9319
(1, minimum_depth, option),
@@ -9324,6 +9349,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9324
9349
(49, local_initiated_shutdown, option),
9325
9350
(51, is_manual_broadcast, option),
9326
9351
(53, funding_tx_broadcast_safe_event_emitted, option),
9352
+ (55, funding_transaction_rebroadcast_flag, option), // Added in 0.1
9327
9353
});
9328
9354
9329
9355
let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9542,6 +9568,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9542
9568
9543
9569
channel_transaction_parameters: channel_parameters,
9544
9570
funding_transaction,
9571
+ // If value is missing, we use false, which may result in rebroadcast
9572
+ funding_transaction_rebroadcast_flag: funding_transaction_rebroadcast_flag.unwrap_or(false),
9545
9573
is_batch_funding,
9546
9574
9547
9575
counterparty_cur_commitment_point,
0 commit comments