@@ -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 broadcast
1387
+ funding_transaction_broadcast: 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_broadcast: 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_broadcast: 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_broadcast(&self) -> Option<Transaction> {
3454
+ if !self.funding_transaction_broadcast {
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_broadcast ())
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,9 @@ 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_broadcast();
5353
+ self.context.funding_transaction_broadcast = true;
5354
+ res
5340
5355
} else { None };
5341
5356
// That said, if the funding transaction is already confirmed (ie we're active with a
5342
5357
// minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
@@ -6594,7 +6609,9 @@ impl<SP: Deref> Channel<SP> where
6594
6609
// Because deciding we're awaiting initial broadcast spuriously could result in
6595
6610
// funds-loss (as we don't have a monitor, but have the funding transaction confirmed),
6596
6611
// we hard-assert here, even in production builds.
6597
- if self.context.is_outbound() { assert!(self.context.funding_transaction.is_some()); }
6612
+ if self.context.is_outbound() {
6613
+ assert!(self.context.funding_transaction_unless_broadcast().is_some());
6614
+ }
6598
6615
assert!(self.context.monitor_pending_channel_ready);
6599
6616
assert_eq!(self.context.latest_monitor_update_id, 0);
6600
6617
return true;
@@ -7740,7 +7757,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7740
7757
self.context.minimum_depth = Some(COINBASE_MATURITY);
7741
7758
}
7742
7759
7760
+ debug_assert!(self.context.funding_transaction.is_none());
7743
7761
self.context.funding_transaction = Some(funding_transaction);
7762
+ self.context.funding_transaction_broadcast = false;
7744
7763
self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
7745
7764
7746
7765
let funding_created = self.get_funding_created_msg(logger);
@@ -8874,6 +8893,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
8874
8893
8875
8894
self.context.channel_transaction_parameters.write(writer)?;
8876
8895
self.context.funding_transaction.write(writer)?;
8896
+ self.context.funding_transaction_broadcast.write(writer)?;
8877
8897
8878
8898
self.context.counterparty_cur_commitment_point.write(writer)?;
8879
8899
self.context.counterparty_prev_commitment_point.write(writer)?;
@@ -9214,6 +9234,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9214
9234
9215
9235
let mut channel_parameters: ChannelTransactionParameters = Readable::read(reader)?;
9216
9236
let funding_transaction: Option<Transaction> = Readable::read(reader)?;
9237
+ let funding_transaction_broadcast: bool = Readable::read(reader)?;
9217
9238
9218
9239
let counterparty_cur_commitment_point = Readable::read(reader)?;
9219
9240
@@ -9542,6 +9563,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9542
9563
9543
9564
channel_transaction_parameters: channel_parameters,
9544
9565
funding_transaction,
9566
+ funding_transaction_broadcast,
9545
9567
is_batch_funding,
9546
9568
9547
9569
counterparty_cur_commitment_point,
0 commit comments