Skip to content

Commit e8663c2

Browse files
committed
Handle fallible commitment point when getting channel_ready
1 parent 329b7a9 commit e8663c2

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

lightning/src/ln/channel.rs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,6 +1277,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
12771277
/// If we attempted to sign a cooperative close transaction but the signer wasn't ready, then this
12781278
/// will be set to `true`.
12791279
signer_pending_closing: bool,
1280+
/// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send a
1281+
/// [`msgs::ChannelReady`].
1282+
signer_pending_channel_ready: bool,
12801283

12811284
// pending_update_fee is filled when sending and receiving update_fee.
12821285
//
@@ -1744,6 +1747,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17441747
signer_pending_commitment_update: false,
17451748
signer_pending_funding: false,
17461749
signer_pending_closing: false,
1750+
signer_pending_channel_ready: false,
17471751

17481752

17491753
#[cfg(debug_assertions)]
@@ -1974,6 +1978,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19741978
signer_pending_commitment_update: false,
19751979
signer_pending_funding: false,
19761980
signer_pending_closing: false,
1981+
signer_pending_channel_ready: false,
19771982

19781983
// We'll add our counterparty's `funding_satoshis` to these max commitment output assertions
19791984
// when we receive `accept_channel2`.
@@ -5350,7 +5355,7 @@ impl<SP: Deref> Channel<SP> where
53505355
assert!(!self.context.is_outbound() || self.context.minimum_depth == Some(0),
53515356
"Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
53525357
self.context.monitor_pending_channel_ready = false;
5353-
Some(self.get_channel_ready())
5358+
self.get_channel_ready(logger)
53545359
} else { None };
53555360

53565361
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5767,7 +5772,7 @@ impl<SP: Deref> Channel<SP> where
57675772

57685773
// We have OurChannelReady set!
57695774
return Ok(ReestablishResponses {
5770-
channel_ready: Some(self.get_channel_ready()),
5775+
channel_ready: self.get_channel_ready(logger),
57715776
raa: None, commitment_update: None,
57725777
order: RAACommitmentOrder::CommitmentFirst,
57735778
shutdown_msg, announcement_sigs,
@@ -5806,7 +5811,7 @@ impl<SP: Deref> Channel<SP> where
58065811

58075812
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.holder_commitment_point.transaction_number() == 1 {
58085813
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
5809-
Some(self.get_channel_ready())
5814+
self.get_channel_ready(logger)
58105815
} else { None };
58115816

58125817
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6713,18 +6718,23 @@ impl<SP: Deref> Channel<SP> where
67136718
return None;
67146719
}
67156720

6716-
// TODO: when get_per_commiment_point becomes async, check if the point is
6717-
// available, if not, set signer_pending_channel_ready and return None
6718-
6719-
Some(self.get_channel_ready())
6721+
self.get_channel_ready(logger)
67206722
}
67216723

6722-
fn get_channel_ready(&self) -> msgs::ChannelReady {
6723-
debug_assert!(self.holder_commitment_point.is_available());
6724-
msgs::ChannelReady {
6725-
channel_id: self.context.channel_id(),
6726-
next_per_commitment_point: self.holder_commitment_point.current_point(),
6727-
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6724+
fn get_channel_ready<L: Deref>(&mut self, logger: &L) -> Option<msgs::ChannelReady>
6725+
where L::Target: Logger
6726+
{
6727+
if let HolderCommitmentPoint::Available { current, .. } = self.holder_commitment_point {
6728+
self.context.signer_pending_channel_ready = false;
6729+
Some(msgs::ChannelReady {
6730+
channel_id: self.context.channel_id(),
6731+
next_per_commitment_point: current,
6732+
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6733+
})
6734+
} else {
6735+
log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available.");
6736+
self.context.signer_pending_channel_ready = true;
6737+
None
67286738
}
67296739
}
67306740

@@ -9591,6 +9601,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95919601
signer_pending_commitment_update: false,
95929602
signer_pending_funding: false,
95939603
signer_pending_closing: false,
9604+
signer_pending_channel_ready: false,
95949605

95959606
pending_update_fee,
95969607
holding_cell_update_fee,

0 commit comments

Comments
 (0)