@@ -2280,6 +2280,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
22802280 context: self.context,
22812281 interactive_tx_signing_session: Some(signing_session),
22822282 holder_commitment_point,
2283+ is_v2_established: true,
22832284 };
22842285 Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
22852286 },
@@ -4645,6 +4646,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
46454646 pub context: ChannelContext<SP>,
46464647 pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
46474648 holder_commitment_point: HolderCommitmentPoint,
4649+ /// Indicates whether this funded channel had been established with V2 channel
4650+ /// establishment.
4651+ is_v2_established: bool,
46484652}
46494653
46504654#[cfg(any(test, fuzzing))]
@@ -6125,10 +6129,10 @@ impl<SP: Deref> FundedChannel<SP> where
61256129 }
61266130 }
61276131
6128- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<( Option<msgs::TxSignatures>, Option<Transaction>) , ChannelError>
6132+ pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
61296133 where L::Target: Logger
61306134 {
6131- if !matches!(self.context.channel_state, ChannelState::FundingNegotiated ) {
6135+ if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_) ) {
61326136 return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
61336137 }
61346138
@@ -6162,25 +6166,25 @@ impl<SP: Deref> FundedChannel<SP> where
61626166 // for spending. Doesn't seem to be anything in rust-bitcoin.
61636167 }
61646168
6165- let (tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
6169+ let (holder_tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
61666170 .map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
6167- if funding_tx_opt.is_some() {
6168- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
6169- }
6170- self.context.funding_transaction = funding_tx_opt.clone();
61716171
6172- self.context.next_funding_txid = None;
61736172
6174- // Clear out the signing session
6175- self.interactive_tx_signing_session = None;
6173+ if funding_tx_opt.is_some() {
6174+ // We have a finalized funding transaction, so we can set the funding transaction and reset the
6175+ // signing session fields.
6176+ self.context.funding_transaction = funding_tx_opt;
6177+ self.context.next_funding_txid = None;
6178+ self.interactive_tx_signing_session = None;
6179+ }
61766180
6177- if tx_signatures_opt .is_some() && self.context.channel_state.is_monitor_update_in_progress () {
6181+ if holder_tx_signatures_opt .is_some() && self.is_awaiting_initial_mon_persist () {
61786182 log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6179- self.context.monitor_pending_tx_signatures = tx_signatures_opt ;
6180- return Ok(( None, None) );
6183+ self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt ;
6184+ return Ok(None);
61816185 }
61826186
6183- Ok((tx_signatures_opt, funding_tx_opt) )
6187+ Ok(holder_tx_signatures_opt )
61846188 } else {
61856189 Err(ChannelError::Close((
61866190 "Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
@@ -6397,12 +6401,12 @@ impl<SP: Deref> FundedChannel<SP> where
63976401 assert!(self.context.channel_state.is_monitor_update_in_progress());
63986402 self.context.channel_state.clear_monitor_update_in_progress();
63996403
6400- // If we're past (or at) the AwaitingChannelReady stage on an outbound channel, try to
6401- // (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6404+ // If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
6405+ // try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
64026406 // first received the funding_signed.
64036407 let mut funding_broadcastable = None;
64046408 if let Some(funding_transaction) = &self.context.funding_transaction {
6405- if self.context.is_outbound() &&
6409+ if ( self.context.is_outbound() || self.is_v2_established() ) &&
64066410 (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
64076411 matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
64086412 {
@@ -8918,6 +8922,10 @@ impl<SP: Deref> FundedChannel<SP> where
89188922 false
89198923 }
89208924 }
8925+
8926+ pub fn is_v2_established(&self) -> bool {
8927+ self.is_v2_established
8928+ }
89218929}
89228930
89238931/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -9185,6 +9193,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
91859193 funding: self.funding,
91869194 context: self.context,
91879195 interactive_tx_signing_session: None,
9196+ is_v2_established: false,
91889197 holder_commitment_point,
91899198 };
91909199
@@ -9452,6 +9461,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
94529461 funding: self.funding,
94539462 context: self.context,
94549463 interactive_tx_signing_session: None,
9464+ is_v2_established: false,
94559465 holder_commitment_point,
94569466 };
94579467 let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -10263,7 +10273,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1026310273 let mut _val: u64 = Readable::read(reader)?;
1026410274 }
1026510275
10266- let channel_id = Readable::read(reader)?;
10276+ let channel_id: ChannelId = Readable::read(reader)?;
1026710277 let channel_state = ChannelState::from_u32(Readable::read(reader)?).map_err(|_| DecodeError::InvalidValue)?;
1026810278 let channel_value_satoshis = Readable::read(reader)?;
1026910279
@@ -10699,6 +10709,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1069910709 }
1070010710 },
1070110711 };
10712+ let is_v2_established = channel_id.is_v2_channel_id(
10713+ &channel_parameters.holder_pubkeys.revocation_basepoint,
10714+ &channel_parameters.counterparty_parameters.as_ref()
10715+ .expect("Persisted channel must have counterparty parameters").pubkeys.revocation_basepoint);
1070210716
1070310717 Ok(FundedChannel {
1070410718 funding: FundingScope {
@@ -10841,6 +10855,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1084110855 is_holder_quiescence_initiator: None,
1084210856 },
1084310857 interactive_tx_signing_session: None,
10858+ is_v2_established,
1084410859 holder_commitment_point,
1084510860 })
1084610861 }
0 commit comments