@@ -1664,12 +1664,12 @@ where
1664
1664
/// send our peer to begin the channel reconnection process.
1665
1665
#[rustfmt::skip]
1666
1666
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,
1668
1668
) -> ReconnectionMsg where L::Target: Logger {
1669
1669
match &mut self.phase {
1670
1670
ChannelPhase::Undefined => unreachable!(),
1671
1671
ChannelPhase::Funded(chan) =>
1672
- ReconnectionMsg::Reestablish(chan.get_channel_reestablish(logger)),
1672
+ ReconnectionMsg::Reestablish(chan.get_channel_reestablish(their_features, logger)),
1673
1673
ChannelPhase::UnfundedOutboundV1(chan) => {
1674
1674
chan.get_open_channel(chain_hash, logger)
1675
1675
.map(|msg| ReconnectionMsg::Open(OpenChannelMessage::V1(msg)))
@@ -9767,6 +9767,13 @@ where
9767
9767
self.context.latest_inbound_scid_alias.or(self.funding.get_short_channel_id())
9768
9768
}
9769
9769
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
+
9770
9777
/// Returns true if our channel_ready has been sent
9771
9778
pub fn is_our_channel_ready(&self) -> bool {
9772
9779
matches!(self.context.channel_state, ChannelState::AwaitingChannelReady(flags) if flags.is_set(AwaitingChannelReadyFlags::OUR_CHANNEL_READY))
@@ -10541,10 +10548,52 @@ where
10541
10548
}
10542
10549
}
10543
10550
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
+
10544
10588
/// May panic if called on a channel that wasn't immediately-previously
10545
10589
/// self.remove_uncommitted_htlcs_and_mark_paused()'d
10546
10590
#[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
+ {
10548
10597
assert!(self.context.channel_state.is_peer_disconnected());
10549
10598
assert_ne!(self.context.cur_counterparty_commitment_transaction_number, INITIAL_COMMITMENT_NUMBER);
10550
10599
// This is generally the first function which gets called on any given channel once we're
@@ -10592,8 +10641,8 @@ where
10592
10641
your_last_per_commitment_secret: remote_last_secret,
10593
10642
my_current_per_commitment_point: dummy_pubkey,
10594
10643
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) ,
10597
10646
}
10598
10647
}
10599
10648
@@ -14460,15 +14509,15 @@ mod tests {
14460
14509
// Now disconnect the two nodes and check that the commitment point in
14461
14510
// Node B's channel_reestablish message is sane.
14462
14511
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);
14464
14513
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
14465
14514
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
14466
14515
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);
14467
14516
14468
14517
// Check that the commitment point in Node A's channel_reestablish message
14469
14518
// is sane.
14470
14519
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);
14472
14521
assert_eq!(msg.next_local_commitment_number, 1); // now called next_commitment_number
14473
14522
assert_eq!(msg.next_remote_commitment_number, 0); // now called next_revocation_number
14474
14523
assert_eq!(msg.your_last_per_commitment_secret, [0; 32]);
0 commit comments