Skip to content

Commit 07991fa

Browse files
committed
Handle fallible commitment point when getting channel_ready
1 parent c336da6 commit 07991fa

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

lightning/src/ln/channel.rs

+24-15
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
12211221
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
12221222
/// outbound or inbound.
12231223
signer_pending_funding: bool,
1224+
/// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send a
1225+
/// [`msgs::ChannelReady`].
1226+
signer_pending_channel_ready: bool,
12241227

12251228
// pending_update_fee is filled when sending and receiving update_fee.
12261229
//
@@ -1681,6 +1684,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
16811684

16821685
signer_pending_commitment_update: false,
16831686
signer_pending_funding: false,
1687+
signer_pending_channel_ready: false,
16841688

16851689

16861690
#[cfg(debug_assertions)]
@@ -1909,6 +1913,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19091913

19101914
signer_pending_commitment_update: false,
19111915
signer_pending_funding: false,
1916+
signer_pending_channel_ready: false,
19121917

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

51415146
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5438,7 +5443,7 @@ impl<SP: Deref> Channel<SP> where
54385443

54395444
// We have OurChannelReady set!
54405445
return Ok(ReestablishResponses {
5441-
channel_ready: Some(self.get_channel_ready()),
5446+
channel_ready: self.get_channel_ready(logger),
54425447
raa: None, commitment_update: None,
54435448
order: RAACommitmentOrder::CommitmentFirst,
54445449
shutdown_msg, announcement_sigs,
@@ -5477,7 +5482,7 @@ impl<SP: Deref> Channel<SP> where
54775482

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

54835488
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6368,24 +6373,27 @@ impl<SP: Deref> Channel<SP> where
63686373
}
63696374

63706375
if self.context.signer_pending_funding {
6371-
// TODO: set signer_pending_channel_ready
63726376
log_debug!(logger, "Can't produce channel_ready: the signer is pending funding.");
6377+
self.context.signer_pending_channel_ready = true;
63736378
return None;
63746379
}
63756380

6376-
// TODO: when get_per_commiment_point becomes async, check if the point is
6377-
// available, if not, set signer_pending_channel_ready and return None
6378-
6379-
Some(self.get_channel_ready())
6381+
self.get_channel_ready(logger)
63806382
}
63816383

6382-
fn get_channel_ready(&self) -> msgs::ChannelReady {
6383-
debug_assert!(self.context.holder_commitment_point.is_available());
6384-
msgs::ChannelReady {
6385-
channel_id: self.context.channel_id(),
6386-
next_per_commitment_point: self.context.holder_commitment_point.current_point()
6387-
.expect("TODO"),
6388-
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6384+
fn get_channel_ready<L: Deref>(&mut self, logger: &L) -> Option<msgs::ChannelReady>
6385+
where L::Target: Logger
6386+
{
6387+
if let HolderCommitmentPoint::Available { current, .. } = self.context.holder_commitment_point {
6388+
Some(msgs::ChannelReady {
6389+
channel_id: self.context.channel_id(),
6390+
next_per_commitment_point: current,
6391+
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6392+
})
6393+
} else {
6394+
log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available.");
6395+
self.context.signer_pending_channel_ready = true;
6396+
None
63896397
}
63906398
}
63916399

@@ -9314,6 +9322,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
93149322

93159323
signer_pending_commitment_update: false,
93169324
signer_pending_funding: false,
9325+
signer_pending_channel_ready: false,
93179326

93189327
pending_update_fee,
93199328
holding_cell_update_fee,

0 commit comments

Comments
 (0)