Skip to content

Commit 6d723ad

Browse files
committed
Handle fallible commitment point when getting channel_ready
1 parent 2c58dc0 commit 6d723ad

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,6 +1270,9 @@ pub(super) struct ChannelContext<SP: Deref> where SP::Target: SignerProvider {
12701270
/// [`msgs::FundingCreated`] or [`msgs::FundingSigned`] depending on if this channel is
12711271
/// outbound or inbound.
12721272
signer_pending_funding: bool,
1273+
/// Similar to [`Self::signer_pending_commitment_update`] but we're waiting to send a
1274+
/// [`msgs::ChannelReady`].
1275+
signer_pending_channel_ready: bool,
12731276

12741277
// pending_update_fee is filled when sending and receiving update_fee.
12751278
//
@@ -1730,6 +1733,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
17301733

17311734
signer_pending_commitment_update: false,
17321735
signer_pending_funding: false,
1736+
signer_pending_channel_ready: false,
17331737

17341738

17351739
#[cfg(debug_assertions)]
@@ -1958,6 +1962,7 @@ impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
19581962

19591963
signer_pending_commitment_update: false,
19601964
signer_pending_funding: false,
1965+
signer_pending_channel_ready: false,
19611966

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

53305335
let announcement_sigs = self.get_announcement_sigs(node_signer, chain_hash, user_config, best_block_height, logger);
@@ -5647,7 +5652,7 @@ impl<SP: Deref> Channel<SP> where
56475652

56485653
// We have OurChannelReady set!
56495654
return Ok(ReestablishResponses {
5650-
channel_ready: Some(self.get_channel_ready()),
5655+
channel_ready: self.get_channel_ready(logger),
56515656
raa: None, commitment_update: None,
56525657
order: RAACommitmentOrder::CommitmentFirst,
56535658
shutdown_msg, announcement_sigs,
@@ -5686,7 +5691,7 @@ impl<SP: Deref> Channel<SP> where
56865691

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

56925697
if msg.next_local_commitment_number == next_counterparty_commitment_number {
@@ -6578,19 +6583,22 @@ impl<SP: Deref> Channel<SP> where
65786583
return None;
65796584
}
65806585

6581-
// TODO: when get_per_commiment_point becomes async, check if the point is
6582-
// available, if not, set signer_pending_channel_ready and return None
6583-
6584-
Some(self.get_channel_ready())
6586+
self.get_channel_ready(logger)
65856587
}
65866588

6587-
fn get_channel_ready(&self) -> msgs::ChannelReady {
6588-
debug_assert!(self.context.holder_commitment_point.is_available());
6589-
msgs::ChannelReady {
6590-
channel_id: self.context.channel_id(),
6591-
next_per_commitment_point: self.context.holder_commitment_point.current_point()
6592-
.expect("TODO"),
6593-
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6589+
fn get_channel_ready<L: Deref>(&mut self, logger: &L) -> Option<msgs::ChannelReady>
6590+
where L::Target: Logger
6591+
{
6592+
if let HolderCommitmentPoint::Available { current, .. } = self.context.holder_commitment_point {
6593+
Some(msgs::ChannelReady {
6594+
channel_id: self.context.channel_id(),
6595+
next_per_commitment_point: current,
6596+
short_channel_id_alias: Some(self.context.outbound_scid_alias),
6597+
})
6598+
} else {
6599+
log_debug!(logger, "Not producing channel_ready: the holder commitment point is not available.");
6600+
self.context.signer_pending_channel_ready = true;
6601+
None
65946602
}
65956603
}
65966604

@@ -9411,6 +9419,7 @@ impl<'a, 'b, 'c, ES: Deref, SP: Deref> ReadableArgs<(&'a ES, &'b SP, u32, &'c Ch
94119419

94129420
signer_pending_commitment_update: false,
94139421
signer_pending_funding: false,
9422+
signer_pending_channel_ready: false,
94149423

94159424
pending_update_fee,
94169425
holding_cell_update_fee,

0 commit comments

Comments
 (0)