Skip to content

Commit 661413f

Browse files
committed
Set funding_locked_txid TLVs in channel_reestablish
The previous commit extended the channel_reestablish message with your_last_funding_locked_txid and my_current_funding_locked_txid for use as described there. This commit sets those fields to the funding txid most recently sent/received accordingly.
1 parent 39ae79e commit 661413f

File tree

2 files changed

+46
-8
lines changed

2 files changed

+46
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,12 +1662,12 @@ where
16621662
/// send our peer to begin the channel reconnection process.
16631663
#[rustfmt::skip]
16641664
pub fn peer_connected_get_handshake<L: Deref>(
1665-
&mut self, chain_hash: ChainHash, logger: &L,
1665+
&mut self, chain_hash: ChainHash, features: &InitFeatures, logger: &L,
16661666
) -> ReconnectionMsg where L::Target: Logger {
16671667
match &mut self.phase {
16681668
ChannelPhase::Undefined => unreachable!(),
16691669
ChannelPhase::Funded(chan) =>
1670-
ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
1670+
ReconnectionMsg::Reestablish(chan.get_channel_reestablish(features, logger)),
16711671
ChannelPhase::UnfundedOutboundV1(chan) => {
16721672
chan.get_open_channel(chain_hash, logger)
16731673
.map(|msg| ReconnectionMsg::Open(OpenChannelMessage::V1(msg)))
@@ -9403,6 +9403,12 @@ where
94039403
false
94049404
}
94059405

9406+
/// Returns true if thier channel_ready has been received
9407+
pub fn is_their_channel_ready(&self) -> bool {
9408+
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY))
9409+
|| matches!(self.context.channel_state, ChannelState::ChannelReady(_))
9410+
}
9411+
94069412
/// Returns true if our channel_ready has been sent
94079413
pub fn is_our_channel_ready(&self) -> bool {
94089414
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::OUR_CHANNEL_READY))
@@ -10150,10 +10156,41 @@ where
1015010156
}
1015110157
}
1015210158

10159+
fn maybe_get_your_last_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10160+
if !features.supports_splicing() {
10161+
return None;
10162+
}
10163+
10164+
self.pending_splice
10165+
.as_ref()
10166+
.and_then(|pending_splice| pending_splice.received_funding_txid)
10167+
.or_else(|| {
10168+
self.is_their_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10169+
})
10170+
}
10171+
10172+
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10173+
if !features.supports_splicing() {
10174+
return None;
10175+
}
10176+
10177+
self.pending_splice
10178+
.as_ref()
10179+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10180+
.or_else(|| {
10181+
self.is_our_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10182+
})
10183+
}
10184+
1015310185
/// May panic if called on a channel that wasn't immediately-previously
1015410186
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
1015510187
#[rustfmt::skip]
10156-
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
10188+
fn get_channel_reestablish<L: Deref>(
10189+
&mut self, features: &InitFeatures, logger: &L,
10190+
) -> msgs::ChannelReestablish
10191+
where
10192+
L::Target: Logger,
10193+
{
1015710194
assert!(self.context.channel_state.is_peer_disconnected());
1015810195
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1015910196
// This is generally the first function which gets called on any given channel once we're
@@ -10201,8 +10238,8 @@ where
1020110238
your_last_per_commitment_secret: remote_last_secret,
1020210239
my_current_per_commitment_point: dummy_pubkey,
1020310240
next_funding_txid: self.maybe_get_next_funding_txid(),
10204-
your_last_funding_locked_txid: None,
10205-
my_current_funding_locked_txid: None,
10241+
your_last_funding_locked_txid: self.maybe_get_your_last_funding_locked_txid(features),
10242+
my_current_funding_locked_txid: self.maybe_get_my_current_funding_locked_txid(features),
1020610243
}
1020710244
}
1020810245

@@ -13690,15 +13727,15 @@ mod tests {
1369013727
// Now disconnect the two nodes and check that the commitment point in
1369113728
// Node B's channel_reestablish message is sane.
1369213729
assert!(node_b_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
13693-
let msg = node_b_chan.get_channel_reestablish(&&logger);
13730+
let msg = node_b_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1369413731
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1369513732
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1369613733
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);
1369713734

1369813735
// Check that the commitment point in Node A's channel_reestablish message
1369913736
// is sane.
1370013737
assert!(node_a_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
13701-
let msg = node_a_chan.get_channel_reestablish(&&logger);
13738+
let msg = node_a_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1370213739
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1370313740
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1370413741
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11937,8 +11937,9 @@ where
1193711937
}
1193811938

1193911939
for (_, chan) in peer_state.channel_by_id.iter_mut() {
11940+
let features = &peer_state.latest_features;
1194011941
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
11941-
match chan.peer_connected_get_handshake(self.chain_hash, &&logger) {
11942+
match chan.peer_connected_get_handshake(self.chain_hash, features, &&logger) {
1194211943
ReconnectionMsg::Reestablish(msg) =>
1194311944
pending_msg_events.push(MessageSendEvent::SendChannelReestablish {
1194411945
node_id: chan.context().get_counterparty_node_id(),

0 commit comments

Comments
 (0)