Skip to content

Commit 21e6bfe

Browse files
committed
Handle fallible commitment point when getting channel_ready
1 parent 5c87f64 commit 21e6bfe

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
12801280
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
12811281
/// outbound or inbound.
12821282
signer_pending_funding: bool,
1283+
/// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send a
1284+
/// [`msgs::ChannelReady`].
1285+
signer_pending_channel_ready: bool,
12831286

12841287
// pending_update_fee is filled when sending and receiving update_fee.
12851288
//
@@ -1741,6 +1744,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17411744
signer_pending_revoke_and_ack: false,
17421745
signer_pending_commitment_update: false,
17431746
signer_pending_funding: false,
1747+
signer_pending_channel_ready: false,
17441748

17451749

17461750
#[cfg(debug_assertions)]
@@ -1970,6 +1974,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19701974
signer_pending_revoke_and_ack: false,
19711975
signer_pending_commitment_update: false,
19721976
signer_pending_funding: false,
1977+
signer_pending_channel_ready: false,
19731978

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

53555360
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5736,7 +5741,7 @@ impl<SP: Deref> Channel<SP> where
57365741

57375742
// We have OurChannelReady set!
57385743
return Ok(ReestablishResponses {
5739-
channel_ready: Some(self.get_channel_ready()),
5744+
channel_ready: self.get_channel_ready(logger),
57405745
raa: None, commitment_update: None,
57415746
order: RAACommitmentOrder::CommitmentFirst,
57425747
shutdown_msg, announcement_sigs,
@@ -5775,7 +5780,7 @@ impl<SP: Deref> Channel<SP> where
57755780

57765781
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.context.holder_commitment_point.transaction_number() == 1 {
57775782
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
5778-
Some(self.get_channel_ready())
5783+
self.get_channel_ready(logger)
57795784
} else { None };
57805785

57815786
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6682,19 +6687,23 @@ impl<SP: Deref> Channel<SP> where
66826687
return None;
66836688
}
66846689

6685-
// TODO: when get_per_commiment_point becomes async, check if the point is
6686-
// available, if not, set signer_pending_channel_ready and return None
6687-
6688-
Some(self.get_channel_ready())
6690+
self.get_channel_ready(logger)
66896691
}
66906692

6691-
fn get_channel_ready(&self) -> msgs::ChannelReady {
6692-
debug_assert!(self.context.holder_commitment_point.is_available());
6693-
msgs::ChannelReady {
6694-
channel_id: self.context.channel_id(),
6695-
next_per_commitment_point: self.context.holder_commitment_point.current_point()
6696-
.expect("TODO"),
6697-
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6693+
fn get_channel_ready<L: Deref>(&mut self, logger: &L) -> Option<msgs::ChannelReady>
6694+
where L::Target: Logger
6695+
{
6696+
if let HolderCommitmentPoint::Available { current, .. } = self.context.holder_commitment_point {
6697+
self.context.signer_pending_channel_ready = false;
6698+
Some(msgs::ChannelReady {
6699+
channel_id: self.context.channel_id(),
6700+
next_per_commitment_point: current,
6701+
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6702+
})
6703+
} else {
6704+
log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available.");
6705+
self.context.signer_pending_channel_ready = true;
6706+
None
66986707
}
66996708
}
67006709

@@ -9523,6 +9532,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
95239532
signer_pending_revoke_and_ack: false,
95249533
signer_pending_commitment_update: false,
95259534
signer_pending_funding: false,
9535+
signer_pending_channel_ready: false,
95269536

95279537
pending_update_fee,
95289538
holding_cell_update_fee,

0 commit comments

Comments
 (0)