Skip to content

Commit 365b848

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 ab7a33f commit 365b848

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-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
@@ -8356,6 +8357,7 @@ where
83568357
tx_signatures: None,
83578358
tx_abort: None,
83588359
splice_locked: None,
8360+
implicit_splice_locked: None,
83598361
});
83608362
}
83618363

@@ -8368,6 +8370,7 @@ where
83688370
tx_signatures: None,
83698371
tx_abort: None,
83708372
splice_locked: None,
8373+
implicit_splice_locked: None,
83718374
});
83728375
}
83738376

@@ -8479,6 +8482,30 @@ where
84798482
splice_txid,
84808483
});
84818484

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

lightning/src/ln/channelmanager.rs

Lines changed: 11 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,14 @@ 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+
}
10157+
1014910158
Ok(NotifyOption::SkipPersistHandleEvents)
1015010159
}
1015110160

0 commit comments

Comments
 (0)