Skip to content

Commit 239ed54

Browse files
committed
Handle fallible commitment point when getting channel_ready
1 parent 9f4872a commit 239ed54

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`.
@@ -5339,7 +5344,7 @@ impl<SP: Deref> Channel<SP> where
53395344
assert!(!self.context.is_outbound() || self.context.minimum_depth == Some(0),
53405345
"Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
53415346
self.context.monitor_pending_channel_ready = false;
5342-
Some(self.get_channel_ready())
5347+
self.get_channel_ready(logger)
53435348
} else { None };
53445349

53455350
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5708,7 +5713,7 @@ impl<SP: Deref> Channel<SP> where
57085713

57095714
// We have OurChannelReady set!
57105715
return Ok(ReestablishResponses {
5711-
channel_ready: Some(self.get_channel_ready()),
5716+
channel_ready: self.get_channel_ready(logger),
57125717
raa: None, commitment_update: None,
57135718
order: RAACommitmentOrder::CommitmentFirst,
57145719
shutdown_msg, announcement_sigs,
@@ -5747,7 +5752,7 @@ impl<SP: Deref> Channel<SP> where
57475752

57485753
let channel_ready = if msg.next_local_commitment_number == 1 && INITIAL_COMMITMENT_NUMBER - self.context.holder_commitment_point.transaction_number() == 1 {
57495754
// We should never have to worry about MonitorUpdateInProgress resending ChannelReady
5750-
Some(self.get_channel_ready())
5755+
self.get_channel_ready(logger)
57515756
} else { None };
57525757

57535758
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6654,19 +6659,23 @@ impl<SP: Deref> Channel<SP> where
66546659
return None;
66556660
}
66566661

6657-
// TODO: when get_per_commiment_point becomes async, check if the point is
6658-
// available, if not, set signer_pending_channel_ready and return None
6659-
6660-
Some(self.get_channel_ready())
6662+
self.get_channel_ready(logger)
66616663
}
66626664

6663-
fn get_channel_ready(&self) -> msgs::ChannelReady {
6664-
debug_assert!(self.context.holder_commitment_point.is_available());
6665-
msgs::ChannelReady {
6666-
channel_id: self.context.channel_id(),
6667-
next_per_commitment_point: self.context.holder_commitment_point.current_point()
6668-
.expect("TODO"),
6669-
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6665+
fn get_channel_ready<L: Deref>(&mut self, logger: &L) -> Option<msgs::ChannelReady>
6666+
where L::Target: Logger
6667+
{
6668+
if let HolderCommitmentPoint::Available { current, .. } = self.context.holder_commitment_point {
6669+
self.context.signer_pending_channel_ready = false;
6670+
Some(msgs::ChannelReady {
6671+
channel_id: self.context.channel_id(),
6672+
next_per_commitment_point: current,
6673+
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6674+
})
6675+
} else {
6676+
log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available.");
6677+
self.context.signer_pending_channel_ready = true;
6678+
None
66706679
}
66716680
}
66726681

@@ -9486,6 +9495,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
94869495
signer_pending_revoke_and_ack: false,
94879496
signer_pending_commitment_update: false,
94889497
signer_pending_funding: false,
9498+
signer_pending_channel_ready: false,
94899499

94909500
pending_update_fee,
94919501
holding_cell_update_fee,

0 commit comments

Comments
 (0)