@@ -1385,6 +1385,8 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
13851385 /// The transaction which funds this channel. Note that for manually-funded channels (i.e.,
13861386 /// is_manual_broadcast is true) this will be a dummy empty transaction.
13871387 funding_transaction: Option<Transaction>,
1388+ /// Rememeber whether the funding transaction has been broadcasted
1389+ funding_transaction_broadcasted_flag: bool,
13881390 /// This flag indicates that it is the user's responsibility to validated and broadcast the
13891391 /// funding transaction.
13901392 is_manual_broadcast: bool,
@@ -1939,6 +1941,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19391941 channel_type_features: channel_type.clone()
19401942 },
19411943 funding_transaction: None,
1944+ funding_transaction_broadcasted_flag: false,
19421945 is_batch_funding: None,
19431946
19441947 counterparty_cur_commitment_point: Some(open_channel_fields.first_per_commitment_point),
@@ -2172,6 +2175,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
21722175 channel_type_features: channel_type.clone()
21732176 },
21742177 funding_transaction: None,
2178+ funding_transaction_broadcasted_flag: false,
21752179 is_batch_funding: None,
21762180
21772181 counterparty_cur_commitment_point: None,
@@ -3595,13 +3599,22 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
35953599 }
35963600 }
35973601
3602+ /// Returns [`Self::funding_transaction`] if it's already set and has not been broadcasted yet
3603+ pub fn funding_transaction_unless_broadcasted(&self) -> Option<Transaction> {
3604+ if self.funding_transaction_broadcasted_flag {
3605+ None
3606+ } else {
3607+ self.funding_transaction.clone()
3608+ }
3609+ }
3610+
35983611 /// Returns the transaction if there is a pending funding transaction that is yet to be
35993612 /// broadcast.
36003613 ///
36013614 /// Note that if [`Self::is_manual_broadcast`] is true the transaction will be a dummy
36023615 /// transaction.
36033616 pub fn unbroadcasted_funding(&self) -> Option<Transaction> {
3604- self.if_unbroadcasted_funding(|| self.funding_transaction.clone ())
3617+ self.if_unbroadcasted_funding(|| self.funding_transaction_unless_broadcasted ())
36053618 }
36063619
36073620 /// Returns the transaction ID if there is a pending funding transaction that is yet to be
@@ -5486,7 +5499,10 @@ impl<SP: Deref> Channel<SP> where
54865499 (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
54875500 matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
54885501 {
5489- self.context.funding_transaction.take()
5502+ let res = self.context.funding_transaction_unless_broadcasted();
5503+ // Prevent broadcasting again in the future
5504+ self.context.funding_transaction_broadcasted_flag = true;
5505+ res
54905506 } else { None };
54915507 // That said, if the funding transaction is already confirmed (ie we're active with a
54925508 // minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
@@ -6747,7 +6763,9 @@ impl<SP: Deref> Channel<SP> where
67476763 // Because deciding we're awaiting initial broadcast spuriously could result in
67486764 // funds-loss (as we don't have a monitor, but have the funding transaction confirmed),
67496765 // we hard-assert here, even in production builds.
6750- if self.context.is_outbound() { assert!(self.context.funding_transaction.is_some()); }
6766+ if self.context.is_outbound() {
6767+ assert!(self.context.funding_transaction_unless_broadcasted().is_some());
6768+ }
67516769 assert!(self.context.monitor_pending_channel_ready);
67526770 assert_eq!(self.context.latest_monitor_update_id, 0);
67536771 return true;
@@ -7893,7 +7911,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
78937911 self.context.minimum_depth = Some(COINBASE_MATURITY);
78947912 }
78957913
7914+ debug_assert!(self.context.funding_transaction.is_none());
78967915 self.context.funding_transaction = Some(funding_transaction);
7916+ self.context.funding_transaction_broadcasted_flag = false;
78977917 self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
78987918
78997919 let funding_created = self.get_funding_created_msg(logger);
@@ -8994,7 +9014,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
89949014 (47, next_holder_commitment_point, option),
89959015 (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
89969016 (51, is_manual_broadcast, option), // Added in 0.0.124
8997- (53, funding_tx_broadcast_safe_event_emitted, option) // Added in 0.0.124
9017+ (53, funding_tx_broadcast_safe_event_emitted, option), // Added in 0.0.124
9018+ (55, self.context.funding_transaction_broadcasted_flag, required), // Added in 0.1
89989019 });
89999020
90009021 Ok(())
@@ -9309,6 +9330,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93099330 let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
93109331 let mut is_manual_broadcast = None;
93119332
9333+ let mut funding_transaction_broadcasted_flag: Option<bool> = None;
9334+
93129335 read_tlv_fields!(reader, {
93139336 (0, announcement_sigs, option),
93149337 (1, minimum_depth, option),
@@ -9344,6 +9367,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93449367 (49, local_initiated_shutdown, option),
93459368 (51, is_manual_broadcast, option),
93469369 (53, funding_tx_broadcast_safe_event_emitted, option),
9370+ (55, funding_transaction_broadcasted_flag, option), // Added in 0.1
93479371 });
93489372
93499373 let (channel_keys_id, holder_signer) = if let Some(channel_keys_id) = channel_keys_id {
@@ -9562,6 +9586,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95629586
95639587 channel_transaction_parameters: channel_parameters,
95649588 funding_transaction,
9589+ // If value is missing, we use false, which may result in rebroadcast
9590+ funding_transaction_broadcasted_flag: funding_transaction_broadcasted_flag.unwrap_or(false),
95659591 is_batch_funding,
95669592
95679593 counterparty_cur_commitment_point,
0 commit comments