@@ -1383,6 +1383,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13831383 /// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
13841384 /// is_manual_broadcast is true) this will be a dummy empty transaction.
13851385 funding_transaction: Option<Transaction>,
1386+ /// Rememeber whether the funding transaction has been broadcast
1387+ funding_transaction_broadcast: bool,
13861388 /// This flag indicates that it is the user's responsibility to validated and broadcast the
13871389 /// funding transaction.
13881390 is_manual_broadcast: bool,
@@ -1791,6 +1793,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17911793 channel_type_features: channel_type.clone()
17921794 },
17931795 funding_transaction: None,
1796+ funding_transaction_broadcast: false,
17941797 is_batch_funding: None,
17951798
17961799 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 {
20242027 channel_type_features: channel_type.clone()
20252028 },
20262029 funding_transaction: None,
2030+ funding_transaction_broadcast: false,
20272031 is_batch_funding: None,
20282032
20292033 counterparty_cur_commitment_point: None,
@@ -3445,13 +3449,22 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
34453449 }
34463450 }
34473451
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+
34483461 /// Returns the transaction if there is a pending funding transaction that is yet to be
34493462 /// broadcast.
34503463 ///
34513464 /// Note that if [`Self::is_manual_broadcast`] is true the transaction will be a dummy
34523465 /// transaction.
34533466 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 ())
34553468 }
34563469
34573470 /// 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
53365349 (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
53375350 matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
53385351 {
5339- self.context.funding_transaction.take()
5352+ let res = self.context.funding_transaction_unless_broadcast();
5353+ self.context.funding_transaction_broadcast = true;
5354+ res
53405355 } else { None };
53415356 // That said, if the funding transaction is already confirmed (ie we're active with a
53425357 // minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
@@ -6594,7 +6609,9 @@ impl<SP: Deref> Channel<SP> where
65946609 // Because deciding we're awaiting initial broadcast spuriously could result in
65956610 // funds-loss (as we don't have a monitor, but have the funding transaction confirmed),
65966611 // 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+ }
65986615 assert!(self.context.monitor_pending_channel_ready);
65996616 assert_eq!(self.context.latest_monitor_update_id, 0);
66006617 return true;
@@ -7740,7 +7757,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
77407757 self.context.minimum_depth = Some(COINBASE_MATURITY);
77417758 }
77427759
7760+ debug_assert!(self.context.funding_transaction.is_none());
77437761 self.context.funding_transaction = Some(funding_transaction);
7762+ self.context.funding_transaction_broadcast = false;
77447763 self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
77457764
77467765 let funding_created = self.get_funding_created_msg(logger);
@@ -8874,6 +8893,7 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
88748893
88758894 self.context.channel_transaction_parameters.write(writer)?;
88768895 self.context.funding_transaction.write(writer)?;
8896+ self.context.funding_transaction_broadcast.write(writer)?;
88778897
88788898 self.context.counterparty_cur_commitment_point.write(writer)?;
88798899 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
92149234
92159235 let mut channel_parameters: ChannelTransactionParameters = Readable::read(reader)?;
92169236 let funding_transaction: Option<Transaction> = Readable::read(reader)?;
9237+ let funding_transaction_broadcast: bool = Readable::read(reader)?;
92179238
92189239 let counterparty_cur_commitment_point = Readable::read(reader)?;
92199240
@@ -9542,6 +9563,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95429563
95439564 channel_transaction_parameters: channel_parameters,
95449565 funding_transaction,
9566+ funding_transaction_broadcast,
95459567 is_batch_funding,
95469568
95479569 counterparty_cur_commitment_point,
0 commit comments