@@ -1193,6 +1193,14 @@ pub(crate) struct ShutdownResult {
1193
1193
pub(crate) splice_funding_failed: Option<SpliceFundingFailed>,
1194
1194
}
1195
1195
1196
+ /// The result of a peer disconnection.
1197
+ pub(crate) struct DisconnectResult {
1198
+ pub(crate) is_resumable: bool,
1199
+ /// If a splice was in progress when the channel was shut down, this contains
1200
+ /// the splice funding information for emitting a SpliceFailed event.
1201
+ pub(crate) splice_funding_failed: Option<SpliceFundingFailed>,
1202
+ }
1203
+
1196
1204
/// Tracks the transaction number, along with current and next commitment points.
1197
1205
/// This consolidates the logic to advance our commitment number and request new
1198
1206
/// commitment points from our signer.
@@ -1585,11 +1593,15 @@ where
1585
1593
/// Should be called when the peer is disconnected. Returns true if the channel can be resumed
1586
1594
/// when the peer reconnects (via [`Self::peer_connected_get_handshake`]). If not, the channel
1587
1595
/// must be immediately closed.
1588
- #[rustfmt::skip]
1589
- pub fn peer_disconnected_is_resumable<L: Deref>(&mut self, logger: &L) -> bool where L::Target: Logger {
1590
- match &mut self.phase {
1596
+ pub fn peer_disconnected_is_resumable<L: Deref>(&mut self, logger: &L) -> DisconnectResult
1597
+ where
1598
+ L::Target: Logger,
1599
+ {
1600
+ let is_resumable = match &mut self.phase {
1591
1601
ChannelPhase::Undefined => unreachable!(),
1592
- ChannelPhase::Funded(chan) => chan.remove_uncommitted_htlcs_and_mark_paused(logger).is_ok(),
1602
+ ChannelPhase::Funded(chan) => {
1603
+ chan.remove_uncommitted_htlcs_and_mark_paused(logger).is_ok()
1604
+ },
1593
1605
// If we get disconnected and haven't yet committed to a funding
1594
1606
// transaction, we can replay the `open_channel` on reconnection, so don't
1595
1607
// bother dropping the channel here. However, if we already committed to
@@ -1599,7 +1611,15 @@ where
1599
1611
ChannelPhase::UnfundedOutboundV1(chan) => chan.is_resumable(),
1600
1612
ChannelPhase::UnfundedInboundV1(_) => false,
1601
1613
ChannelPhase::UnfundedV2(_) => false,
1602
- }
1614
+ };
1615
+
1616
+ let splice_funding_failed = if let ChannelPhase::Funded(chan) = &mut self.phase {
1617
+ chan.maybe_fail_splice_negotiation()
1618
+ } else {
1619
+ None
1620
+ };
1621
+
1622
+ DisconnectResult { is_resumable, splice_funding_failed }
1603
1623
}
1604
1624
1605
1625
/// Should be called when the peer re-connects, returning an initial message which we should
@@ -6800,8 +6820,15 @@ where
6800
6820
}
6801
6821
6802
6822
pub fn force_shutdown(&mut self, closure_reason: ClosureReason) -> ShutdownResult {
6803
- let splice_funding_failed = self
6804
- .pending_splice
6823
+ let splice_funding_failed = self.maybe_fail_splice_negotiation();
6824
+
6825
+ let mut shutdown_result = self.context.force_shutdown(&self.funding, closure_reason);
6826
+ shutdown_result.splice_funding_failed = splice_funding_failed;
6827
+ shutdown_result
6828
+ }
6829
+
6830
+ fn maybe_fail_splice_negotiation(&mut self) -> Option<SpliceFundingFailed> {
6831
+ self.pending_splice
6805
6832
.as_mut()
6806
6833
.and_then(|pending_splice| pending_splice.funding_negotiation.take())
6807
6834
.filter(|funding_negotiation| funding_negotiation.is_initiator())
@@ -6831,11 +6858,7 @@ where
6831
6858
None
6832
6859
},
6833
6860
})
6834
- });
6835
-
6836
- let mut shutdown_result = self.context.force_shutdown(&self.funding, closure_reason);
6837
- shutdown_result.splice_funding_failed = splice_funding_failed;
6838
- shutdown_result
6861
+ })
6839
6862
}
6840
6863
6841
6864
fn interactive_tx_constructor_mut(&mut self) -> Option<&mut InteractiveTxConstructor> {
@@ -11672,9 +11695,9 @@ where
11672
11695
.map_err(|e| APIError::APIMisuseError { err: e.to_owned() })
11673
11696
}
11674
11697
11675
- fn send_splice_init(
11676
- &mut self, instructions: SpliceInstructions,
11677
- ) -> Result<msgs::SpliceInit, String> {
11698
+ fn send_splice_init(&mut self, instructions: SpliceInstructions) -> msgs::SpliceInit {
11699
+ debug_assert!( self.pending_splice.is_none());
11700
+
11678
11701
let SpliceInstructions {
11679
11702
adjusted_funding_contribution,
11680
11703
our_funding_inputs,
@@ -11684,15 +11707,6 @@ where
11684
11707
locktime,
11685
11708
} = instructions;
11686
11709
11687
- // Check if a splice has been initiated already.
11688
- // Note: only a single outstanding splice is supported (per spec)
11689
- if self.pending_splice.is_some() {
11690
- return Err(format!(
11691
- "Channel {} cannot be spliced, as it has already a splice pending",
11692
- self.context.channel_id(),
11693
- ));
11694
- }
11695
-
11696
11710
let prev_funding_input = self.funding.to_splice_funding_input();
11697
11711
let context = FundingNegotiationContext {
11698
11712
is_initiator: true,
@@ -11716,14 +11730,14 @@ where
11716
11730
let prev_funding_txid = self.funding.get_funding_txid();
11717
11731
let funding_pubkey = self.context.holder_pubkeys(prev_funding_txid).funding_pubkey;
11718
11732
11719
- Ok( msgs::SpliceInit {
11733
+ msgs::SpliceInit {
11720
11734
channel_id: self.context.channel_id,
11721
11735
funding_contribution_satoshis: adjusted_funding_contribution.to_sat(),
11722
11736
funding_feerate_per_kw,
11723
11737
locktime,
11724
11738
funding_pubkey,
11725
11739
require_confirmed_inputs: None,
11726
- })
11740
+ }
11727
11741
}
11728
11742
11729
11743
/// Checks during handling splice_init
@@ -12868,10 +12882,21 @@ where
12868
12882
"Internal Error: Didn't have anything to do after reaching quiescence".to_owned()
12869
12883
));
12870
12884
},
12871
- Some(QuiescentAction::Splice(_instructions)) => {
12872
- return self.send_splice_init(_instructions)
12873
- .map(|splice_init| Some(StfuResponse::SpliceInit(splice_init)))
12874
- .map_err(|e| ChannelError::WarnAndDisconnect(e.to_owned()));
12885
+ Some(QuiescentAction::Splice(instructions)) => {
12886
+ if self.pending_splice.is_some() {
12887
+ debug_assert!(false);
12888
+ self.quiescent_action = Some(QuiescentAction::Splice(instructions));
12889
+
12890
+ return Err(ChannelError::WarnAndDisconnect(
12891
+ format!(
12892
+ "Channel {} cannot be spliced as it already has a splice pending",
12893
+ self.context.channel_id(),
12894
+ ),
12895
+ ));
12896
+ }
12897
+
12898
+ let splice_init = self.send_splice_init(instructions);
12899
+ return Ok(Some(StfuResponse::SpliceInit(splice_init)));
12875
12900
},
12876
12901
#[cfg(any(test, fuzzing))]
12877
12902
Some(QuiescentAction::DoNothing) => {
0 commit comments