Skip to content

Commit c4f2483

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 c151332 commit c4f2483

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
@@ -8763,6 +8764,7 @@ where
87638764
tx_signatures: None,
87648765
tx_abort: None,
87658766
splice_locked: None,
8767+
implicit_splice_locked: None,
87668768
});
87678769
}
87688770

@@ -8775,6 +8777,7 @@ where
87758777
tx_signatures: None,
87768778
tx_abort: None,
87778779
splice_locked: None,
8780+
implicit_splice_locked: None,
87788781
});
87798782
}
87808783

@@ -8888,6 +8891,30 @@ where
88888891
splice_txid,
88898892
});
88908893

8894+
// A receiving node:
8895+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8896+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8897+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8898+
// for this `txid`.
8899+
#[cfg(splicing)]
8900+
let implicit_splice_locked = msg.my_current_funding_locked_txid.and_then(|funding_txid| {
8901+
self.pending_funding
8902+
.iter()
8903+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
8904+
.and_then(|_| {
8905+
self.pending_splice.as_ref().and_then(|pending_splice| {
8906+
(Some(funding_txid) != pending_splice.received_funding_txid)
8907+
.then(|| funding_txid)
8908+
})
8909+
})
8910+
.map(|splice_txid| msgs::SpliceLocked {
8911+
channel_id: self.context.channel_id,
8912+
splice_txid,
8913+
})
8914+
});
8915+
#[cfg(not(splicing))]
8916+
let implicit_splice_locked = None;
8917+
88918918
let mut commitment_update = None;
88928919
let mut tx_signatures = None;
88938920
let mut tx_abort = None;
@@ -9003,6 +9030,7 @@ where
90039030
tx_signatures,
90049031
tx_abort,
90059032
splice_locked,
9033+
implicit_splice_locked,
90069034
})
90079035
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
90089036
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -9025,6 +9053,7 @@ where
90259053
tx_signatures,
90269054
tx_abort,
90279055
splice_locked,
9056+
implicit_splice_locked,
90289057
})
90299058
} else {
90309059
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -9050,6 +9079,7 @@ where
90509079
tx_signatures,
90519080
tx_abort,
90529081
splice_locked,
9082+
implicit_splice_locked,
90539083
})
90549084
}
90559085
} 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
@@ -10778,7 +10778,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1077810778

1077910779
#[rustfmt::skip]
1078010780
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
10781-
let need_lnd_workaround = {
10781+
let (implicit_splice_locked, need_lnd_workaround) = {
1078210782
let per_peer_state = self.per_peer_state.read().unwrap();
1078310783

1078410784
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -10831,7 +10831,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1083110831
if let Some(upd) = channel_update {
1083210832
peer_state.pending_msg_events.push(upd);
1083310833
}
10834-
need_lnd_workaround
10834+
10835+
(responses.implicit_splice_locked, need_lnd_workaround)
1083510836
} else {
1083610837
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1083710838
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -10878,6 +10879,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1087810879
if let Some(channel_ready_msg) = need_lnd_workaround {
1087910880
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1088010881
}
10882+
10883+
#[cfg(not(splicing))]
10884+
let _ = implicit_splice_locked;
10885+
#[cfg(splicing)]
10886+
if let Some(splice_locked) = implicit_splice_locked {
10887+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
10888+
return Ok(NotifyOption::DoPersist);
10889+
}
10890+
1088110891
Ok(NotifyOption::SkipPersistHandleEvents)
1088210892
}
1088310893

0 commit comments

Comments
 (0)