Skip to content

Commit 1657987

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 efe8314 commit 1657987

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)))
@@ -9767,6 +9767,13 @@ where
97679767
self.context.latest_inbound_scid_alias.or(self.funding.get_short_channel_id())
97689768
}
97699769

9770+
/// Returns true if their channel_ready has been received
9771+
#[cfg(splicing)]
9772+
pub fn is_their_channel_ready(&self) -> bool {
9773+
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY))
9774+
|| matches!(self.context.channel_state, ChannelState::ChannelReady(_))
9775+
}
9776+
97709777
/// Returns true if our channel_ready has been sent
97719778
pub fn is_our_channel_ready(&self) -> bool {
97729779
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::OUR_CHANNEL_READY))
@@ -10541,10 +10548,52 @@ where
1054110548
}
1054210549
}
1054310550

10551+
#[cfg(splicing)]
10552+
fn maybe_get_your_last_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10553+
if !features.supports_splicing() {
10554+
return None;
10555+
}
10556+
10557+
self.pending_splice
10558+
.as_ref()
10559+
.and_then(|pending_splice| pending_splice.received_funding_txid)
10560+
.or_else(|| {
10561+
self.is_their_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10562+
})
10563+
}
10564+
#[cfg(not(splicing))]
10565+
fn maybe_get_your_last_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10566+
None
10567+
}
10568+
10569+
#[cfg(splicing)]
10570+
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10571+
if !features.supports_splicing() {
10572+
return None;
10573+
}
10574+
10575+
self.pending_splice
10576+
.as_ref()
10577+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10578+
.or_else(|| {
10579+
self.is_our_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10580+
})
10581+
}
10582+
10583+
#[cfg(not(splicing))]
10584+
fn maybe_get_my_current_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10585+
None
10586+
}
10587+
1054410588
/// May panic if called on a channel that wasn't immediately-previously
1054510589
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
1054610590
#[rustfmt::skip]
10547-
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
10591+
fn get_channel_reestablish<L: Deref>(
10592+
&mut self, their_features: &InitFeatures, logger: &L,
10593+
) -> msgs::ChannelReestablish
10594+
where
10595+
L::Target: Logger,
10596+
{
1054810597
assert!(self.context.channel_state.is_peer_disconnected());
1054910598
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1055010599
// This is generally the first function which gets called on any given channel once we're
@@ -10592,8 +10641,8 @@ where
1059210641
your_last_per_commitment_secret: remote_last_secret,
1059310642
my_current_per_commitment_point: dummy_pubkey,
1059410643
next_funding_txid: self.maybe_get_next_funding_txid(),
10595-
your_last_funding_locked_txid: None,
10596-
my_current_funding_locked_txid: None,
10644+
your_last_funding_locked_txid: self.maybe_get_your_last_funding_locked_txid(their_features),
10645+
my_current_funding_locked_txid: self.maybe_get_my_current_funding_locked_txid(their_features),
1059710646
}
1059810647
}
1059910648

@@ -14460,15 +14509,15 @@ mod tests {
1446014509
// Now disconnect the two nodes and check that the commitment point in
1446114510
// Node B's channel_reestablish message is sane.
1446214511
assert!(node_b_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
14463-
let msg = node_b_chan.get_channel_reestablish(&&logger);
14512+
let msg = node_b_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1446414513
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1446514514
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1446614515
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);
1446714516

1446814517
// Check that the commitment point in Node A's channel_reestablish message
1446914518
// is sane.
1447014519
assert!(node_a_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
14471-
let msg = node_a_chan.get_channel_reestablish(&&logger);
14520+
let msg = node_a_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]);

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13062,8 +13062,9 @@ where
1306213062
}
1306313063

1306413064
for (_, chan) in peer_state.channel_by_id.iter_mut() {
13065+
let features = &peer_state.latest_features;
1306513066
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
13066-
match chan.peer_connected_get_handshake(self.chain_hash, &&logger) {
13067+
match chan.peer_connected_get_handshake(self.chain_hash, features, &&logger) {
1306713068
ReconnectionMsg::Reestablish(msg) =>
1306813069
pending_msg_events.push(MessageSendEvent::SendChannelReestablish {
1306913070
node_id: chan.context().get_counterparty_node_id(),

0 commit comments

Comments
 (0)