Skip to content

Commit 8004c6f

Browse files
committed
Handle implicit splice_locked during channel_reestablish
When handling a counterparties channel_reestablish, the spec dictates that a splice_locked may be implied by my_current_funding_locked. Compare that against any pending splices and handle an implicit splice_locked message when applicable.
1 parent 15eef7b commit 8004c6f

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

lightning/src/ln/channel.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,6 +1217,7 @@ pub(super) struct ReestablishResponses {
12171217
pub tx_signatures: Option<msgs::TxSignatures>,
12181218
pub tx_abort: Option<msgs::TxAbort>,
12191219
pub splice_locked: Option<msgs::SpliceLocked>,
1220+
pub implicit_splice_locked: Option<msgs::SpliceLocked>,
12201221
}
12211222

12221223
/// The first message we send to our peer after connection
@@ -8357,6 +8358,7 @@ where
83578358
tx_signatures: None,
83588359
tx_abort: None,
83598360
splice_locked: None,
8361+
implicit_splice_locked: None,
83608362
});
83618363
}
83628364

@@ -8369,6 +8371,7 @@ where
83698371
tx_signatures: None,
83708372
tx_abort: None,
83718373
splice_locked: None,
8374+
implicit_splice_locked: None,
83728375
});
83738376
}
83748377

@@ -8480,6 +8483,30 @@ where
84808483
splice_txid,
84818484
});
84828485

8486+
// A receiving node:
8487+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8488+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8489+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8490+
// for this `txid`.
8491+
#[cfg(splicing)]
8492+
let implicit_splice_locked = msg.my_current_funding_locked_txid.and_then(|funding_txid| {
8493+
self.pending_funding
8494+
.iter()
8495+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
8496+
.and_then(|_| {
8497+
self.pending_splice.as_ref().and_then(|pending_splice| {
8498+
(Some(funding_txid) != pending_splice.received_funding_txid)
8499+
.then(|| funding_txid)
8500+
})
8501+
})
8502+
.map(|splice_txid| msgs::SpliceLocked {
8503+
channel_id: self.context.channel_id,
8504+
splice_txid,
8505+
})
8506+
});
8507+
#[cfg(not(splicing))]
8508+
let implicit_splice_locked = None;
8509+
84838510
let mut commitment_update = None;
84848511
let mut tx_signatures = None;
84858512
let mut tx_abort = None;
@@ -8593,6 +8620,7 @@ where
85938620
tx_signatures,
85948621
tx_abort,
85958622
splice_locked,
8623+
implicit_splice_locked,
85968624
})
85978625
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
85988626
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8615,6 +8643,7 @@ where
86158643
tx_signatures,
86168644
tx_abort,
86178645
splice_locked,
8646+
implicit_splice_locked,
86188647
})
86198648
} else {
86208649
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8640,6 +8669,7 @@ where
86408669
tx_signatures,
86418670
tx_abort,
86428671
splice_locked,
8672+
implicit_splice_locked,
86438673
})
86448674
}
86458675
} else if msg.next_local_commitment_number < next_counterparty_commitment_number {

lightning/src/ln/channelmanager.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10046,7 +10046,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1004610046

1004710047
#[rustfmt::skip]
1004810048
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
10049-
let need_lnd_workaround = {
10049+
let (implicit_splice_locked, need_lnd_workaround) = {
1005010050
let per_peer_state = self.per_peer_state.read().unwrap();
1005110051

1005210052
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -10099,7 +10099,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1009910099
if let Some(upd) = channel_update {
1010010100
peer_state.pending_msg_events.push(upd);
1010110101
}
10102-
need_lnd_workaround
10102+
10103+
(responses.implicit_splice_locked, need_lnd_workaround)
1010310104
} else {
1010410105
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1010510106
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -10146,6 +10147,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1014610147
if let Some(channel_ready_msg) = need_lnd_workaround {
1014710148
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1014810149
}
10150+
10151+
#[cfg(not(splicing))]
10152+
let _ = implicit_splice_locked;
10153+
#[cfg(splicing)]
10154+
if let Some(splice_locked) = implicit_splice_locked {
10155+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
10156+
return Ok(NotifyOption::DoPersist);
10157+
}
10158+
1014910159
Ok(NotifyOption::SkipPersistHandleEvents)
1015010160
}
1015110161

0 commit comments

Comments
 (0)