Skip to content

Commit c9260ee

Browse files
authored
Merge pull request #4654 from wpaulino/splice-locked-reestablish-fixes
`splice_locked` + `channel_reestablish` bug fixes
2 parents 1d13f39 + c58cba3 commit c9260ee

4 files changed

Lines changed: 421 additions & 14 deletions

File tree

lightning/src/ln/channel.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10756,6 +10756,9 @@ where
1075610756
let required_revoke = if msg.next_remote_commitment_number == our_commitment_transaction {
1075710757
// Remote isn't waiting on any RevokeAndACK from us!
1075810758
// Note that if we need to repeat our ChannelReady we'll do that in the next if block.
10759+
// If a stale ChannelManager replayed a completed update, the monitor-pending state may
10760+
// still think we owe one; the reestablish proof is authoritative here.
10761+
self.context.monitor_pending_revoke_and_ack = false;
1075910762
None
1076010763
} else if msg.next_remote_commitment_number + 1 == our_commitment_transaction {
1076110764
if self.context.channel_state.is_monitor_update_in_progress() {
@@ -10826,9 +10829,25 @@ where
1082610829
channel_id: self.context.channel_id,
1082710830
splice_txid,
1082810831
})
10832+
}).or_else(|| {
10833+
// If a splice confirms after we've sent `channel_reestablish` but before we've received
10834+
// theirs, we may promote the splice and clear `pending_splice`. We still need to send
10835+
// `splice_locked` after reestablishing as it was not included in our
10836+
// `channel_reestablish`.
10837+
let current_funding_txid = self.funding.get_funding_txid()?;
10838+
(self.pending_splice.is_none()
10839+
&& self.funding.channel_transaction_parameters.splice_parent_funding_txid.is_some()
10840+
&& Some(current_funding_txid) != funding_locked_txid_sent_in_reestablish)
10841+
.then(|| msgs::SpliceLocked {
10842+
channel_id: self.context.channel_id,
10843+
splice_txid: current_funding_txid,
10844+
})
1082910845
});
1083010846

1083110847
if msg.next_local_commitment_number == next_counterparty_commitment_number {
10848+
// If a stale ChannelManager replayed a completed update, the monitor-pending state may
10849+
// still think we owe one.
10850+
self.context.monitor_pending_commitment_signed = false;
1083210851
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
1083310852
log_debug!(logger, "Reconnected with only lost outbound RAA");
1083410853
} else {

lightning/src/ln/channelmanager.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11052,6 +11052,19 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1105211052
}
1105311053
}
1105411054

11055+
if let Some(funding_tx_signed) = funding_tx_signed.as_ref() {
11056+
// These [`FundingTxSigned`] fields are only expected as a result of calling
11057+
// [`ChannelManager::funding_transaction_signed`].
11058+
debug_assert!(funding_tx_signed.commitment_signed.is_none());
11059+
debug_assert!(funding_tx_signed.counterparty_initial_commitment_signed_result.is_none());
11060+
}
11061+
if let Some(msg) = funding_tx_signed.as_mut().and_then(|v| v.splice_locked.take()) {
11062+
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
11063+
node_id: counterparty_node_id,
11064+
msg,
11065+
});
11066+
}
11067+
1105511068
macro_rules! handle_cs { () => {
1105611069
if let Some(update) = commitment_update {
1105711070
pending_msg_events.push(MessageSendEvent::UpdateHTLCs {
@@ -11080,12 +11093,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1108011093
},
1108111094
}
1108211095

11083-
if let Some(funding_tx_signed) = funding_tx_signed.as_ref() {
11084-
// These [`FundingTxSigned`] fields are only expected as a result of calling
11085-
// [`ChannelManager::funding_transaction_signed`].
11086-
debug_assert!(funding_tx_signed.commitment_signed.is_none());
11087-
debug_assert!(funding_tx_signed.counterparty_initial_commitment_signed_result.is_none());
11088-
}
1108911096
if let Some(msg) = funding_tx_signed.as_mut().and_then(|v| v.tx_signatures.take()) {
1109011097
pending_msg_events.push(MessageSendEvent::SendTxSignatures {
1109111098
node_id: counterparty_node_id,
@@ -11111,13 +11118,6 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1111111118
});
1111211119
}
1111311120
}
11114-
11115-
if let Some(msg) = funding_tx_signed.as_mut().and_then(|v| v.splice_locked.take()) {
11116-
pending_msg_events.push(MessageSendEvent::SendSpliceLocked {
11117-
node_id: counterparty_node_id,
11118-
msg,
11119-
});
11120-
}
1112111121
} else if let Some(msg) = channel_ready {
1112211122
self.send_channel_ready(pending_msg_events, channel, msg);
1112311123
}

lightning/src/ln/functional_test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ pub fn get_updates_and_revoke<CM: AChannelManager, H: NodeHolder<CM = CM>>(
10231023
macro_rules! get_event_msg {
10241024
($node: expr, $event_type: path, $node_id: expr) => {{
10251025
let events = $node.node.get_and_clear_pending_msg_events();
1026-
assert_eq!(events.len(), 1);
1026+
assert_eq!(events.len(), 1, "{events:?}");
10271027
match events[0] {
10281028
$event_type { ref node_id, ref msg } => {
10291029
assert_eq!(*node_id, $node_id);

0 commit comments

Comments
 (0)