Skip to content

Commit eb33983

Browse files
jkczyzAnyitechs
authored andcommitted
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 a35392f commit eb33983

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
@@ -1220,6 +1220,7 @@ pub(super) struct ReestablishResponses {
12201220
pub shutdown_msg: Option<msgs::Shutdown>,
12211221
pub tx_signatures: Option<msgs::TxSignatures>,
12221222
pub tx_abort: Option<msgs::TxAbort>,
1223+
pub inferred_splice_locked: Option<msgs::SpliceLocked>,
12231224
}
12241225

12251226
/// The first message we send to our peer after connection
@@ -9328,6 +9329,7 @@ where
93289329
shutdown_msg, announcement_sigs,
93299330
tx_signatures,
93309331
tx_abort: None,
9332+
inferred_splice_locked: None,
93319333
});
93329334
}
93339335

@@ -9340,6 +9342,7 @@ where
93409342
shutdown_msg, announcement_sigs,
93419343
tx_signatures,
93429344
tx_abort,
9345+
inferred_splice_locked: None,
93439346
});
93449347
}
93459348

@@ -9375,6 +9378,30 @@ where
93759378
self.get_channel_ready(logger)
93769379
} else { None };
93779380

9381+
// A receiving node:
9382+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
9383+
// those splice transactions, for which it hasn't received `splice_locked` yet:
9384+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
9385+
// for this `txid`.
9386+
#[cfg(splicing)]
9387+
let inferred_splice_locked = msg.my_current_funding_locked.as_ref().and_then(|funding_locked| {
9388+
self.pending_funding
9389+
.iter()
9390+
.find(|funding| funding.get_funding_txid() == Some(funding_locked.txid))
9391+
.and_then(|_| {
9392+
self.pending_splice.as_ref().and_then(|pending_splice| {
9393+
(Some(funding_locked.txid) != pending_splice.received_funding_txid)
9394+
.then(|| funding_locked.txid)
9395+
})
9396+
})
9397+
.map(|splice_txid| msgs::SpliceLocked {
9398+
channel_id: self.context.channel_id,
9399+
splice_txid,
9400+
})
9401+
});
9402+
#[cfg(not(splicing))]
9403+
let inferred_splice_locked = None;
9404+
93789405
if msg.next_local_commitment_number == next_counterparty_commitment_number {
93799406
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
93809407
log_debug!(logger, "Reconnected channel {} with only lost outbound RAA", &self.context.channel_id());
@@ -9392,6 +9419,7 @@ where
93929419
commitment_order: self.context.resend_order.clone(),
93939420
tx_signatures,
93949421
tx_abort,
9422+
inferred_splice_locked,
93959423
})
93969424
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
93979425
debug_assert!(commitment_update.is_none());
@@ -9416,6 +9444,7 @@ where
94169444
commitment_order: self.context.resend_order.clone(),
94179445
tx_signatures: None,
94189446
tx_abort,
9447+
inferred_splice_locked,
94199448
})
94209449
} else {
94219450
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -9442,6 +9471,7 @@ where
94429471
commitment_order: self.context.resend_order.clone(),
94439472
tx_signatures: None,
94449473
tx_abort,
9474+
inferred_splice_locked,
94459475
})
94469476
}
94479477
} 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
@@ -11026,7 +11026,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1102611026

1102711027
#[rustfmt::skip]
1102811028
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
11029-
let need_lnd_workaround = {
11029+
let (inferred_splice_locked, need_lnd_workaround) = {
1103011030
let per_peer_state = self.per_peer_state.read().unwrap();
1103111031

1103211032
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -11084,7 +11084,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1108411084
if let Some(upd) = channel_update {
1108511085
peer_state.pending_msg_events.push(upd);
1108611086
}
11087-
need_lnd_workaround
11087+
11088+
(responses.inferred_splice_locked, need_lnd_workaround)
1108811089
} else {
1108911090
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1109011091
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -11130,6 +11131,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1113011131
if let Some(channel_ready_msg) = need_lnd_workaround {
1113111132
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1113211133
}
11134+
11135+
#[cfg(not(splicing))]
11136+
let _ = inferred_splice_locked;
11137+
#[cfg(splicing)]
11138+
if let Some(splice_locked) = inferred_splice_locked {
11139+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
11140+
return Ok(NotifyOption::DoPersist);
11141+
}
11142+
1113311143
Ok(NotifyOption::SkipPersistHandleEvents)
1113411144
}
1113511145

0 commit comments

Comments
 (0)