@@ -1804,7 +1804,6 @@ where
1804
1804
};
1805
1805
let mut funded_channel = FundedChannel {
1806
1806
funding: chan.funding,
1807
- pending_funding: vec![],
1808
1807
context: chan.context,
1809
1808
interactive_tx_signing_session: chan.interactive_tx_signing_session,
1810
1809
holder_commitment_point,
@@ -2176,6 +2175,7 @@ impl FundingScope {
2176
2175
struct PendingSplice {
2177
2176
pub our_funding_contribution: i64,
2178
2177
funding: Option<FundingScope>,
2178
+ pending_funding: Vec<FundingScope>,
2179
2179
2180
2180
/// The funding txid used in the `splice_locked` sent to the counterparty.
2181
2181
sent_funding_txid: Option<Txid>,
@@ -2187,11 +2187,14 @@ struct PendingSplice {
2187
2187
#[cfg(splicing)]
2188
2188
impl PendingSplice {
2189
2189
fn check_get_splice_locked<SP: Deref>(
2190
- &mut self, context: &ChannelContext<SP>, funding: &FundingScope , height: u32,
2190
+ &mut self, context: &ChannelContext<SP>, confirmed_funding_index: usize , height: u32,
2191
2191
) -> Option<msgs::SpliceLocked>
2192
2192
where
2193
2193
SP::Target: SignerProvider,
2194
2194
{
2195
+ debug_assert!(confirmed_funding_index < self.pending_funding.len());
2196
+
2197
+ let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
2195
2198
if !context.check_funding_meets_minimum_depth(funding, height) {
2196
2199
return None;
2197
2200
}
@@ -5931,7 +5934,6 @@ where
5931
5934
SP::Target: SignerProvider,
5932
5935
{
5933
5936
pub funding: FundingScope,
5934
- pending_funding: Vec<FundingScope>,
5935
5937
pub context: ChannelContext<SP>,
5936
5938
/// The signing session for the current interactive tx construction, if any.
5937
5939
///
@@ -5955,7 +5957,6 @@ macro_rules! promote_splice_funding {
5955
5957
}
5956
5958
core::mem::swap(&mut $self.funding, $funding);
5957
5959
$self.pending_splice = None;
5958
- $self.pending_funding.clear();
5959
5960
$self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
5960
5961
};
5961
5962
}
@@ -6049,6 +6050,14 @@ where
6049
6050
SP::Target: SignerProvider,
6050
6051
<SP::Target as SignerProvider>::EcdsaSigner: EcdsaChannelSigner,
6051
6052
{
6053
+ fn pending_funding(&self) -> &[FundingScope] {
6054
+ if let Some(pending_splice) = &self.pending_splice {
6055
+ pending_splice.pending_funding.as_slice()
6056
+ } else {
6057
+ &[]
6058
+ }
6059
+ }
6060
+
6052
6061
#[rustfmt::skip]
6053
6062
fn check_remote_fee<F: Deref, L: Deref>(
6054
6063
channel_type: &ChannelTypeFeatures, fee_estimator: &LowerBoundedFeeEstimator<F>,
@@ -6613,7 +6622,7 @@ where
6613
6622
}
6614
6623
6615
6624
core::iter::once(&self.funding)
6616
- .chain(self.pending_funding.iter())
6625
+ .chain(self.pending_funding() .iter())
6617
6626
.try_for_each(|funding| self.context.validate_update_add_htlc(funding, msg, fee_estimator))?;
6618
6627
6619
6628
// Now update local state:
@@ -6839,7 +6848,7 @@ where
6839
6848
{
6840
6849
self.commitment_signed_check_state()?;
6841
6850
6842
- if !self.pending_funding.is_empty() {
6851
+ if !self.pending_funding() .is_empty() {
6843
6852
return Err(ChannelError::close(
6844
6853
"Got a single commitment_signed message when expecting a batch".to_owned(),
6845
6854
));
@@ -6901,7 +6910,7 @@ where
6901
6910
// Any commitment_signed not associated with a FundingScope is ignored below if a
6902
6911
// pending splice transaction has confirmed since receiving the batch.
6903
6912
let updates = core::iter::once(&self.funding)
6904
- .chain(self.pending_funding.iter())
6913
+ .chain(self.pending_funding() .iter())
6905
6914
.map(|funding| {
6906
6915
let funding_txid = funding.get_funding_txo().unwrap().txid;
6907
6916
let msg = messages.get(&funding_txid).ok_or_else(|| {
@@ -7293,11 +7302,13 @@ where
7293
7302
7294
7303
#[cfg(any(test, fuzzing))]
7295
7304
{
7296
- for funding in
7297
- core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7298
- {
7299
- *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7300
- *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7305
+ *self.funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7306
+ *self.funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7307
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
7308
+ for funding in pending_splice.pending_funding.iter_mut() {
7309
+ *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7310
+ *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7311
+ }
7301
7312
}
7302
7313
}
7303
7314
@@ -7498,9 +7509,13 @@ where
7498
7509
}
7499
7510
}
7500
7511
7501
- for funding in core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut()) {
7502
- funding.value_to_self_msat =
7503
- (funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7512
+ self.funding.value_to_self_msat =
7513
+ (self.funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7514
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
7515
+ for funding in pending_splice.pending_funding.iter_mut() {
7516
+ funding.value_to_self_msat =
7517
+ (funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7518
+ }
7504
7519
}
7505
7520
7506
7521
if let Some((feerate, update_state)) = self.context.pending_update_fee {
@@ -7763,7 +7778,7 @@ where
7763
7778
}
7764
7779
7765
7780
let can_send_update_fee = core::iter::once(&self.funding)
7766
- .chain(self.pending_funding.iter())
7781
+ .chain(self.pending_funding() .iter())
7767
7782
.all(|funding| self.context.can_send_update_fee(funding, &self.holder_commitment_point, feerate_per_kw, fee_estimator, logger));
7768
7783
if !can_send_update_fee {
7769
7784
return None;
@@ -8052,14 +8067,14 @@ where
8052
8067
}
8053
8068
8054
8069
core::iter::once(&self.funding)
8055
- .chain(self.pending_funding.iter())
8070
+ .chain(self.pending_funding() .iter())
8056
8071
.try_for_each(|funding| FundedChannel::<SP>::check_remote_fee(funding.get_channel_type(), fee_estimator, msg.feerate_per_kw, Some(self.context.feerate_per_kw), logger))?;
8057
8072
8058
8073
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
8059
8074
self.context.update_time_counter += 1;
8060
8075
8061
8076
core::iter::once(&self.funding)
8062
- .chain(self.pending_funding.iter())
8077
+ .chain(self.pending_funding() .iter())
8063
8078
.try_for_each(|funding| self.context.validate_update_fee(funding, fee_estimator, msg))
8064
8079
}
8065
8080
@@ -9252,7 +9267,7 @@ where
9252
9267
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
9253
9268
9254
9269
core::iter::once(&self.funding)
9255
- .chain(self.pending_funding.iter())
9270
+ .chain(self.pending_funding() .iter())
9256
9271
.try_for_each(|funding| self.context.can_accept_incoming_htlc(funding, msg, dust_exposure_limiting_feerate, &logger))
9257
9272
}
9258
9273
@@ -9535,9 +9550,11 @@ where
9535
9550
L::Target: Logger,
9536
9551
{
9537
9552
debug_assert!(self.pending_splice.is_some());
9538
- debug_assert!(confirmed_funding_index < self.pending_funding.len());
9539
9553
9540
9554
let pending_splice = self.pending_splice.as_mut().unwrap();
9555
+
9556
+ debug_assert!(confirmed_funding_index < pending_splice.pending_funding.len());
9557
+
9541
9558
let splice_txid = match pending_splice.sent_funding_txid {
9542
9559
Some(sent_funding_txid) => sent_funding_txid,
9543
9560
None => {
@@ -9554,7 +9571,7 @@ where
9554
9571
&self.context.channel_id,
9555
9572
);
9556
9573
9557
- let funding = self .pending_funding.get_mut(confirmed_funding_index).unwrap();
9574
+ let funding = pending_splice .pending_funding.get_mut(confirmed_funding_index).unwrap();
9558
9575
debug_assert_eq!(Some(splice_txid), funding.get_funding_txid());
9559
9576
promote_splice_funding!(self, funding);
9560
9577
@@ -9628,18 +9645,20 @@ where
9628
9645
#[cfg(splicing)]
9629
9646
let mut funding_already_confirmed = false;
9630
9647
#[cfg(splicing)]
9631
- for (index, funding) in self.pending_funding.iter_mut().enumerate() {
9632
- if self.context.check_for_funding_tx_confirmed(
9633
- funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
9634
- )? {
9635
- if funding_already_confirmed || confirmed_funding_index.is_some() {
9636
- let err_reason = "splice tx of another pending funding already confirmed";
9637
- return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9638
- }
9648
+ if let Some(pending_splice) = &mut self.pending_splice {
9649
+ for (index, funding) in pending_splice.pending_funding.iter_mut().enumerate() {
9650
+ if self.context.check_for_funding_tx_confirmed(
9651
+ funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
9652
+ )? {
9653
+ if funding_already_confirmed || confirmed_funding_index.is_some() {
9654
+ let err_reason = "splice tx of another pending funding already confirmed";
9655
+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9656
+ }
9639
9657
9640
- confirmed_funding_index = Some(index);
9641
- } else if funding.funding_tx_confirmation_height != 0 {
9642
- funding_already_confirmed = true;
9658
+ confirmed_funding_index = Some(index);
9659
+ } else if funding.funding_tx_confirmation_height != 0 {
9660
+ funding_already_confirmed = true;
9661
+ }
9643
9662
}
9644
9663
}
9645
9664
@@ -9654,11 +9673,15 @@ where
9654
9673
return Err(ClosureReason::ProcessingError { err });
9655
9674
},
9656
9675
};
9657
- let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9658
9676
9659
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
9677
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9678
+ &self.context,
9679
+ confirmed_funding_index,
9680
+ height,
9681
+ ) {
9660
9682
for &(idx, tx) in txdata.iter() {
9661
9683
if idx > index_in_block {
9684
+ let funding = pending_splice.pending_funding.get(confirmed_funding_index).unwrap();
9662
9685
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9663
9686
}
9664
9687
}
@@ -9687,10 +9710,11 @@ where
9687
9710
9688
9711
self.context.check_for_funding_tx_spent(&self.funding, tx, logger)?;
9689
9712
#[cfg(splicing)]
9690
- for funding in self.pending_funding.iter() {
9691
- self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9713
+ if let Some(pending_splice) = self.pending_splice.as_ref() {
9714
+ for funding in pending_splice.pending_funding.iter() {
9715
+ self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9716
+ }
9692
9717
}
9693
-
9694
9718
}
9695
9719
9696
9720
Ok((None, None))
@@ -9794,7 +9818,7 @@ where
9794
9818
#[cfg(splicing)]
9795
9819
let mut confirmed_funding_index = None;
9796
9820
#[cfg(splicing)]
9797
- for (index, funding) in self.pending_funding.iter().enumerate() {
9821
+ for (index, funding) in self.pending_funding() .iter().enumerate() {
9798
9822
if funding.funding_tx_confirmation_height != 0 {
9799
9823
if confirmed_funding_index.is_some() {
9800
9824
let err_reason = "splice tx of another pending funding already confirmed";
@@ -9816,7 +9840,7 @@ where
9816
9840
return Err(ClosureReason::ProcessingError { err });
9817
9841
},
9818
9842
};
9819
- let funding = self .pending_funding.get_mut(confirmed_funding_index).unwrap();
9843
+ let funding = pending_splice .pending_funding.get_mut(confirmed_funding_index).unwrap();
9820
9844
9821
9845
// Check if the splice funding transaction was unconfirmed
9822
9846
if funding.get_funding_tx_confirmations(height) == 0 {
@@ -9835,8 +9859,11 @@ where
9835
9859
}
9836
9860
9837
9861
let pending_splice = self.pending_splice.as_mut().unwrap();
9838
- let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9839
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
9862
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9863
+ &self.context,
9864
+ confirmed_funding_index,
9865
+ height,
9866
+ ) {
9840
9867
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9841
9868
9842
9869
let funding_promoted =
@@ -9866,7 +9893,7 @@ where
9866
9893
9867
9894
pub fn get_relevant_txids(&self) -> impl Iterator<Item = (Txid, u32, Option<BlockHash>)> + '_ {
9868
9895
core::iter::once(&self.funding)
9869
- .chain(self.pending_funding.iter())
9896
+ .chain(self.pending_funding() .iter())
9870
9897
.map(|funding| {
9871
9898
(
9872
9899
funding.get_funding_txid(),
@@ -9896,9 +9923,16 @@ where
9896
9923
where
9897
9924
L::Target: Logger,
9898
9925
{
9899
- let unconfirmed_funding = core::iter::once(&mut self.funding)
9900
- .chain(self.pending_funding.iter_mut())
9901
- .find(|funding| funding.get_funding_txid() == Some(*txid));
9926
+ let unconfirmed_funding = (self.funding.get_funding_txid() == Some(*txid))
9927
+ .then(|| &mut self.funding)
9928
+ .or_else(|| {
9929
+ self.pending_splice.as_mut().and_then(|pending_splice| {
9930
+ pending_splice
9931
+ .pending_funding
9932
+ .iter_mut()
9933
+ .find(|funding| funding.get_funding_txid() == Some(*txid))
9934
+ })
9935
+ });
9902
9936
9903
9937
if let Some(funding) = unconfirmed_funding {
9904
9938
if funding.funding_tx_confirmation_height != 0 {
@@ -10254,6 +10288,7 @@ where
10254
10288
self.pending_splice = Some(PendingSplice {
10255
10289
our_funding_contribution: our_funding_contribution_satoshis,
10256
10290
funding: None,
10291
+ pending_funding: vec![],
10257
10292
sent_funding_txid: None,
10258
10293
received_funding_txid: None,
10259
10294
});
@@ -10370,7 +10405,7 @@ where
10370
10405
10371
10406
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10372
10407
if sent_funding_txid == msg.splice_txid {
10373
- if let Some(funding) = self
10408
+ if let Some(funding) = pending_splice
10374
10409
.pending_funding
10375
10410
.iter_mut()
10376
10411
.find(|funding| funding.get_funding_txid() == Some(sent_funding_txid))
@@ -10569,7 +10604,7 @@ where
10569
10604
F::Target: FeeEstimator,
10570
10605
{
10571
10606
core::iter::once(&self.funding)
10572
- .chain(self.pending_funding.iter())
10607
+ .chain(self.pending_funding() .iter())
10573
10608
.map(|funding| self.context.get_available_balances_for_scope(funding, fee_estimator))
10574
10609
.reduce(|acc, e| {
10575
10610
AvailableBalances {
@@ -10616,14 +10651,14 @@ where
10616
10651
}
10617
10652
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
10618
10653
10619
- let mut updates = Vec::with_capacity(self.pending_funding.len() + 1);
10620
- for funding in core::iter::once(&self.funding).chain(self.pending_funding.iter()) {
10654
+ let mut updates = Vec::with_capacity(self.pending_funding() .len() + 1);
10655
+ for funding in core::iter::once(&self.funding).chain(self.pending_funding() .iter()) {
10621
10656
let (htlcs_ref, counterparty_commitment_tx) =
10622
10657
self.build_commitment_no_state_update(funding, logger);
10623
10658
let htlc_outputs: Vec<(HTLCOutputInCommitment, Option<Box<HTLCSource>>)> =
10624
10659
htlcs_ref.into_iter().map(|(htlc, htlc_source)| (htlc, htlc_source.map(|source_ref| Box::new(source_ref.clone())))).collect();
10625
10660
10626
- if self.pending_funding.is_empty() {
10661
+ if self.pending_funding() .is_empty() {
10627
10662
// Soon, we will switch this to `LatestCounterpartyCommitmentTX`,
10628
10663
// and provide the full commit tx instead of the information needed to rebuild it.
10629
10664
updates.push(ChannelMonitorUpdateStep::LatestCounterpartyCommitmentTXInfo {
@@ -10700,7 +10735,7 @@ where
10700
10735
L::Target: Logger,
10701
10736
{
10702
10737
core::iter::once(&self.funding)
10703
- .chain(self.pending_funding.iter())
10738
+ .chain(self.pending_funding() .iter())
10704
10739
.map(|funding| self.send_commitment_no_state_update_for_funding(funding, logger))
10705
10740
.collect::<Result<Vec<_>, ChannelError>>()
10706
10741
}
@@ -11477,7 +11512,6 @@ where
11477
11512
11478
11513
let mut channel = FundedChannel {
11479
11514
funding: self.funding,
11480
- pending_funding: vec![],
11481
11515
context: self.context,
11482
11516
interactive_tx_signing_session: None,
11483
11517
holder_commitment_point,
@@ -11769,7 +11803,6 @@ where
11769
11803
// `ChannelMonitor`.
11770
11804
let mut channel = FundedChannel {
11771
11805
funding: self.funding,
11772
- pending_funding: vec![],
11773
11806
context: self.context,
11774
11807
interactive_tx_signing_session: None,
11775
11808
holder_commitment_point,
@@ -12937,7 +12970,6 @@ where
12937
12970
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
12938
12971
let mut is_manual_broadcast = None;
12939
12972
12940
- let mut pending_funding = Some(Vec::new());
12941
12973
let mut historical_scids = Some(Vec::new());
12942
12974
12943
12975
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
@@ -13161,7 +13193,6 @@ where
13161
13193
short_channel_id,
13162
13194
minimum_depth_override,
13163
13195
},
13164
- pending_funding: pending_funding.unwrap(),
13165
13196
context: ChannelContext {
13166
13197
user_id,
13167
13198
0 commit comments