@@ -5316,12 +5316,7 @@ impl<SP: Deref> Channel<SP> where
5316
5316
assert!(!self.context.is_outbound() || self.context.minimum_depth == Some(0),
5317
5317
"Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
5318
5318
self.context.monitor_pending_channel_ready = false;
5319
- 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);
5320
- Some(msgs::ChannelReady {
5321
- channel_id: self.context.channel_id(),
5322
- next_per_commitment_point,
5323
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5324
- })
5319
+ Some(self.get_channel_ready())
5325
5320
} else { None };
5326
5321
5327
5322
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5407,7 +5402,7 @@ impl<SP: Deref> Channel<SP> where
5407
5402
self.context.get_funding_signed_msg(logger).1
5408
5403
} else { None };
5409
5404
let channel_ready = if funding_signed.is_some() {
5410
- self.check_get_channel_ready(0)
5405
+ self.check_get_channel_ready(0, logger )
5411
5406
} else { None };
5412
5407
5413
5408
log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed and {} channel_ready",
@@ -5619,13 +5614,8 @@ impl<SP: Deref> Channel<SP> where
5619
5614
}
5620
5615
5621
5616
// We have OurChannelReady set!
5622
- 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);
5623
5617
return Ok(ReestablishResponses {
5624
- channel_ready: Some(msgs::ChannelReady {
5625
- channel_id: self.context.channel_id(),
5626
- next_per_commitment_point,
5627
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5628
- }),
5618
+ channel_ready: Some(self.get_channel_ready()),
5629
5619
raa: None, commitment_update: None,
5630
5620
order: RAACommitmentOrder::CommitmentFirst,
5631
5621
shutdown_msg, announcement_sigs,
@@ -5664,12 +5654,7 @@ impl<SP: Deref> Channel<SP> where
5664
5654
5665
5655
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.context.holder_commitment_point.transaction_number() == 1 {
5666
5656
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
5667
- 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);
5668
- Some(msgs::ChannelReady {
5669
- channel_id: self.context.channel_id(),
5670
- next_per_commitment_point,
5671
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5672
- })
5657
+ Some(self.get_channel_ready())
5673
5658
} else { None };
5674
5659
5675
5660
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6489,7 +6474,9 @@ impl<SP: Deref> Channel<SP> where
6489
6474
self.context.channel_update_status = status;
6490
6475
}
6491
6476
6492
- fn check_get_channel_ready(&mut self, height: u32) -> Option<msgs::ChannelReady> {
6477
+ fn check_get_channel_ready<L: Deref>(&mut self, height: u32, logger: &L) -> Option<msgs::ChannelReady>
6478
+ where L::Target: Logger
6479
+ {
6493
6480
// Called:
6494
6481
// * always when a new block/transactions are confirmed with the new height
6495
6482
// * when funding is signed with a height of 0
@@ -6541,22 +6528,42 @@ impl<SP: Deref> Channel<SP> where
6541
6528
false
6542
6529
};
6543
6530
6544
- if need_commitment_update {
6545
- if !self.context.channel_state.is_monitor_update_in_progress() {
6546
- if !self.context.channel_state.is_peer_disconnected() {
6547
- let next_per_commitment_point =
6548
- self.context.holder_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &self.context.secp_ctx);
6549
- return Some(msgs::ChannelReady {
6550
- channel_id: self.context.channel_id,
6551
- next_per_commitment_point,
6552
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
6553
- });
6554
- }
6555
- } else {
6556
- self.context.monitor_pending_channel_ready = true;
6557
- }
6531
+ if !need_commitment_update {
6532
+ log_debug!(logger, "Not producing channel_ready: we do not need a commitment update");
6533
+ return None;
6534
+ }
6535
+
6536
+ if self.context.channel_state.is_monitor_update_in_progress() {
6537
+ log_debug!(logger, "Not producing channel_ready: a monitor update is in progress. Setting monitor_pending_channel_ready.");
6538
+ self.context.monitor_pending_channel_ready = true;
6539
+ return None;
6540
+ }
6541
+
6542
+ if self.context.channel_state.is_peer_disconnected() {
6543
+ log_debug!(logger, "Not producing channel_ready: the peer is disconnected.");
6544
+ return None;
6545
+ }
6546
+
6547
+ if self.context.signer_pending_funding {
6548
+ // TODO: set signer_pending_channel_ready
6549
+ log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
6550
+ return None;
6551
+ }
6552
+
6553
+ // TODO: when get_per_commiment_point becomes async, check if the point is
6554
+ // available, if not, set signer_pending_channel_ready and return None
6555
+
6556
+ Some(self.get_channel_ready())
6557
+ }
6558
+
6559
+ fn get_channel_ready(&self) -> msgs::ChannelReady {
6560
+ debug_assert!(self.context.holder_commitment_point.is_available());
6561
+ msgs::ChannelReady {
6562
+ channel_id: self.context.channel_id(),
6563
+ next_per_commitment_point: self.context.holder_commitment_point.current_point()
6564
+ .expect("TODO"),
6565
+ short_channel_id_alias: Some(self.context.outbound_scid_alias),
6558
6566
}
6559
- None
6560
6567
}
6561
6568
6562
6569
/// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -6623,7 +6630,7 @@ impl<SP: Deref> Channel<SP> where
6623
6630
// If we allow 1-conf funding, we may need to check for channel_ready here and
6624
6631
// send it immediately instead of waiting for a best_block_updated call (which
6625
6632
// may have already happened for this block).
6626
- if let Some(channel_ready) = self.check_get_channel_ready(height) {
6633
+ if let Some(channel_ready) = self.check_get_channel_ready(height, logger ) {
6627
6634
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
6628
6635
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
6629
6636
msgs = (Some(channel_ready), announcement_sigs);
@@ -6689,7 +6696,7 @@ impl<SP: Deref> Channel<SP> where
6689
6696
6690
6697
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
6691
6698
6692
- if let Some(channel_ready) = self.check_get_channel_ready(height) {
6699
+ if let Some(channel_ready) = self.check_get_channel_ready(height, logger ) {
6693
6700
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
6694
6701
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
6695
6702
} else { None };
@@ -7876,7 +7883,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7876
7883
dual_funding_channel_context: None,
7877
7884
};
7878
7885
7879
- let need_channel_ready = channel.check_get_channel_ready(0).is_some();
7886
+ let need_channel_ready = channel.check_get_channel_ready(0, logger ).is_some();
7880
7887
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
7881
7888
Ok((channel, channel_monitor))
7882
7889
}
@@ -8165,7 +8172,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8165
8172
#[cfg(any(dual_funding, splicing))]
8166
8173
dual_funding_channel_context: None,
8167
8174
};
8168
- let need_channel_ready = channel.check_get_channel_ready(0).is_some();
8175
+ let need_channel_ready = channel.check_get_channel_ready(0, logger ).is_some();
8169
8176
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
8170
8177
8171
8178
Ok((channel, funding_signed, channel_monitor))
@@ -11274,6 +11281,6 @@ mod tests {
11274
11281
// Clear the ChannelState::WaitingForBatch only when called by ChannelManager.
11275
11282
node_a_chan.set_batch_ready();
11276
11283
assert_eq!(node_a_chan.context.channel_state, ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY));
11277
- assert!(node_a_chan.check_get_channel_ready(0).is_some());
11284
+ assert!(node_a_chan.check_get_channel_ready(0, &&logger ).is_some());
11278
11285
}
11279
11286
}
0 commit comments