@@ -2280,6 +2280,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2280
2280
context: self.context,
2281
2281
interactive_tx_signing_session: Some(signing_session),
2282
2282
holder_commitment_point,
2283
+ is_v2_established: true,
2283
2284
};
2284
2285
Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2285
2286
},
@@ -4645,6 +4646,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4645
4646
pub context: ChannelContext<SP>,
4646
4647
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
4647
4648
holder_commitment_point: HolderCommitmentPoint,
4649
+ /// Indicates whether this funded channel had been established with V2 channel
4650
+ /// establishment (i.e. is a dual-funded channel).
4651
+ is_v2_established: bool,
4648
4652
}
4649
4653
4650
4654
#[cfg(any(test, fuzzing))]
@@ -6125,10 +6129,10 @@ impl<SP: Deref> FundedChannel<SP> where
6125
6129
}
6126
6130
}
6127
6131
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>
6129
6133
where L::Target: Logger
6130
6134
{
6131
- if !matches!(self.context.channel_state, ChannelState::FundingNegotiated ) {
6135
+ if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_) ) {
6132
6136
return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
6133
6137
}
6134
6138
@@ -6162,25 +6166,25 @@ impl<SP: Deref> FundedChannel<SP> where
6162
6166
// for spending. Doesn't seem to be anything in rust-bitcoin.
6163
6167
}
6164
6168
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())
6166
6170
.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();
6171
6171
6172
- self.context.next_funding_txid = None;
6173
6172
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
+ }
6176
6180
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 () {
6178
6182
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);
6181
6185
}
6182
6186
6183
- Ok((tx_signatures_opt, funding_tx_opt) )
6187
+ Ok(holder_tx_signatures_opt )
6184
6188
} else {
6185
6189
Err(ChannelError::Close((
6186
6190
"Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
@@ -6397,12 +6401,12 @@ impl<SP: Deref> FundedChannel<SP> where
6397
6401
assert!(self.context.channel_state.is_monitor_update_in_progress());
6398
6402
self.context.channel_state.clear_monitor_update_in_progress();
6399
6403
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
6402
6406
// first received the funding_signed.
6403
6407
let mut funding_broadcastable = None;
6404
6408
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() ) &&
6406
6410
(matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
6407
6411
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
6408
6412
{
@@ -8918,6 +8922,10 @@ impl<SP: Deref> FundedChannel<SP> where
8918
8922
false
8919
8923
}
8920
8924
}
8925
+
8926
+ pub fn is_v2_established(&self) -> bool {
8927
+ self.is_v2_established
8928
+ }
8921
8929
}
8922
8930
8923
8931
/// 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 {
9185
9193
funding: self.funding,
9186
9194
context: self.context,
9187
9195
interactive_tx_signing_session: None,
9196
+ is_v2_established: false,
9188
9197
holder_commitment_point,
9189
9198
};
9190
9199
@@ -9452,6 +9461,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9452
9461
funding: self.funding,
9453
9462
context: self.context,
9454
9463
interactive_tx_signing_session: None,
9464
+ is_v2_established: false,
9455
9465
holder_commitment_point,
9456
9466
};
9457
9467
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
10263
10273
let mut _val: u64 = Readable::read(reader)?;
10264
10274
}
10265
10275
10266
- let channel_id = Readable::read(reader)?;
10276
+ let channel_id: ChannelId = Readable::read(reader)?;
10267
10277
let channel_state = ChannelState::from_u32(Readable::read(reader)?).map_err(|_| DecodeError::InvalidValue)?;
10268
10278
let channel_value_satoshis = Readable::read(reader)?;
10269
10279
@@ -10699,6 +10709,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10699
10709
}
10700
10710
},
10701
10711
};
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);
10702
10716
10703
10717
Ok(FundedChannel {
10704
10718
funding: FundingScope {
@@ -10841,6 +10855,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10841
10855
is_holder_quiescence_initiator: None,
10842
10856
},
10843
10857
interactive_tx_signing_session: None,
10858
+ is_v2_established,
10844
10859
holder_commitment_point,
10845
10860
})
10846
10861
}
0 commit comments