Skip to content

Commit 221fd75

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 e39a86f commit 221fd75

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
@@ -1664,12 +1664,12 @@ where
16641664
/// send our peer to begin the channel reconnection process.
16651665
#[rustfmt::skip]
16661666
pub fn peer_connected_get_handshake<L: Deref>(
1667-
&mut self, chain_hash: ChainHash, logger: &L,
1667+
&mut self, chain_hash: ChainHash, their_features: &InitFeatures, logger: &L,
16681668
) -> ReconnectionMsg where L::Target: Logger {
16691669
match &mut self.phase {
16701670
ChannelPhase::Undefined => unreachable!(),
16711671
ChannelPhase::Funded(chan) =>
1672-
ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
1672+
ReconnectionMsg::Reestablish(chan.get_channel_reestablish(their_features, logger)),
16731673
ChannelPhase::UnfundedOutboundV1(chan) => {
16741674
chan.get_open_channel(chain_hash, logger)
16751675
.map(|msg| ReconnectionMsg::Open(OpenChannelMessage::V1(msg)))
@@ -9779,6 +9779,13 @@ where
97799779
self.context.latest_inbound_scid_alias.or(self.funding.get_short_channel_id())
97809780
}
97819781

9782+
/// Returns true if their channel_ready has been received
9783+
#[cfg(splicing)]
9784+
pub fn is_their_channel_ready(&self) -> bool {
9785+
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY))
9786+
|| matches!(self.context.channel_state, ChannelState::ChannelReady(_))
9787+
}
9788+
97829789
/// Returns true if our channel_ready has been sent
97839790
pub fn is_our_channel_ready(&self) -> bool {
97849791
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::OUR_CHANNEL_READY))
@@ -10553,10 +10560,52 @@ where
1055310560
}
1055410561
}
1055510562

10563+
#[cfg(splicing)]
10564+
fn maybe_get_your_last_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10565+
if !features.supports_splicing() {
10566+
return None;
10567+
}
10568+
10569+
self.pending_splice
10570+
.as_ref()
10571+
.and_then(|pending_splice| pending_splice.received_funding_txid)
10572+
.or_else(|| {
10573+
self.is_their_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10574+
})
10575+
}
10576+
#[cfg(not(splicing))]
10577+
fn maybe_get_your_last_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10578+
None
10579+
}
10580+
10581+
#[cfg(splicing)]
10582+
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10583+
if !features.supports_splicing() {
10584+
return None;
10585+
}
10586+
10587+
self.pending_splice
10588+
.as_ref()
10589+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10590+
.or_else(|| {
10591+
self.is_our_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10592+
})
10593+
}
10594+
10595+
#[cfg(not(splicing))]
10596+
fn maybe_get_my_current_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10597+
None
10598+
}
10599+
1055610600
/// May panic if called on a channel that wasn't immediately-previously
1055710601
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
1055810602
#[rustfmt::skip]
10559-
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
10603+
fn get_channel_reestablish<L: Deref>(
10604+
&mut self, their_features: &InitFeatures, logger: &L,
10605+
) -> msgs::ChannelReestablish
10606+
where
10607+
L::Target: Logger,
10608+
{
1056010609
assert!(self.context.channel_state.is_peer_disconnected());
1056110610
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1056210611
// This is generally the first function which gets called on any given channel once we're
@@ -10604,8 +10653,8 @@ where
1060410653
your_last_per_commitment_secret: remote_last_secret,
1060510654
my_current_per_commitment_point: dummy_pubkey,
1060610655
next_funding_txid: self.maybe_get_next_funding_txid(),
10607-
your_last_funding_locked_txid: None,
10608-
my_current_funding_locked_txid: None,
10656+
your_last_funding_locked_txid: self.maybe_get_your_last_funding_locked_txid(their_features),
10657+
my_current_funding_locked_txid: self.maybe_get_my_current_funding_locked_txid(their_features),
1060910658
}
1061010659
}
1061110660

@@ -14468,15 +14517,15 @@ mod tests {
1446814517
// Now disconnect the two nodes and check that the commitment point in
1446914518
// Node B's channel_reestablish message is sane.
1447014519
assert!(node_b_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
14471-
let msg = node_b_chan.get_channel_reestablish(&&logger);
14520+
let msg = node_b_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1447214521
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1447314522
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1447414523
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);
1447514524

1447614525
// Check that the commitment point in Node A's channel_reestablish message
1447714526
// is sane.
1447814527
assert!(node_a_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
14479-
let msg = node_a_chan.get_channel_reestablish(&&logger);
14528+
let msg = node_a_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1448014529
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1448114530
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1448214531
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
@@ -12870,8 +12870,9 @@ where
1287012870
}
1287112871

1287212872
for (_, chan) in peer_state.channel_by_id.iter_mut() {
12873+
let features = &peer_state.latest_features;
1287312874
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
12874-
match chan.peer_connected_get_handshake(self.chain_hash, &&logger) {
12875+
match chan.peer_connected_get_handshake(self.chain_hash, features, &&logger) {
1287512876
ReconnectionMsg::Reestablish(msg) =>
1287612877
pending_msg_events.push(MessageSendEvent::SendChannelReestablish {
1287712878
node_id: chan.context().get_counterparty_node_id(),

0 commit comments

Comments
 (0)