Skip to content

Commit d4ddbc4

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 7050856 commit d4ddbc4

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
@@ -9291,6 +9292,7 @@ where
92919292
shutdown_msg, announcement_sigs,
92929293
tx_signatures,
92939294
tx_abort: None,
9295+
inferred_splice_locked: None,
92949296
});
92959297
}
92969298

@@ -9303,6 +9305,7 @@ where
93039305
shutdown_msg, announcement_sigs,
93049306
tx_signatures,
93059307
tx_abort,
9308+
inferred_splice_locked: None,
93069309
});
93079310
}
93089311

@@ -9338,6 +9341,30 @@ where
93389341
self.get_channel_ready(logger)
93399342
} else { None };
93409343

9344+
// A receiving node:
9345+
// - if splice transactions are pending and `my_current_funding_locked` matches one of
9346+
// those splice transactions, for which it hasn't received `splice_locked` yet:
9347+
// - MUST process `my_current_funding_locked` as if it was receiving `splice_locked`
9348+
// for this `txid`.
9349+
#[cfg(splicing)]
9350+
let inferred_splice_locked = msg.my_current_funding_locked.as_ref().and_then(|funding_locked| {
9351+
self.pending_funding
9352+
.iter()
9353+
.find(|funding| funding.get_funding_txid() == Some(funding_locked.txid))
9354+
.and_then(|_| {
9355+
self.pending_splice.as_ref().and_then(|pending_splice| {
9356+
(Some(funding_locked.txid) != pending_splice.received_funding_txid)
9357+
.then(|| funding_locked.txid)
9358+
})
9359+
})
9360+
.map(|splice_txid| msgs::SpliceLocked {
9361+
channel_id: self.context.channel_id,
9362+
splice_txid,
9363+
})
9364+
});
9365+
#[cfg(not(splicing))]
9366+
let inferred_splice_locked = None;
9367+
93419368
if msg.next_local_commitment_number == next_counterparty_commitment_number {
93429369
if required_revoke.is_some() || self.context.signer_pending_revoke_and_ack {
93439370
log_debug!(logger, "Reconnected channel {} with only lost outbound RAA", &self.context.channel_id());
@@ -9355,6 +9382,7 @@ where
93559382
commitment_order: self.context.resend_order.clone(),
93569383
tx_signatures,
93579384
tx_abort,
9385+
inferred_splice_locked,
93589386
})
93599387
} else if msg.next_local_commitment_number == next_counterparty_commitment_number - 1 {
93609388
debug_assert!(commitment_update.is_none());
@@ -9379,6 +9407,7 @@ where
93799407
commitment_order: self.context.resend_order.clone(),
93809408
tx_signatures: None,
93819409
tx_abort,
9410+
inferred_splice_locked,
93829411
})
93839412
} else {
93849413
let commitment_update = if self.context.resend_order == RAACommitmentOrder::RevokeAndACKFirst
@@ -9405,6 +9434,7 @@ where
94059434
commitment_order: self.context.resend_order.clone(),
94069435
tx_signatures: None,
94079436
tx_abort,
9437+
inferred_splice_locked,
94089438
})
94099439
}
94109440
} 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
@@ -11034,7 +11034,7 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1103411034

1103511035
#[rustfmt::skip]
1103611036
fn internal_channel_reestablish(&self, counterparty_node_id: &PublicKey, msg: &msgs::ChannelReestablish) -> Result<NotifyOption, MsgHandleErrInternal> {
11037-
let need_lnd_workaround = {
11037+
let (inferred_splice_locked, need_lnd_workaround) = {
1103811038
let per_peer_state = self.per_peer_state.read().unwrap();
1103911039

1104011040
let peer_state_mutex = per_peer_state.get(counterparty_node_id)
@@ -11086,7 +11086,8 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1108611086
if let Some(upd) = channel_update {
1108711087
peer_state.pending_msg_events.push(upd);
1108811088
}
11089-
need_lnd_workaround
11089+
11090+
(responses.inferred_splice_locked, need_lnd_workaround)
1109011091
} else {
1109111092
return try_channel_entry!(self, peer_state, Err(ChannelError::close(
1109211093
"Got a channel_reestablish message for an unfunded channel!".into())), chan_entry);
@@ -11132,6 +11133,15 @@ This indicates a bug inside LDK. Please report this error at https://github.com/
1113211133
if let Some(channel_ready_msg) = need_lnd_workaround {
1113311134
self.internal_channel_ready(counterparty_node_id, &channel_ready_msg)?;
1113411135
}
11136+
11137+
#[cfg(not(splicing))]
11138+
let _ = inferred_splice_locked;
11139+
#[cfg(splicing)]
11140+
if let Some(splice_locked) = inferred_splice_locked {
11141+
self.internal_splice_locked(counterparty_node_id, &splice_locked)?;
11142+
return Ok(NotifyOption::DoPersist);
11143+
}
11144+
1113511145
Ok(NotifyOption::SkipPersistHandleEvents)
1113611146
}
1113711147

0 commit comments

Comments
 (0)