Skip to content

Commit

Permalink
Handle fallible commitment point when getting channel_ready
Browse files Browse the repository at this point in the history
  • Loading branch information
alecchendev committed Jul 3, 2024
1 parent 9f4872a commit 239ed54
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions lightning/src/ln/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
/// outbound or inbound.
signer_pending_funding: bool,
/// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send a
/// [`msgs::ChannelReady`].
signer_pending_channel_ready: bool,

// pending_update_fee is filled when sending and receiving update_fee.
//
Expand Down Expand Up @@ -1741,6 +1744,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
signer_pending_revoke_and_ack: false,
signer_pending_commitment_update: false,
signer_pending_funding: false,
signer_pending_channel_ready: false,


#[cfg(debug_assertions)]
Expand Down Expand Up @@ -1970,6 +1974,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
signer_pending_revoke_and_ack: false,
signer_pending_commitment_update: false,
signer_pending_funding: false,
signer_pending_channel_ready: false,

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

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

// We have OurChannelReady set!
return Ok(ReestablishResponses {
channel_ready: Some(self.get_channel_ready()),
channel_ready: self.get_channel_ready(logger),
raa: None, commitment_update: None,
order: RAACommitmentOrder::CommitmentFirst,
shutdown_msg, announcement_sigs,
Expand Down Expand Up @@ -5747,7 +5752,7 @@ impl<SP: Deref> Channel<SP> where

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

if msg.next_local_commitment_number == next_counterparty_commitment_number {
Expand Down Expand Up @@ -6654,19 +6659,23 @@ impl<SP: Deref> Channel<SP> where
return None;
}

// TODO: when get_per_commiment_point becomes async, check if the point is
// available, if not, set signer_pending_channel_ready and return None

Some(self.get_channel_ready())
self.get_channel_ready(logger)
}

fn get_channel_ready(&self) -> msgs::ChannelReady {
debug_assert!(self.context.holder_commitment_point.is_available());
msgs::ChannelReady {
channel_id: self.context.channel_id(),
next_per_commitment_point: self.context.holder_commitment_point.current_point()
.expect("TODO"),
short_channel_id_alias: Some(self.context.outbound_scid_alias),
fn get_channel_ready<L: Deref>(&mut self, logger: &L) -> Option<msgs::ChannelReady>
where L::Target: Logger
{
if let HolderCommitmentPoint::Available { current, .. } = self.context.holder_commitment_point {
self.context.signer_pending_channel_ready = false;
Some(msgs::ChannelReady {
channel_id: self.context.channel_id(),
next_per_commitment_point: current,
short_channel_id_alias: Some(self.context.outbound_scid_alias),
})
} else {
log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available.");
self.context.signer_pending_channel_ready = true;
None
}
}

Expand Down Expand Up @@ -9486,6 +9495,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
signer_pending_revoke_and_ack: false,
signer_pending_commitment_update: false,
signer_pending_funding: false,
signer_pending_channel_ready: false,

pending_update_fee,
holding_cell_update_fee,
Expand Down

0 comments on commit 239ed54

Please sign in to comment.