@@ -5306,12 +5306,7 @@ impl<SP: Deref> Channel<SP> where
5306
5306
assert!(!self.context.is_outbound() || self.context.minimum_depth == Some(0),
5307
5307
"Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
5308
5308
self.context.monitor_pending_channel_ready = false;
5309
- 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);
5310
- Some(msgs::ChannelReady {
5311
- channel_id: self.context.channel_id(),
5312
- next_per_commitment_point,
5313
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5314
- })
5309
+ Some(self.get_channel_ready())
5315
5310
} else { None };
5316
5311
5317
5312
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5397,7 +5392,7 @@ impl<SP: Deref> Channel<SP> where
5397
5392
self.context.get_funding_signed_msg(logger).1
5398
5393
} else { None };
5399
5394
let channel_ready = if funding_signed.is_some() {
5400
- self.check_get_channel_ready(0)
5395
+ self.check_get_channel_ready(0, logger )
5401
5396
} else { None };
5402
5397
5403
5398
log_trace!(logger, "Signer unblocked with {} commitment_update, {} funding_signed and {} channel_ready",
@@ -5609,13 +5604,8 @@ impl<SP: Deref> Channel<SP> where
5609
5604
}
5610
5605
5611
5606
// We have OurChannelReady set!
5612
- 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);
5613
5607
return Ok(ReestablishResponses {
5614
- channel_ready: Some(msgs::ChannelReady {
5615
- channel_id: self.context.channel_id(),
5616
- next_per_commitment_point,
5617
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5618
- }),
5608
+ channel_ready: Some(self.get_channel_ready()),
5619
5609
raa: None, commitment_update: None,
5620
5610
order: RAACommitmentOrder::CommitmentFirst,
5621
5611
shutdown_msg, announcement_sigs,
@@ -5654,12 +5644,7 @@ impl<SP: Deref> Channel<SP> where
5654
5644
5655
5645
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.context.holder_commitment_point.transaction_number() == 1 {
5656
5646
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
5657
- 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);
5658
- Some(msgs::ChannelReady {
5659
- channel_id: self.context.channel_id(),
5660
- next_per_commitment_point,
5661
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
5662
- })
5647
+ Some(self.get_channel_ready())
5663
5648
} else { None };
5664
5649
5665
5650
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6479,7 +6464,9 @@ impl<SP: Deref> Channel<SP> where
6479
6464
self.context.channel_update_status = status;
6480
6465
}
6481
6466
6482
- fn check_get_channel_ready(&mut self, height: u32) -> Option<msgs::ChannelReady> {
6467
+ fn check_get_channel_ready<L: Deref>(&mut self, height: u32, logger: &L) -> Option<msgs::ChannelReady>
6468
+ where L::Target: Logger
6469
+ {
6483
6470
// Called:
6484
6471
// * always when a new block/transactions are confirmed with the new height
6485
6472
// * when funding is signed with a height of 0
@@ -6531,22 +6518,41 @@ impl<SP: Deref> Channel<SP> where
6531
6518
false
6532
6519
};
6533
6520
6534
- if need_commitment_update {
6535
- if !self.context.channel_state.is_monitor_update_in_progress() {
6536
- if !self.context.channel_state.is_peer_disconnected() {
6537
- let next_per_commitment_point =
6538
- self.context.holder_signer.as_ref().get_per_commitment_point(INITIAL_COMMITMENT_NUMBER - 1, &self.context.secp_ctx);
6539
- return Some(msgs::ChannelReady {
6540
- channel_id: self.context.channel_id,
6541
- next_per_commitment_point,
6542
- short_channel_id_alias: Some(self.context.outbound_scid_alias),
6543
- });
6544
- }
6545
- } else {
6546
- self.context.monitor_pending_channel_ready = true;
6547
- }
6521
+ if !need_commitment_update {
6522
+ log_debug!(logger, "Not producing channel_ready: we do not need a commitment update");
6523
+ return None;
6524
+ }
6525
+
6526
+ if self.context.channel_state.is_monitor_update_in_progress() {
6527
+ log_debug!(logger, "Not producing channel_ready: a monitor update is in progress. Setting monitor_pending_channel_ready.");
6528
+ self.context.monitor_pending_channel_ready = true;
6529
+ return None;
6530
+ }
6531
+
6532
+ if self.context.channel_state.is_peer_disconnected() {
6533
+ log_debug!(logger, "Not producing channel_ready: the peer is disconnected.");
6534
+ return None;
6535
+ }
6536
+
6537
+ if self.context.signer_pending_funding {
6538
+ // TODO: set signer_pending_channel_ready
6539
+ log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
6540
+ return None;
6541
+ }
6542
+
6543
+ // TODO: when get_per_commiment_point becomes async, check if the point is
6544
+ // available, if not, set signer_pending_channel_ready and return None
6545
+
6546
+ Some(self.get_channel_ready())
6547
+ }
6548
+
6549
+ fn get_channel_ready(&self) -> msgs::ChannelReady {
6550
+ debug_assert!(self.context.holder_commitment_point.is_available());
6551
+ msgs::ChannelReady {
6552
+ channel_id: self.context.channel_id(),
6553
+ next_per_commitment_point: self.context.holder_commitment_point.current_point(),
6554
+ short_channel_id_alias: Some(self.context.outbound_scid_alias),
6548
6555
}
6549
- None
6550
6556
}
6551
6557
6552
6558
/// When a transaction is confirmed, we check whether it is or spends the funding transaction
@@ -6613,7 +6619,7 @@ impl<SP: Deref> Channel<SP> where
6613
6619
// If we allow 1-conf funding, we may need to check for channel_ready here and
6614
6620
// send it immediately instead of waiting for a best_block_updated call (which
6615
6621
// may have already happened for this block).
6616
- if let Some(channel_ready) = self.check_get_channel_ready(height) {
6622
+ if let Some(channel_ready) = self.check_get_channel_ready(height, logger ) {
6617
6623
log_info!(logger, "Sending a channel_ready to our peer for channel {}", &self.context.channel_id);
6618
6624
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger);
6619
6625
msgs = (Some(channel_ready), announcement_sigs);
@@ -6679,7 +6685,7 @@ impl<SP: Deref> Channel<SP> where
6679
6685
6680
6686
self.context.update_time_counter = cmp::max(self.context.update_time_counter, highest_header_time);
6681
6687
6682
- if let Some(channel_ready) = self.check_get_channel_ready(height) {
6688
+ if let Some(channel_ready) = self.check_get_channel_ready(height, logger ) {
6683
6689
let announcement_sigs = if let Some((chain_hash, node_signer, user_config)) = chain_node_signer {
6684
6690
self.get_announcement_sigs(node_signer, chain_hash, user_config, height, logger)
6685
6691
} else { None };
@@ -7864,7 +7870,7 @@ impl<SP: Deref> OutboundV1Channel<SP> where SP::Target: SignerProvider {
7864
7870
dual_funding_channel_context: None,
7865
7871
};
7866
7872
7867
- let need_channel_ready = channel.check_get_channel_ready(0).is_some();
7873
+ let need_channel_ready = channel.check_get_channel_ready(0, logger ).is_some();
7868
7874
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
7869
7875
Ok((channel, channel_monitor))
7870
7876
}
@@ -8153,7 +8159,7 @@ impl<SP: Deref> InboundV1Channel<SP> where SP::Target: SignerProvider {
8153
8159
#[cfg(any(dual_funding, splicing))]
8154
8160
dual_funding_channel_context: None,
8155
8161
};
8156
- let need_channel_ready = channel.check_get_channel_ready(0).is_some();
8162
+ let need_channel_ready = channel.check_get_channel_ready(0, logger ).is_some();
8157
8163
channel.monitor_updating_paused(false, false, need_channel_ready, Vec::new(), Vec::new(), Vec::new());
8158
8164
8159
8165
Ok((channel, funding_signed, channel_monitor))
@@ -11260,6 +11266,6 @@ mod tests {
11260
11266
// Clear the ChannelState::WaitingForBatch only when called by ChannelManager.
11261
11267
node_a_chan.set_batch_ready();
11262
11268
assert_eq!(node_a_chan.context.channel_state, ChannelState::AwaitingChannelReady(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY));
11263
- assert!(node_a_chan.check_get_channel_ready(0).is_some());
11269
+ assert!(node_a_chan.check_get_channel_ready(0, &&logger ).is_some());
11264
11270
}
11265
11271
}
0 commit comments