Skip to content

Commit f000b76

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 0b13b32 commit f000b76

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
@@ -1214,6 +1214,7 @@ pub(super) struct ReestablishResponses {
12141214
pub tx_signatures: Option<msgs::TxSignatures>,
12151215
pub tx_abort: Option<msgs::TxAbort>,
12161216
pub splice_locked: Option<msgs::SpliceLocked>,
1217+
pub implicit_splice_locked: Option<msgs::SpliceLocked>,
12171218
}
12181219

12191220
/// The first message we send to our peer after connection
@@ -8396,6 +8397,7 @@ where
83968397
tx_signatures: None,
83978398
tx_abort: None,
83988399
splice_locked: None,
8400+
implicit_splice_locked: None,
83998401
});
84008402
}
84018403

@@ -8408,6 +8410,7 @@ where
84088410
tx_signatures: None,
84098411
tx_abort: None,
84108412
splice_locked: None,
8413+
implicit_splice_locked: None,
84118414
});
84128415
}
84138416

@@ -8519,6 +8522,30 @@ where
85198522
splice_txid,
85208523
});
85218524

8525+
// A receiving node:
8526+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8527+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8528+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8529+
// for this `txid`.
8530+
#[cfg(splicing)]
8531+
let implicit_splice_locked = msg.my_current_funding_locked_txid.and_then(|funding_txid| {
8532+
self.pending_funding
8533+
.iter()
8534+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
8535+
.and_then(|_| {
8536+
self.pending_splice.as_ref().and_then(|pending_splice| {
8537+
(Some(funding_txid) != pending_splice.received_funding_txid)
8538+
.then(|| funding_txid)
8539+
})
8540+
})
8541+
.map(|splice_txid| msgs::SpliceLocked {
8542+
channel_id: self.context.channel_id,
8543+
splice_txid,
8544+
})
8545+
});
8546+
#[cfg(not(splicing))]
8547+
let implicit_splice_locked = None;
8548+
85228549
let mut commitment_update = None;
85238550
let mut tx_signatures = None;
85248551
let mut tx_abort = None;
@@ -8626,6 +8653,7 @@ where
86268653
tx_signatures,
86278654
tx_abort,
86288655
splice_locked,
8656+
implicit_splice_locked,
86298657
})
86308658
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
86318659
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8648,6 +8676,7 @@ where
86488676
tx_signatures,
86498677
tx_abort,
86508678
splice_locked,
8679+
implicit_splice_locked,
86518680
})
86528681
} else {
86538682
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8673,6 +8702,7 @@ where
86738702
tx_signatures,
86748703
tx_abort,
86758704
splice_locked,
8705+
implicit_splice_locked,
86768706
})
86778707
}
86788708
} 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
@@ -10017,7 +10017,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1001710017

1001810018
#[rustfmt::skip]
1001910019
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
10020-
let need_lnd_workaround = {
10020+
let (implicit_splice_locked, need_lnd_workaround) = {
1002110021
let per_peer_state = self.per_peer_state.read().unwrap();
1002210022

1002310023
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -10070,7 +10070,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1007010070
if let Some(upd) = channel_update {
1007110071
peer_state.pending_msg_events.push(upd);
1007210072
}
10073-
need_lnd_workaround
10073+
10074+
(responses.implicit_splice_locked, need_lnd_workaround)
1007410075
} else {
1007510076
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1007610077
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -10117,6 +10118,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1011710118
if let Some(channel_ready_msg) = need_lnd_workaround {
1011810119
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1011910120
}
10121+
10122+
#[cfg(not(splicing))]
10123+
let _ = implicit_splice_locked;
10124+
#[cfg(splicing)]
10125+
if let Some(splice_locked) = implicit_splice_locked {
10126+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
10127+
}
10128+
1012010129
Ok(NotifyOption::SkipPersistHandleEvents)
1012110130
}
1012210131

0 commit comments

Comments
 (0)