Skip to content

Commit e2ea3bf

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 cc1f3b9 commit e2ea3bf

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

12221223
/// The first message we send to our peer after connection
@@ -8368,6 +8369,7 @@ where
83688369
tx_signatures: None,
83698370
tx_abort: None,
83708371
splice_locked: None,
8372+
implicit_splice_locked: None,
83718373
});
83728374
}
83738375

@@ -8380,6 +8382,7 @@ where
83808382
tx_signatures: None,
83818383
tx_abort: None,
83828384
splice_locked: None,
8385+
implicit_splice_locked: None,
83838386
});
83848387
}
83858388

@@ -8491,6 +8494,30 @@ where
84918494
splice_txid,
84928495
});
84938496

8497+
// A receiving node:
8498+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
8499+
// those splice transactions, for which it hasn't received `splice_locked` yet:
8500+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
8501+
// for this `txid`.
8502+
#[cfg(splicing)]
8503+
let implicit_splice_locked = msg.my_current_funding_locked_txid.and_then(|funding_txid| {
8504+
self.pending_funding
8505+
.iter()
8506+
.find(|funding| funding.get_funding_txid() == Some(funding_txid))
8507+
.and_then(|_| {
8508+
self.pending_splice.as_ref().and_then(|pending_splice| {
8509+
(Some(funding_txid) != pending_splice.received_funding_txid)
8510+
.then(|| funding_txid)
8511+
})
8512+
})
8513+
.map(|splice_txid| msgs::SpliceLocked {
8514+
channel_id: self.context.channel_id,
8515+
splice_txid,
8516+
})
8517+
});
8518+
#[cfg(not(splicing))]
8519+
let implicit_splice_locked = None;
8520+
84948521
let mut commitment_update = None;
84958522
let mut tx_signatures = None;
84968523
let mut tx_abort = None;
@@ -8598,6 +8625,7 @@ where
85988625
tx_signatures,
85998626
tx_abort,
86008627
splice_locked,
8628+
implicit_splice_locked,
86018629
})
86028630
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
86038631
// We've made an update so we must have exchanged `tx_signatures`, implying that
@@ -8620,6 +8648,7 @@ where
86208648
tx_signatures,
86218649
tx_abort,
86228650
splice_locked,
8651+
implicit_splice_locked,
86238652
})
86248653
} else {
86258654
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -8645,6 +8674,7 @@ where
86458674
tx_signatures,
86468675
tx_abort,
86478676
splice_locked,
8677+
implicit_splice_locked,
86488678
})
86498679
}
86508680
} 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
@@ -10046,7 +10046,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1004610046

1004710047
#[rustfmt::skip]
1004810048
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
10049-
let need_lnd_workaround = {
10049+
let (implicit_splice_locked, need_lnd_workaround) = {
1005010050
let per_peer_state = self.per_peer_state.read().unwrap();
1005110051

1005210052
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -10099,7 +10099,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1009910099
if let Some(upd) = channel_update {
1010010100
peer_state.pending_msg_events.push(upd);
1010110101
}
10102-
need_lnd_workaround
10102+
10103+
(responses.implicit_splice_locked, need_lnd_workaround)
1010310104
} else {
1010410105
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1010510106
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -10146,6 +10147,14 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1014610147
if let Some(channel_ready_msg) = need_lnd_workaround {
1014710148
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1014810149
}
10150+
10151+
#[cfg(not(splicing))]
10152+
let _ = implicit_splice_locked;
10153+
#[cfg(splicing)]
10154+
if let Some(splice_locked) = implicit_splice_locked {
10155+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
10156+
}
10157+
1014910158
Ok(NotifyOption::SkipPersistHandleEvents)
1015010159
}
1015110160

0 commit comments

Comments
 (0)