Skip to content

Commit 49ba3f7

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 8a2e86e commit 49ba3f7

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
@@ -1216,6 +1216,7 @@ pub(super) struct ReestablishResponses {
12161216
pub tx_signatures: Option<msgs::TxSignatures>,
12171217
pub tx_abort: Option<msgs::TxAbort>,
12181218
pub splice_locked: Option<msgs::SpliceLocked>,
1219+
pub implicit_splice_locked: Option<msgs::SpliceLocked>,
12191220
}
12201221

12211222
/// The first message we send to our peer after connection
@@ -8758,6 +8759,7 @@ where
87588759
tx_signatures: None,
87598760
tx_abort: None,
87608761
splice_locked: None,
8762+
implicit_splice_locked: None,
87618763
});
87628764
}
87638765

@@ -8770,6 +8772,7 @@ where
87708772
tx_signatures: None,
87718773
tx_abort: None,
87728774
splice_locked: None,
8775+
implicit_splice_locked: None,
87738776
});
87748777
}
87758778

@@ -8883,6 +8886,30 @@ where
88838886
splice_txid,
88848887
});
88858888

8889+
// A receiving node:
8890+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8891+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8892+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8893+
// for this `txid`.
8894+
#[cfg(splicing)]
8895+
let implicit_splice_locked = msg.my_current_funding_locked_txid.and_then(|funding_txid| {
8896+
self.pending_funding
8897+
.iter()
8898+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
8899+
.and_then(|_| {
8900+
self.pending_splice.as_ref().and_then(|pending_splice| {
8901+
(Some(funding_txid) != pending_splice.received_funding_txid)
8902+
.then(|| funding_txid)
8903+
})
8904+
})
8905+
.map(|splice_txid| msgs::SpliceLocked {
8906+
channel_id: self.context.channel_id,
8907+
splice_txid,
8908+
})
8909+
});
8910+
#[cfg(not(splicing))]
8911+
let implicit_splice_locked = None;
8912+
88868913
let mut commitment_update = None;
88878914
let mut tx_signatures = None;
88888915
let mut tx_abort = None;
@@ -8992,6 +9019,7 @@ where
89929019
tx_signatures,
89939020
tx_abort,
89949021
splice_locked,
9022+
implicit_splice_locked,
89959023
})
89969024
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
89979025
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -9014,6 +9042,7 @@ where
90149042
tx_signatures,
90159043
tx_abort,
90169044
splice_locked,
9045+
implicit_splice_locked,
90179046
})
90189047
} else {
90199048
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -9039,6 +9068,7 @@ where
90399068
tx_signatures,
90409069
tx_abort,
90419070
splice_locked,
9071+
implicit_splice_locked,
90429072
})
90439073
}
90449074
} 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
@@ -10975,7 +10975,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1097510975

1097610976
#[rustfmt::skip]
1097710977
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
10978-
let need_lnd_workaround = {
10978+
let (implicit_splice_locked, need_lnd_workaround) = {
1097910979
let per_peer_state = self.per_peer_state.read().unwrap();
1098010980

1098110981
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -11028,7 +11028,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1102811028
if let Some(upd) = channel_update {
1102911029
peer_state.pending_msg_events.push(upd);
1103011030
}
11031-
need_lnd_workaround
11031+
11032+
(responses.implicit_splice_locked, need_lnd_workaround)
1103211033
} else {
1103311034
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1103411035
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -11075,6 +11076,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1107511076
if let Some(channel_ready_msg) = need_lnd_workaround {
1107611077
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1107711078
}
11079+
11080+
#[cfg(not(splicing))]
11081+
let _ = implicit_splice_locked;
11082+
#[cfg(splicing)]
11083+
if let Some(splice_locked) = implicit_splice_locked {
11084+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
11085+
return Ok(NotifyOption::DoPersist);
11086+
}
11087+
1107811088
Ok(NotifyOption::SkipPersistHandleEvents)
1107911089
}
1108011090

0 commit comments

Comments
 (0)