@@ -2186,6 +2186,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
21862186 context: self.context,
21872187 interactive_tx_signing_session: Some(signing_session),
21882188 holder_commitment_point,
2189+ is_v2_established: true,
21892190 };
21902191 Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
21912192 },
@@ -4540,6 +4541,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
45404541 pub context: ChannelContext<SP>,
45414542 pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
45424543 holder_commitment_point: HolderCommitmentPoint,
4544+ /// Indicates whether this funded channel had been established with V2 channel
4545+ /// establishment (i.e. is a dual-funded channel).
4546+ is_v2_established: bool,
45434547}
45444548
45454549#[cfg(any(test, fuzzing))]
@@ -5994,10 +5998,10 @@ impl<SP: Deref> FundedChannel<SP> where
59945998 }
59955999 }
59966000
5997- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<( Option<msgs::TxSignatures>, Option<Transaction>) , ChannelError>
6001+ pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
59986002 where L::Target: Logger
59996003 {
6000- if !matches!(self.context.channel_state, ChannelState::FundingNegotiated ) {
6004+ if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_) ) {
60016005 return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
60026006 }
60036007
@@ -6031,25 +6035,23 @@ impl<SP: Deref> FundedChannel<SP> where
60316035 // for spending. Doesn't seem to be anything in rust-bitcoin.
60326036 }
60336037
6034- let (tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
6038+ let (holder_tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
60356039 .map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
6040+ if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
6041+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6042+ self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
6043+ return Ok(None);
6044+ }
60366045 if funding_tx_opt.is_some() {
6046+ // We have a persisted channel monitor and and a finalized funding transaction, so we can move
6047+ // the channel state forward, set the funding transaction and reset the signing session fields.
6048+ self.context.funding_transaction = funding_tx_opt;
6049+ self.context.next_funding_txid = None;
6050+ self.interactive_tx_signing_session = None;
60376051 self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
60386052 }
6039- self.context.funding_transaction = funding_tx_opt.clone();
6040-
6041- self.context.next_funding_txid = None;
6042-
6043- // Clear out the signing session
6044- self.interactive_tx_signing_session = None;
6045-
6046- if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
6047- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6048- self.context.monitor_pending_tx_signatures = tx_signatures_opt;
6049- return Ok((None, None));
6050- }
60516053
6052- Ok((tx_signatures_opt, funding_tx_opt) )
6054+ Ok(holder_tx_signatures_opt )
60536055 } else {
60546056 Err(ChannelError::Close((
60556057 "Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
@@ -6252,12 +6254,12 @@ impl<SP: Deref> FundedChannel<SP> where
62526254 assert!(self.context.channel_state.is_monitor_update_in_progress());
62536255 self.context.channel_state.clear_monitor_update_in_progress();
62546256
6255- // If we're past (or at) the AwaitingChannelReady stage on an outbound channel, try to
6256- // (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6257+ // If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
6258+ // try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
62576259 // first received the funding_signed.
62586260 let mut funding_broadcastable = None;
62596261 if let Some(funding_transaction) = &self.context.funding_transaction {
6260- if self.context.is_outbound() &&
6262+ if ( self.context.is_outbound() || self.is_v2_established() ) &&
62616263 (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
62626264 matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
62636265 {
@@ -8549,6 +8551,10 @@ impl<SP: Deref> FundedChannel<SP> where
85498551 })
85508552 .chain(self.context.pending_outbound_htlcs.iter().map(|htlc| (&htlc.source, &htlc.payment_hash)))
85518553 }
8554+
8555+ pub fn is_v2_established(&self) -> bool {
8556+ self.is_v2_established
8557+ }
85528558}
85538559
85548560/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -8812,6 +8818,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
88128818 let mut channel = FundedChannel {
88138819 context: self.context,
88148820 interactive_tx_signing_session: None,
8821+ is_v2_established: false,
88158822 holder_commitment_point,
88168823 };
88178824
@@ -9077,6 +9084,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
90779084 let mut channel = FundedChannel {
90789085 context: self.context,
90799086 interactive_tx_signing_session: None,
9087+ is_v2_established: false,
90809088 holder_commitment_point,
90819089 };
90829090 let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -9885,7 +9893,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98859893 let mut _val: u64 = Readable::read(reader)?;
98869894 }
98879895
9888- let channel_id = Readable::read(reader)?;
9896+ let channel_id: ChannelId = Readable::read(reader)?;
98899897 let channel_state = ChannelState::from_u32(Readable::read(reader)?).map_err(|_| DecodeError::InvalidValue)?;
98909898 let channel_value_satoshis = Readable::read(reader)?;
98919899
@@ -10321,6 +10329,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1032110329 }
1032210330 },
1032310331 };
10332+ let is_v2_established = channel_id.is_v2_channel_id(
10333+ &channel_parameters.holder_pubkeys.revocation_basepoint,
10334+ &channel_parameters.counterparty_parameters.as_ref()
10335+ .expect("Persisted channel must have counterparty parameters").pubkeys.revocation_basepoint);
1032410336
1032510337 Ok(FundedChannel {
1032610338 context: ChannelContext {
@@ -10458,6 +10470,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1045810470 next_funding_txid: None,
1045910471 },
1046010472 interactive_tx_signing_session: None,
10473+ is_v2_established,
1046110474 holder_commitment_point,
1046210475 })
1046310476 }
0 commit comments