Skip to content

Commit 231b24e

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 4306beb commit 231b24e

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
@@ -8734,6 +8735,7 @@ where
87348735
shutdown_msg, announcement_sigs,
87358736
tx_signatures: None,
87368737
tx_abort: None,
8738+
implicit_splice_locked: None,
87378739
});
87388740
}
87398741

@@ -8745,6 +8747,7 @@ where
87458747
shutdown_msg, announcement_sigs,
87468748
tx_signatures: None,
87478749
tx_abort: None,
8750+
implicit_splice_locked: None,
87488751
});
87498752
}
87508753

@@ -8780,6 +8783,30 @@ where
87808783
self.get_channel_ready(logger)
87818784
} else { None };
87828785

8786+
// A receiving node:
8787+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8788+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8789+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8790+
// for this `txid`.
8791+
#[cfg(splicing)]
8792+
let implicit_splice_locked = msg.my_current_funding_locked.as_ref().and_then(|funding_locked| {
8793+
self.pending_funding
8794+
.iter()
8795+
.find(|funding| funding.get_funding_txid() == Some(funding_locked.txid))
8796+
.and_then(|_| {
8797+
self.pending_splice.as_ref().and_then(|pending_splice| {
8798+
(Some(funding_locked.txid) != pending_splice.received_funding_txid)
8799+
.then(|| funding_locked.txid)
8800+
})
8801+
})
8802+
.map(|splice_txid| msgs::SpliceLocked {
8803+
channel_id: self.context.channel_id,
8804+
splice_txid,
8805+
})
8806+
});
8807+
#[cfg(not(splicing))]
8808+
let implicit_splice_locked = None;
8809+
87838810
let mut commitment_update = None;
87848811
let mut tx_signatures = None;
87858812
let mut tx_abort = None;
@@ -8888,6 +8915,7 @@ where
88888915
order: self.context.resend_order.clone(),
88898916
tx_signatures,
88908917
tx_abort,
8918+
implicit_splice_locked,
88918919
})
88928920
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
88938921
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8909,6 +8937,7 @@ where
89098937
order: self.context.resend_order.clone(),
89108938
tx_signatures,
89118939
tx_abort,
8940+
implicit_splice_locked,
89128941
})
89138942
} else {
89148943
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8933,6 +8962,7 @@ where
89338962
order: self.context.resend_order.clone(),
89348963
tx_signatures,
89358964
tx_abort,
8965+
implicit_splice_locked,
89368966
})
89378967
}
89388968
} 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
@@ -11002,7 +11002,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1100211002

1100311003
#[rustfmt::skip]
1100411004
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
11005-
let need_lnd_workaround = {
11005+
let (implicit_splice_locked, need_lnd_workaround) = {
1100611006
let per_peer_state = self.per_peer_state.read().unwrap();
1100711007

1100811008
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -11053,7 +11053,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1105311053
if let Some(upd) = channel_update {
1105411054
peer_state.pending_msg_events.push(upd);
1105511055
}
11056-
need_lnd_workaround
11056+
11057+
(responses.implicit_splice_locked, need_lnd_workaround)
1105711058
} else {
1105811059
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1105911060
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -11099,6 +11100,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1109911100
if let Some(channel_ready_msg) = need_lnd_workaround {
1110011101
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1110111102
}
11103+
11104+
#[cfg(not(splicing))]
11105+
let _ = implicit_splice_locked;
11106+
#[cfg(splicing)]
11107+
if let Some(splice_locked) = implicit_splice_locked {
11108+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
11109+
return Ok(NotifyOption::DoPersist);
11110+
}
11111+
1110211112
Ok(NotifyOption::SkipPersistHandleEvents)
1110311113
}
1110411114

0 commit comments

Comments
 (0)