@@ -2159,6 +2159,7 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
2159
2159
context: self.context,
2160
2160
interactive_tx_signing_session: Some(signing_session),
2161
2161
holder_commitment_point,
2162
+ is_v2_established: true,
2162
2163
};
2163
2164
Ok((funded_chan, commitment_signed, funding_ready_for_sig_event))
2164
2165
},
@@ -4500,6 +4501,9 @@ pub(super) struct FundedChannel<SP: Deref> where SP::Target: SignerProvider {
4500
4501
pub context: ChannelContext<SP>,
4501
4502
pub interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
4502
4503
holder_commitment_point: HolderCommitmentPoint,
4504
+ /// Indicates whether this funded channel had been established with V2 channel
4505
+ /// establishment (i.e. is a dual-funded channel).
4506
+ is_v2_established: bool,
4503
4507
}
4504
4508
4505
4509
#[cfg(any(test, fuzzing))]
@@ -5954,10 +5958,10 @@ impl<SP: Deref> FundedChannel<SP> where
5954
5958
}
5955
5959
}
5956
5960
5957
- pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<( Option<msgs::TxSignatures>, Option<Transaction>) , ChannelError>
5961
+ pub fn tx_signatures<L: Deref>(&mut self, msg: &msgs::TxSignatures, logger: &L) -> Result<Option<msgs::TxSignatures>, ChannelError>
5958
5962
where L::Target: Logger
5959
5963
{
5960
- if !matches!(self.context.channel_state, ChannelState::FundingNegotiated ) {
5964
+ if !matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(_) ) {
5961
5965
return Err(ChannelError::close("Received tx_signatures in strange state!".to_owned()));
5962
5966
}
5963
5967
@@ -5991,25 +5995,23 @@ impl<SP: Deref> FundedChannel<SP> where
5991
5995
// for spending. Doesn't seem to be anything in rust-bitcoin.
5992
5996
}
5993
5997
5994
- let (tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
5998
+ let (holder_tx_signatures_opt , funding_tx_opt) = signing_session.received_tx_signatures(msg.clone())
5995
5999
.map_err(|_| ChannelError::Warn("Witness count did not match contributed input count".to_string()))?;
6000
+ if holder_tx_signatures_opt.is_some() && self.is_awaiting_initial_mon_persist() {
6001
+ log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6002
+ self.context.monitor_pending_tx_signatures = holder_tx_signatures_opt;
6003
+ return Ok(None);
6004
+ }
5996
6005
if funding_tx_opt.is_some() {
6006
+ // We have a persisted channel monitor and and a finalized funding transaction, so we can move
6007
+ // the channel state forward, set the funding transaction and reset the signing session fields.
6008
+ self.context.funding_transaction = funding_tx_opt;
6009
+ self.context.next_funding_txid = None;
6010
+ self.interactive_tx_signing_session = None;
5997
6011
self.context.channel_state = ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::new());
5998
6012
}
5999
- self.context.funding_transaction = funding_tx_opt.clone();
6000
-
6001
- self.context.next_funding_txid = None;
6002
-
6003
- // Clear out the signing session
6004
- self.interactive_tx_signing_session = None;
6005
-
6006
- if tx_signatures_opt.is_some() && self.context.channel_state.is_monitor_update_in_progress() {
6007
- log_debug!(logger, "Not sending tx_signatures: a monitor update is in progress. Setting monitor_pending_tx_signatures.");
6008
- self.context.monitor_pending_tx_signatures = tx_signatures_opt;
6009
- return Ok((None, None));
6010
- }
6011
6013
6012
- Ok((tx_signatures_opt, funding_tx_opt) )
6014
+ Ok(holder_tx_signatures_opt )
6013
6015
} else {
6014
6016
Err(ChannelError::Close((
6015
6017
"Unexpected tx_signatures. No funding transaction awaiting signatures".to_string(),
@@ -6212,12 +6214,12 @@ impl<SP: Deref> FundedChannel<SP> where
6212
6214
assert!(self.context.channel_state.is_monitor_update_in_progress());
6213
6215
self.context.channel_state.clear_monitor_update_in_progress();
6214
6216
6215
- // If we're past (or at) the AwaitingChannelReady stage on an outbound channel, try to
6216
- // (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6217
+ // If we're past (or at) the AwaitingChannelReady stage on an outbound (or V2-established) channel,
6218
+ // try to (re-)broadcast the funding transaction as we may have declined to broadcast it when we
6217
6219
// first received the funding_signed.
6218
6220
let mut funding_broadcastable = None;
6219
6221
if let Some(funding_transaction) = &self.context.funding_transaction {
6220
- if self.context.is_outbound() &&
6222
+ if ( self.context.is_outbound() || self.is_v2_established() ) &&
6221
6223
(matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if !flags.is_set(AwaitingChannelReadyFlags::WAITING_FOR_BATCH)) ||
6222
6224
matches!(self.context.channel_state, ChannelState::ChannelReady(_)))
6223
6225
{
@@ -8509,6 +8511,10 @@ impl<SP: Deref> FundedChannel<SP> where
8509
8511
})
8510
8512
.chain(self.context.pending_outbound_htlcs.iter().map(|htlc| (&htlc.source, &htlc.payment_hash)))
8511
8513
}
8514
+
8515
+ pub fn is_v2_established(&self) -> bool {
8516
+ self.is_v2_established
8517
+ }
8512
8518
}
8513
8519
8514
8520
/// A not-yet-funded outbound (from holder) channel using V1 channel establishment.
@@ -8772,6 +8778,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
8772
8778
let mut channel = FundedChannel {
8773
8779
context: self.context,
8774
8780
interactive_tx_signing_session: None,
8781
+ is_v2_established: false,
8775
8782
holder_commitment_point,
8776
8783
};
8777
8784
@@ -9037,6 +9044,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
9037
9044
let mut channel = FundedChannel {
9038
9045
context: self.context,
9039
9046
interactive_tx_signing_session: None,
9047
+ is_v2_established: false,
9040
9048
holder_commitment_point,
9041
9049
};
9042
9050
let need_channel_ready = channel.check_get_channel_ready(0, logger).is_some()
@@ -9839,7 +9847,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
9839
9847
let mut _val: u64 = Readable::read(reader)?;
9840
9848
}
9841
9849
9842
- let channel_id = Readable::read(reader)?;
9850
+ let channel_id: ChannelId = Readable::read(reader)?;
9843
9851
let channel_state = ChannelState::from_u32(Readable::read(reader)?).map_err(|_| DecodeError::InvalidValue)?;
9844
9852
let channel_value_satoshis = Readable::read(reader)?;
9845
9853
@@ -10275,6 +10283,10 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10275
10283
}
10276
10284
},
10277
10285
};
10286
+ let is_v2_established = channel_id.is_v2_channel_id(
10287
+ &channel_parameters.holder_pubkeys.revocation_basepoint,
10288
+ &channel_parameters.counterparty_parameters.as_ref()
10289
+ .expect("Persisted channel must have counterparty parameters").pubkeys.revocation_basepoint);
10278
10290
10279
10291
Ok(FundedChannel {
10280
10292
context: ChannelContext {
@@ -10412,6 +10424,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
10412
10424
next_funding_txid: None,
10413
10425
},
10414
10426
interactive_tx_signing_session: None,
10427
+ is_v2_established,
10415
10428
holder_commitment_point,
10416
10429
})
10417
10430
}
0 commit comments