@@ -2276,6 +2276,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2276
2276
context: self.context,
2277
2277
interactive_tx_signing_session: Some(signing_session),
2278
2278
holder_commitment_point,
2279
+ is_v2_established: true,
2279
2280
};
2280
2281
Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2281
2282
},
@@ -4652,6 +4653,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4652
4653
pub context: ChannelContext<SP>,
4653
4654
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
4654
4655
holder_commitment_point: HolderCommitmentPoint,
4656
+ /// Indicates whether this funded channel had been established with V2 channel
4657
+ /// establishment (i.e. is a dual-funded channel).
4658
+ is_v2_established: bool,
4655
4659
}
4656
4660
4657
4661
#[cfg(any(test, fuzzing))]
@@ -6132,10 +6136,10 @@ impl<SP: Deref> FundedChannel<SP> where
6132
6136
}
6133
6137
}
6134
6138
6135
- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<( Option<msgs::TxSignatures>, Option<Transaction>) , ChannelError>
6139
+ pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
6136
6140
where L::Target: Logger
6137
6141
{
6138
- if !matches!(self.context.channel_state, ChannelState::FundingNegotiated ) {
6142
+ if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_) ) {
6139
6143
return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
6140
6144
}
6141
6145
@@ -6169,25 +6173,22 @@ impl<SP: Deref> FundedChannel<SP> where
6169
6173
// for spending. Doesn't seem to be anything in rust-bitcoin.
6170
6174
}
6171
6175
6172
- let (tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
6176
+ let (holder_tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
6173
6177
.map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
6174
- if funding_tx_opt.is_some() {
6175
- self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
6176
- }
6177
- self.context.funding_transaction = funding_tx_opt.clone();
6178
-
6179
- self.context.next_funding_txid = None;
6180
-
6181
- // Clear out the signing session
6182
- self.interactive_tx_signing_session = None;
6183
-
6184
- if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
6178
+ if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
6185
6179
log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6186
- self.context.monitor_pending_tx_signatures = tx_signatures_opt;
6187
- return Ok((None, None));
6180
+ self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
6181
+ return Ok(None);
6182
+ }
6183
+ if funding_tx_opt.is_some() {
6184
+ // We have a finalized funding transaction, so we can set the funding transaction and reset the
6185
+ // signing session fields.
6186
+ self.context.funding_transaction = funding_tx_opt;
6187
+ self.context.next_funding_txid = None;
6188
+ self.interactive_tx_signing_session = None;
6188
6189
}
6189
6190
6190
- Ok((tx_signatures_opt, funding_tx_opt) )
6191
+ Ok(holder_tx_signatures_opt )
6191
6192
} else {
6192
6193
Err(ChannelError::Close((
6193
6194
"Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
@@ -6404,12 +6405,12 @@ impl<SP: Deref> FundedChannel<SP> where
6404
6405
assert!(self.context.channel_state.is_monitor_update_in_progress());
6405
6406
self.context.channel_state.clear_monitor_update_in_progress();
6406
6407
6407
- // If we're past (or at) the AwaitingChannelReady stage on an outbound channel, try to
6408
- // (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6408
+ // If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
6409
+ // try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6409
6410
// first received the funding_signed.
6410
6411
let mut funding_broadcastable = None;
6411
6412
if let Some(funding_transaction) = &self.context.funding_transaction {
6412
- if self.context.is_outbound() &&
6413
+ if ( self.context.is_outbound() || self.is_v2_established() ) &&
6413
6414
(matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
6414
6415
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
6415
6416
{
@@ -8937,6 +8938,10 @@ impl<SP: Deref> FundedChannel<SP> where
8937
8938
false
8938
8939
}
8939
8940
}
8941
+
8942
+ pub fn is_v2_established(&self) -> bool {
8943
+ self.is_v2_established
8944
+ }
8940
8945
}
8941
8946
8942
8947
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -9204,6 +9209,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
9204
9209
funding: self.funding,
9205
9210
context: self.context,
9206
9211
interactive_tx_signing_session: None,
9212
+ is_v2_established: false,
9207
9213
holder_commitment_point,
9208
9214
};
9209
9215
@@ -9471,6 +9477,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9471
9477
funding: self.funding,
9472
9478
context: self.context,
9473
9479
interactive_tx_signing_session: None,
9480
+ is_v2_established: false,
9474
9481
holder_commitment_point,
9475
9482
};
9476
9483
let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -10282,7 +10289,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10282
10289
let mut _val: u64 = Readable::read(reader)?;
10283
10290
}
10284
10291
10285
- let channel_id = Readable::read(reader)?;
10292
+ let channel_id: ChannelId = Readable::read(reader)?;
10286
10293
let channel_state = ChannelState::from_u32(Readable::read(reader)?).map_err(|_| DecodeError::InvalidValue)?;
10287
10294
let channel_value_satoshis = Readable::read(reader)?;
10288
10295
@@ -10718,6 +10725,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10718
10725
}
10719
10726
},
10720
10727
};
10728
+ let is_v2_established = channel_id.is_v2_channel_id(
10729
+ &channel_parameters.holder_pubkeys.revocation_basepoint,
10730
+ &channel_parameters.counterparty_parameters.as_ref()
10731
+ .expect("Persisted channel must have counterparty parameters").pubkeys.revocation_basepoint);
10721
10732
10722
10733
Ok(FundedChannel {
10723
10734
funding: FundingScope {
@@ -10860,6 +10871,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10860
10871
is_holder_quiescence_initiator: None,
10861
10872
},
10862
10873
interactive_tx_signing_session: None,
10874
+ is_v2_established,
10863
10875
holder_commitment_point,
10864
10876
})
10865
10877
}
0 commit comments