Skip to content

Commit 7797824

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 7797824

File tree

2 files changed

+58
-8
lines changed

2 files changed

+58
-8
lines changed

lightning/src/ln/channel.rs

Lines changed: 56 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,13 @@ where
94039403
false
94049404
}
94059405

9406+
/// Returns true if thier channel_ready has been received
9407+
#[cfg(splicing)]
9408+
pub fn is_their_channel_ready(&self) -> bool {
9409+
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY))
9410+
|| matches!(self.context.channel_state, ChannelState::ChannelReady(_))
9411+
}
9412+
94069413
/// Returns true if our channel_ready has been sent
94079414
pub fn is_our_channel_ready(&self) -> bool {
94089415
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::OUR_CHANNEL_READY))
@@ -10150,10 +10157,52 @@ where
1015010157
}
1015110158
}
1015210159

10160+
#[cfg(splicing)]
10161+
fn maybe_get_your_last_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10162+
if !features.supports_splicing() {
10163+
return None;
10164+
}
10165+
10166+
self.pending_splice
10167+
.as_ref()
10168+
.and_then(|pending_splice| pending_splice.received_funding_txid)
10169+
.or_else(|| {
10170+
self.is_their_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10171+
})
10172+
}
10173+
#[cfg(not(splicing))]
10174+
fn maybe_get_your_last_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10175+
None
10176+
}
10177+
10178+
#[cfg(splicing)]
10179+
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10180+
if !features.supports_splicing() {
10181+
return None;
10182+
}
10183+
10184+
self.pending_splice
10185+
.as_ref()
10186+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10187+
.or_else(|| {
10188+
self.is_our_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10189+
})
10190+
}
10191+
10192+
#[cfg(not(splicing))]
10193+
fn maybe_get_my_current_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10194+
None
10195+
}
10196+
1015310197
/// May panic if called on a channel that wasn't immediately-previously
1015410198
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
1015510199
#[rustfmt::skip]
10156-
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
10200+
fn get_channel_reestablish<L: Deref>(
10201+
&mut self, features: &InitFeatures, logger: &L,
10202+
) -> msgs::ChannelReestablish
10203+
where
10204+
L::Target: Logger,
10205+
{
1015710206
assert!(self.context.channel_state.is_peer_disconnected());
1015810207
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1015910208
// This is generally the first function which gets called on any given channel once we're
@@ -10201,8 +10250,8 @@ where
1020110250
your_last_per_commitment_secret: remote_last_secret,
1020210251
my_current_per_commitment_point: dummy_pubkey,
1020310252
next_funding_txid: self.maybe_get_next_funding_txid(),
10204-
your_last_funding_locked_txid: None,
10205-
my_current_funding_locked_txid: None,
10253+
your_last_funding_locked_txid: self.maybe_get_your_last_funding_locked_txid(features),
10254+
my_current_funding_locked_txid: self.maybe_get_my_current_funding_locked_txid(features),
1020610255
}
1020710256
}
1020810257

@@ -13690,15 +13739,15 @@ mod tests {
1369013739
// Now disconnect the two nodes and check that the commitment point in
1369113740
// Node B's channel_reestablish message is sane.
1369213741
assert!(node_b_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
13693-
let msg = node_b_chan.get_channel_reestablish(&&logger);
13742+
let msg = node_b_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1369413743
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1369513744
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1369613745
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);
1369713746

1369813747
// Check that the commitment point in Node A's channel_reestablish message
1369913748
// is sane.
1370013749
assert!(node_a_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
13701-
let msg = node_a_chan.get_channel_reestablish(&&logger);
13750+
let msg = node_a_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1370213751
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1370313752
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1370413753
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)