@@ -2188,6 +2188,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
21882188 context: self.context,
21892189 interactive_tx_signing_session: Some(signing_session),
21902190 holder_commitment_point,
2191+ is_v2_established: true,
21912192 };
21922193 Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
21932194 },
@@ -4542,6 +4543,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
45424543 pub context: ChannelContext<SP>,
45434544 pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
45444545 holder_commitment_point: HolderCommitmentPoint,
4546+ /// Indicates whether this funded channel had been established with V2 channel
4547+ /// establishment (i.e. is a dual-funded channel).
4548+ is_v2_established: bool,
45454549}
45464550
45474551#[cfg(any(test, fuzzing))]
@@ -5996,10 +6000,10 @@ impl<SP: Deref> FundedChannel<SP> where
59966000 }
59976001 }
59986002
5999- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<( Option<msgs::TxSignatures>, Option<Transaction>) , ChannelError>
6003+ pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
60006004 where L::Target: Logger
60016005 {
6002- if !matches!(self.context.channel_state, ChannelState::FundingNegotiated ) {
6006+ if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_) ) {
60036007 return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
60046008 }
60056009
@@ -6033,25 +6037,23 @@ impl<SP: Deref> FundedChannel<SP> where
60336037 // for spending. Doesn't seem to be anything in rust-bitcoin.
60346038 }
60356039
6036- let (tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
6040+ let (holder_tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
60376041 .map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
6042+ if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
6043+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6044+ self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
6045+ return Ok(None);
6046+ }
60386047 if funding_tx_opt.is_some() {
6048+ // We have a persisted channel monitor and and a finalized funding transaction, so we can move
6049+ // the channel state forward, set the funding transaction and reset the signing session fields.
6050+ self.context.funding_transaction = funding_tx_opt;
6051+ self.context.next_funding_txid = None;
6052+ self.interactive_tx_signing_session = None;
60396053 self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
60406054 }
6041- self.context.funding_transaction = funding_tx_opt.clone();
6042-
6043- self.context.next_funding_txid = None;
6044-
6045- // Clear out the signing session
6046- self.interactive_tx_signing_session = None;
6047-
6048- if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
6049- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6050- self.context.monitor_pending_tx_signatures = tx_signatures_opt;
6051- return Ok((None, None));
6052- }
60536055
6054- Ok((tx_signatures_opt, funding_tx_opt) )
6056+ Ok(holder_tx_signatures_opt )
60556057 } else {
60566058 Err(ChannelError::Close((
60576059 "Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
@@ -6254,12 +6256,12 @@ impl<SP: Deref> FundedChannel<SP> where
62546256 assert!(self.context.channel_state.is_monitor_update_in_progress());
62556257 self.context.channel_state.clear_monitor_update_in_progress();
62566258
6257- // If we're past (or at) the AwaitingChannelReady stage on an outbound channel, try to
6258- // (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6259+ // If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
6260+ // try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
62596261 // first received the funding_signed.
62606262 let mut funding_broadcastable = None;
62616263 if let Some(funding_transaction) = &self.context.funding_transaction {
6262- if self.context.is_outbound() &&
6264+ if ( self.context.is_outbound() || self.is_v2_established() ) &&
62636265 (matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
62646266 matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
62656267 {
@@ -8551,6 +8553,10 @@ impl<SP: Deref> FundedChannel<SP> where
85518553 })
85528554 .chain(self.context.pending_outbound_htlcs.iter().map(|htlc| (&htlc.source, &htlc.payment_hash)))
85538555 }
8556+
8557+ pub fn is_v2_established(&self) -> bool {
8558+ self.is_v2_established
8559+ }
85548560}
85558561
85568562/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -8814,6 +8820,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
88148820 let mut channel = FundedChannel {
88158821 context: self.context,
88168822 interactive_tx_signing_session: None,
8823+ is_v2_established: false,
88178824 holder_commitment_point,
88188825 };
88198826
@@ -9079,6 +9086,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
90799086 let mut channel = FundedChannel {
90809087 context: self.context,
90819088 interactive_tx_signing_session: None,
9089+ is_v2_established: false,
90829090 holder_commitment_point,
90839091 };
90849092 let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -9887,7 +9895,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
98879895 let mut _val: u64 = Readable::read(reader)?;
98889896 }
98899897
9890- let channel_id = Readable::read(reader)?;
9898+ let channel_id: ChannelId = Readable::read(reader)?;
98919899 let channel_state = ChannelState::from_u32(Readable::read(reader)?).map_err(|_| DecodeError::InvalidValue)?;
98929900 let channel_value_satoshis = Readable::read(reader)?;
98939901
@@ -10323,6 +10331,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1032310331 }
1032410332 },
1032510333 };
10334+ let is_v2_established = channel_id.is_v2_channel_id(
10335+ &channel_parameters.holder_pubkeys.revocation_basepoint,
10336+ &channel_parameters.counterparty_parameters.as_ref()
10337+ .expect("Persisted channel must have counterparty parameters").pubkeys.revocation_basepoint);
1032610338
1032710339 Ok(FundedChannel {
1032810340 context: ChannelContext {
@@ -10460,6 +10472,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
1046010472 next_funding_txid: None,
1046110473 },
1046210474 interactive_tx_signing_session: None,
10475+ is_v2_established,
1046310476 holder_commitment_point,
1046410477 })
1046510478 }
0 commit comments