Skip to content

Commit fa4c9c9

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 99affd3 commit fa4c9c9

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

9384+
/// Returns true if their channel_ready has been received
9385+
#[cfg(splicing)]
9386+
pub fn is_their_channel_ready(&self) -> bool {
9387+
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::THEIR_CHANNEL_READY))
9388+
|| matches!(self.context.channel_state, ChannelState::ChannelReady(_))
9389+
}
9390+
93849391
/// Returns true if our channel_ready has been sent
93859392
pub fn is_our_channel_ready(&self) -> bool {
93869393
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::OUR_CHANNEL_READY))
@@ -10128,10 +10135,52 @@ where
1012810135
}
1012910136
}
1013010137

10138+
#[cfg(splicing)]
10139+
fn maybe_get_your_last_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10140+
if !features.supports_splicing() {
10141+
return None;
10142+
}
10143+
10144+
self.pending_splice
10145+
.as_ref()
10146+
.and_then(|pending_splice| pending_splice.received_funding_txid)
10147+
.or_else(|| {
10148+
self.is_their_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10149+
})
10150+
}
10151+
#[cfg(not(splicing))]
10152+
fn maybe_get_your_last_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10153+
None
10154+
}
10155+
10156+
#[cfg(splicing)]
10157+
fn maybe_get_my_current_funding_locked_txid(&self, features: &InitFeatures) -> Option<Txid> {
10158+
if !features.supports_splicing() {
10159+
return None;
10160+
}
10161+
10162+
self.pending_splice
10163+
.as_ref()
10164+
.and_then(|pending_splice| pending_splice.sent_funding_txid)
10165+
.or_else(|| {
10166+
self.is_our_channel_ready().then(|| self.funding.get_funding_txid()).flatten()
10167+
})
10168+
}
10169+
10170+
#[cfg(not(splicing))]
10171+
fn maybe_get_my_current_funding_locked_txid(&self, _features: &InitFeatures) -> Option<Txid> {
10172+
None
10173+
}
10174+
1013110175
/// May panic if called on a channel that wasn't immediately-previously
1013210176
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
1013310177
#[rustfmt::skip]
10134-
fn get_channel_reestablish<L: Deref>(&mut self, logger: &L) -> msgs::ChannelReestablish where L::Target: Logger {
10178+
fn get_channel_reestablish<L: Deref>(
10179+
&mut self, their_features: &InitFeatures, logger: &L,
10180+
) -> msgs::ChannelReestablish
10181+
where
10182+
L::Target: Logger,
10183+
{
1013510184
assert!(self.context.channel_state.is_peer_disconnected());
1013610185
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
1013710186
// This is generally the first function which gets called on any given channel once we're
@@ -10179,8 +10228,8 @@ where
1017910228
your_last_per_commitment_secret: remote_last_secret,
1018010229
my_current_per_commitment_point: dummy_pubkey,
1018110230
next_funding_txid: self.maybe_get_next_funding_txid(),
10182-
your_last_funding_locked_txid: None,
10183-
my_current_funding_locked_txid: None,
10231+
your_last_funding_locked_txid: self.maybe_get_your_last_funding_locked_txid(their_features),
10232+
my_current_funding_locked_txid: self.maybe_get_my_current_funding_locked_txid(their_features),
1018410233
}
1018510234
}
1018610235

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

1369913748
// Check that the commitment point in Node A's channel_reestablish message
1370013749
// is sane.
1370113750
assert!(node_a_chan.remove_uncommitted_htlcs_and_mark_paused(&&logger).is_ok());
13702-
let msg = node_a_chan.get_channel_reestablish(&&logger);
13751+
let msg = node_a_chan.get_channel_reestablish(&channelmanager::provided_init_features(&config), &&logger);
1370313752
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
1370413753
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
1370513754
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
@@ -12007,8 +12007,9 @@ where
1200712007
}
1200812008

1200912009
for (_, chan) in peer_state.channel_by_id.iter_mut() {
12010+
let features = &peer_state.latest_features;
1201012011
let logger = WithChannelContext::from(&self.logger, &chan.context(), None);
12011-
match chan.peer_connected_get_handshake(self.chain_hash, &&logger) {
12012+
match chan.peer_connected_get_handshake(self.chain_hash, features, &&logger) {
1201212013
ReconnectionMsg::Reestablish(msg) =>
1201312014
pending_msg_events.push(MessageSendEvent::SendChannelReestablish {
1201412015
node_id: chan.context().get_counterparty_node_id(),

0 commit comments

Comments
 (0)