Skip to content

Commit 585493a

Browse files
committed
Handle cases where a channel is in use w/o an SCID in ChannelManager
In the next few commits we add support for 0conf channels, allowing us to have an active channel with HTLC and other updates flying prior to having an SCID available. This would break several assumptions made in `ChannelManager`, which we address here by looking at SCID aliases in addition to SCIDs.
1 parent 342698f commit 585493a

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lightning/src/ln/channel.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3565,9 +3565,10 @@ impl<Signer: Sign> Channel<Signer> {
35653565

35663566
// We will never broadcast the funding transaction when we're in MonitorUpdateFailed (and
35673567
// we assume the user never directly broadcasts the funding transaction and waits for us to
3568-
// do it). Thus, we can only ever hit monitor_pending_funding_locked when we're an inbound
3569-
// channel which failed to persist the monitor on funding_created, and we got the funding
3570-
// transaction confirmed before the monitor was persisted.
3568+
// do it). Thus, we can only ever hit monitor_pending_funding_locked when we're
3569+
// * an inbound channel that failed to persist the monitor on funding_created and we got
3570+
// the funding transaction confirmed before the monitor was persisted, or
3571+
// * a 0-conf channel and intended to send the funding_locked before any broadcast at all.
35713572
let funding_locked = if self.monitor_pending_funding_locked {
35723573
assert!(!self.is_outbound(), "Funding transaction broadcast by the local client before it should have - LDK didn't do it!");
35733574
self.monitor_pending_funding_locked = false;

lightning/src/ln/channelmanager.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ use util::crypto::sign;
9393
pub(super) enum PendingHTLCRouting {
9494
Forward {
9595
onion_packet: msgs::OnionPacket,
96+
/// The SCID from the onion that we should forward to. This could be a "real" SCID, an
97+
/// outbound SCID alias, or a phantom node SCID.
9698
short_channel_id: u64, // This should be NonZero<u64> eventually when we bump MSRV
9799
},
98100
Receive {
@@ -136,6 +138,8 @@ pub(super) enum HTLCForwardInfo {
136138
// `process_pending_htlc_forwards()` for constructing the
137139
// `HTLCSource::PreviousHopData` for failed and forwarded
138140
// HTLCs.
141+
//
142+
// Note that this may be an outbound SCID alias for the associated channel.
139143
prev_short_channel_id: u64,
140144
prev_htlc_id: u64,
141145
prev_funding_outpoint: OutPoint,
@@ -149,6 +153,7 @@ pub(super) enum HTLCForwardInfo {
149153
/// Tracks the inbound corresponding to an outbound HTLC
150154
#[derive(Clone, Hash, PartialEq, Eq)]
151155
pub(crate) struct HTLCPreviousHopData {
156+
// Note that this may be an outbound SCID alias for the associated channel.
152157
short_channel_id: u64,
153158
htlc_id: u64,
154159
incoming_packet_shared_secret: [u8; 32],
@@ -1398,7 +1403,7 @@ macro_rules! handle_chan_restoration_locked {
13981403
let res = loop {
13991404
let forwards: Vec<(PendingHTLCInfo, u64)> = $pending_forwards; // Force type-checking to resolve
14001405
if !forwards.is_empty() {
1401-
htlc_forwards = Some(($channel_entry.get().get_short_channel_id().expect("We can't have pending forwards before funding confirmation"),
1406+
htlc_forwards = Some(($channel_entry.get().get_short_channel_id().unwrap_or($channel_entry.get().outbound_scid_alias()),
14021407
$channel_entry.get().get_funding_txo().unwrap(), forwards));
14031408
}
14041409

@@ -4676,7 +4681,7 @@ impl<Signer: Sign, M: Deref, T: Deref, K: Deref, F: Deref, L: Deref> ChannelMana
46764681
break Ok((raa_updates.accepted_htlcs, raa_updates.failed_htlcs,
46774682
raa_updates.finalized_claimed_htlcs,
46784683
chan.get().get_short_channel_id()
4679-
.expect("RAA should only work on a short-id-available channel"),
4684+
.unwrap_or(chan.get().outbound_scid_alias()),
46804685
chan.get().get_funding_txo().unwrap()))
46814686
},
46824687
hash_map::Entry::Vacant(_) => break Err(MsgHandleErrInternal::send_err_msg_no_close("Failed to find corresponding channel".to_owned(), msg.channel_id))

0 commit comments

Comments
 (0)