@@ -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 (re)broadcast (legacy)
1387+ funding_transaction_rebroadcast_flag: 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_rebroadcast_flag: 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_rebroadcast_flag: 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 [`Self::funding_transaction`] if it's already set and has not been broadcast yet
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+
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_rebroadcast ())
34553468 }
34563469
34573470 /// 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
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_rebroadcast();
5353+ // Note: this is legacy logic, prevents (re)broadcasting twice, unclear if needed
5354+ self.context.funding_transaction_rebroadcast_flag = true;
5355+ res
53405356 } else { None };
53415357 // That said, if the funding transaction is already confirmed (ie we're active with a
53425358 // minimum_depth over 0) don't bother re-broadcasting the confirmed funding tx.
@@ -6594,7 +6610,9 @@ impl<SP: Deref> Channel<SP> where
65946610 // Because deciding we're awaiting initial broadcast spuriously could result in
65956611 // funds-loss (as we don't have a monitor, but have the funding transaction confirmed),
65966612 // 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+ }
65986616 assert!(self.context.monitor_pending_channel_ready);
65996617 assert_eq!(self.context.latest_monitor_update_id, 0);
66006618 return true;
@@ -7740,7 +7758,9 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
77407758 self.context.minimum_depth = Some(COINBASE_MATURITY);
77417759 }
77427760
7761+ debug_assert!(self.context.funding_transaction.is_none());
77437762 self.context.funding_transaction = Some(funding_transaction);
7763+ self.context.funding_transaction_rebroadcast_flag = false;
77447764 self.context.is_batch_funding = Some(()).filter(|_| is_batch_funding);
77457765
77467766 let funding_created = self.get_funding_created_msg(logger);
@@ -8934,6 +8954,8 @@ impl<SP: Deref> Writeable for Channel<SP> where SP::Target: SignerProvider {
89348954 let cur_holder_commitment_point = Some(self.context.holder_commitment_point.current_point());
89358955 let next_holder_commitment_point = self.context.holder_commitment_point.next_point();
89368956
8957+ let funding_transaction_rebroadcast_flag = Some(self.context.funding_transaction_rebroadcast_flag);
8958+
89378959 write_tlv_fields!(writer, {
89388960 (0, self.context.announcement_sigs, option),
89398961 // 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 {
89748996 (47, next_holder_commitment_point, option),
89758997 (49, self.context.local_initiated_shutdown, option), // Added in 0.0.122
89768998 (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
89789001 });
89799002
89809003 Ok(())
@@ -9289,6 +9312,8 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
92899312 let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
92909313 let mut is_manual_broadcast = None;
92919314
9315+ let mut funding_transaction_rebroadcast_flag: Option<bool> = None;
9316+
92929317 read_tlv_fields!(reader, {
92939318 (0, announcement_sigs, option),
92949319 (1, minimum_depth, option),
@@ -9324,6 +9349,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93249349 (49, local_initiated_shutdown, option),
93259350 (51, is_manual_broadcast, option),
93269351 (53, funding_tx_broadcast_safe_event_emitted, option),
9352+ (55, funding_transaction_rebroadcast_flag, option), // Added in 0.1
93279353 });
93289354
93299355 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
95429568
95439569 channel_transaction_parameters: channel_parameters,
95449570 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),
95459573 is_batch_funding,
95469574
95479575 counterparty_cur_commitment_point,
0 commit comments