@@ -5315,12 +5315,7 @@ impl<SP: Deref> Channel<SP> where
5315
5315
assert!(!self.context.is_outbound() || self.context.minimum_depth == Some(0),
5316
5316
"Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
5317
5317
self.context.monitor_pending_channel_ready = false;
5318
- let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
5319
- Some(msgs::ChannelReady {
5320
- channel_id: self.context.channel_id(),
5321
- next_per_commitment_point,
5322
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5323
- })
5318
+ Some(self.get_channel_ready())
5324
5319
} else { None };
5325
5320
5326
5321
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5406,7 +5401,7 @@ impl<SP: Deref> Channel<SP> where
5406
5401
self.context.get_funding_signed_msg(logger).1
5407
5402
} else { None };
5408
5403
let channel_ready = if funding_signed.is_some() {
5409
- self.check_get_channel_ready(0)
5404
+ self.check_get_channel_ready(0, logger )
5410
5405
} else { None };
5411
5406
5412
5407
log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed and {} channel_ready",
@@ -5618,13 +5613,8 @@ impl<SP: Deref> Channel<SP> where
5618
5613
}
5619
5614
5620
5615
// We have OurChannelReady set!
5621
- let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
5622
5616
return Ok(ReestablishResponses {
5623
- channel_ready: Some(msgs::ChannelReady {
5624
- channel_id: self.context.channel_id(),
5625
- next_per_commitment_point,
5626
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5627
- }),
5617
+ channel_ready: Some(self.get_channel_ready()),
5628
5618
raa: None, commitment_update: None,
5629
5619
order: RAACommitmentOrder::CommitmentFirst,
5630
5620
shutdown_msg, announcement_sigs,
@@ -5663,12 +5653,7 @@ impl<SP: Deref> Channel<SP> where
5663
5653
5664
5654
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.context.holder_commitment_point.transaction_number() == 1 {
5665
5655
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
5666
- let next_per_commitment_point = self.context.holder_signer.as_ref().get_per_commitment_point(self.context.holder_commitment_point.transaction_number(), &self.context.secp_ctx);
5667
- Some(msgs::ChannelReady {
5668
- channel_id: self.context.channel_id(),
5669
- next_per_commitment_point,
5670
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5671
- })
5656
+ Some(self.get_channel_ready())
5672
5657
} else { None };
5673
5658
5674
5659
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6488,7 +6473,9 @@ impl<SP: Deref> Channel<SP> where
6488
6473
self.context.channel_update_status = status;
6489
6474
}
6490
6475
6491
- fn check_get_channel_ready(&mut self, height: u32) -> Option<msgs::ChannelReady> {
6476
+ fn check_get_channel_ready<L: Deref>(&mut self, height: u32, logger: &L) -> Option<msgs::ChannelReady>
6477
+ where L::Target: Logger
6478
+ {
6492
6479
// Called:
6493
6480
// * always when a new block/transactions are confirmed with the new height
6494
6481
// * when funding is signed with a height of 0
@@ -6508,6 +6495,8 @@ impl<SP: Deref> Channel<SP> where
6508
6495
// If we're still pending the signature on a funding transaction, then we're not ready to send a
6509
6496
// channel_ready yet.
6510
6497
if self.context.signer_pending_funding {
6498
+ // TODO: set signer_pending_channel_ready
6499
+ log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
6511
6500
return None;
6512
6501
}
6513
6502
@@ -6540,22 +6529,35 @@ impl<SP: Deref> Channel<SP> where
6540
6529
false
6541
6530
};
6542
6531
6543
- if need_commitment_update {
6544
- if !self.context.channel_state.is_monitor_update_in_progress() {
6545
- if !self.context.channel_state.is_peer_disconnected() {
6546
- let next_per_commitment_point =
6547
- self.context.holder_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &self.context.secp_ctx);
6548
- return Some(msgs::ChannelReady {
6549
- channel_id: self.context.channel_id,
6550
- next_per_commitment_point,
6551
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
6552
- });
6553
- }
6554
- } else {
6555
- self.context.monitor_pending_channel_ready = true;
6556
- }
6532
+ if !need_commitment_update {
6533
+ log_debug!(logger, "Not producing channel_ready: we do not need a commitment update");
6534
+ return None;
6535
+ }
6536
+
6537
+ if self.context.channel_state.is_monitor_update_in_progress() {
6538
+ log_debug!(logger, "Not producing channel_ready: a monitor update is in progress. Setting monitor_pending_channel_ready.");
6539
+ self.context.monitor_pending_channel_ready = true;
6540
+ return None;
6541
+ }
6542
+
6543
+ if self.context.channel_state.is_peer_disconnected() {
6544
+ log_debug!(logger, "Not producing channel_ready: the peer is disconnected.");
6545
+ return None;
6546
+ }
6547
+
6548
+ // TODO: when get_per_commiment_point becomes async, check if the point is
6549
+ // available, if not, set signer_pending_channel_ready and return None
6550
+
6551
+ Some(self.get_channel_ready())
6552
+ }
6553
+
6554
+ fn get_channel_ready(&self) -> msgs::ChannelReady {
6555
+ debug_assert!(self.context.holder_commitment_point.is_available());
6556
+ msgs::ChannelReady {
6557
+ channel_id: self.context.channel_id(),
6558
+ next_per_commitment_point: self.context.holder_commitment_point.current_point(),
6559
+ short_channel_id_alias: Some(self.context.outbound_scid_alias),
6557
6560
}
6558
- None
6559
6561
}
6560
6562
6561
6563
/// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -6622,7 +6624,7 @@ impl<SP: Deref> Channel<SP> where
6622
6624
// If we allow 1-conf funding, we may need to check for channel_ready here and
6623
6625
// send it immediately instead of waiting for a best_block_updated call (which
6624
6626
// may have already happened for this block).
6625
- if let Some(channel_ready) = self.check_get_channel_ready(height) {
6627
+ if let Some(channel_ready) = self.check_get_channel_ready(height, logger ) {
6626
6628
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
6627
6629
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
6628
6630
msgs = (Some(channel_ready), announcement_sigs);
@@ -6688,7 +6690,7 @@ impl<SP: Deref> Channel<SP> where
6688
6690
6689
6691
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
6690
6692
6691
- if let Some(channel_ready) = self.check_get_channel_ready(height) {
6693
+ if let Some(channel_ready) = self.check_get_channel_ready(height, logger ) {
6692
6694
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
6693
6695
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
6694
6696
} else { None };
@@ -7873,7 +7875,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7873
7875
dual_funding_channel_context: None,
7874
7876
};
7875
7877
7876
- let need_channel_ready = channel.check_get_channel_ready(0).is_some();
7878
+ let need_channel_ready = channel.check_get_channel_ready(0, logger ).is_some();
7877
7879
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
7878
7880
Ok((channel, channel_monitor))
7879
7881
}
@@ -8162,7 +8164,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8162
8164
#[cfg(any(dual_funding, splicing))]
8163
8165
dual_funding_channel_context: None,
8164
8166
};
8165
- let need_channel_ready = channel.check_get_channel_ready(0).is_some();
8167
+ let need_channel_ready = channel.check_get_channel_ready(0, logger ).is_some();
8166
8168
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
8167
8169
8168
8170
Ok((channel, funding_signed, channel_monitor))
@@ -11269,6 +11271,6 @@ mod tests {
11269
11271
// Clear the ChannelState::WaitingForBatch only when called by ChannelManager.
11270
11272
node_a_chan.set_batch_ready();
11271
11273
assert_eq!(node_a_chan.context.channel_state, ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY));
11272
- assert!(node_a_chan.check_get_channel_ready(0).is_some());
11274
+ assert!(node_a_chan.check_get_channel_ready(0, &&logger ).is_some());
11273
11275
}
11274
11276
}
0 commit comments