Skip to content

Commit 9fabe4e

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 836efe3 commit 9fabe4e

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
@@ -1215,6 +1215,7 @@ pub(super) struct ReestablishResponses {
12151215
pub shutdown_msg: Option<msgs::Shutdown>,
12161216
pub tx_signatures: Option<msgs::TxSignatures>,
12171217
pub tx_abort: Option<msgs::TxAbort>,
1218+
pub implicit_splice_locked: Option<msgs::SpliceLocked>,
12181219
}
12191220

12201221
/// The first message we send to our peer after connection
@@ -8750,6 +8751,7 @@ where
87508751
shutdown_msg, announcement_sigs,
87518752
tx_signatures: None,
87528753
tx_abort: None,
8754+
implicit_splice_locked: None,
87538755
});
87548756
}
87558757

@@ -8761,6 +8763,7 @@ where
87618763
shutdown_msg, announcement_sigs,
87628764
tx_signatures: None,
87638765
tx_abort: None,
8766+
implicit_splice_locked: None,
87648767
});
87658768
}
87668769

@@ -8796,6 +8799,30 @@ where
87968799
self.get_channel_ready(logger)
87978800
} else { None };
87988801

8802+
// A receiving node:
8803+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8804+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8805+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8806+
// for this `txid`.
8807+
#[cfg(splicing)]
8808+
let implicit_splice_locked = msg.my_current_funding_locked_txid.and_then(|funding_txid| {
8809+
self.pending_funding
8810+
.iter()
8811+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
8812+
.and_then(|_| {
8813+
self.pending_splice.as_ref().and_then(|pending_splice| {
8814+
(Some(funding_txid) != pending_splice.received_funding_txid)
8815+
.then(|| funding_txid)
8816+
})
8817+
})
8818+
.map(|splice_txid| msgs::SpliceLocked {
8819+
channel_id: self.context.channel_id,
8820+
splice_txid,
8821+
})
8822+
});
8823+
#[cfg(not(splicing))]
8824+
let implicit_splice_locked = None;
8825+
87998826
let mut commitment_update = None;
88008827
let mut tx_signatures = None;
88018828
let mut tx_abort = None;
@@ -8904,6 +8931,7 @@ where
89048931
order: self.context.resend_order.clone(),
89058932
tx_signatures,
89068933
tx_abort,
8934+
implicit_splice_locked,
89078935
})
89088936
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
89098937
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8925,6 +8953,7 @@ where
89258953
order: self.context.resend_order.clone(),
89268954
tx_signatures,
89278955
tx_abort,
8956+
implicit_splice_locked,
89288957
})
89298958
} else {
89308959
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8949,6 +8978,7 @@ where
89498978
order: self.context.resend_order.clone(),
89508979
tx_signatures,
89518980
tx_abort,
8981+
implicit_splice_locked,
89528982
})
89538983
}
89548984
} 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
@@ -10966,7 +10966,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1096610966

1096710967
#[rustfmt::skip]
1096810968
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
10969-
let need_lnd_workaround = {
10969+
let (implicit_splice_locked, need_lnd_workaround) = {
1097010970
let per_peer_state = self.per_peer_state.read().unwrap();
1097110971

1097210972
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -11017,7 +11017,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1101711017
if let Some(upd) = channel_update {
1101811018
peer_state.pending_msg_events.push(upd);
1101911019
}
11020-
need_lnd_workaround
11020+
11021+
(responses.implicit_splice_locked, need_lnd_workaround)
1102111022
} else {
1102211023
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1102311024
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -11063,6 +11064,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1106311064
if let Some(channel_ready_msg) = need_lnd_workaround {
1106411065
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1106511066
}
11067+
11068+
#[cfg(not(splicing))]
11069+
let _ = implicit_splice_locked;
11070+
#[cfg(splicing)]
11071+
if let Some(splice_locked) = implicit_splice_locked {
11072+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
11073+
return Ok(NotifyOption::DoPersist);
11074+
}
11075+
1106611076
Ok(NotifyOption::SkipPersistHandleEvents)
1106711077
}
1106811078

0 commit comments

Comments
 (0)