@@ -1807,7 +1807,6 @@ where
1807
1807
};
1808
1808
let mut funded_channel = FundedChannel {
1809
1809
funding: chan.funding,
1810
- pending_funding: vec![],
1811
1810
context: chan.context,
1812
1811
interactive_tx_signing_session: chan.interactive_tx_signing_session,
1813
1812
holder_commitment_point,
@@ -2179,6 +2178,7 @@ impl FundingScope {
2179
2178
struct PendingSplice {
2180
2179
pub our_funding_contribution: i64,
2181
2180
funding: Option<FundingScope>,
2181
+ pending_funding: Vec<FundingScope>,
2182
2182
2183
2183
/// The funding txid used in the `splice_locked` sent to the counterparty.
2184
2184
sent_funding_txid: Option<Txid>,
@@ -2190,11 +2190,14 @@ struct PendingSplice {
2190
2190
#[cfg(splicing)]
2191
2191
impl PendingSplice {
2192
2192
fn check_get_splice_locked<SP: Deref>(
2193
- &mut self, context: &ChannelContext<SP>, funding: &FundingScope , height: u32,
2193
+ &mut self, context: &ChannelContext<SP>, confirmed_funding_index: usize , height: u32,
2194
2194
) -> Option<msgs::SpliceLocked>
2195
2195
where
2196
2196
SP::Target: SignerProvider,
2197
2197
{
2198
+ debug_assert!(confirmed_funding_index < self.pending_funding.len());
2199
+
2200
+ let funding = &self.pending_funding[confirmed_funding_index];
2198
2201
if !context.check_funding_meets_minimum_depth(funding, height) {
2199
2202
return None;
2200
2203
}
@@ -5885,7 +5888,6 @@ where
5885
5888
SP::Target: SignerProvider,
5886
5889
{
5887
5890
pub funding: FundingScope,
5888
- pending_funding: Vec<FundingScope>,
5889
5891
pub context: ChannelContext<SP>,
5890
5892
/// The signing session for the current interactive tx construction, if any.
5891
5893
///
@@ -5909,7 +5911,6 @@ macro_rules! promote_splice_funding {
5909
5911
}
5910
5912
core::mem::swap(&mut $self.funding, $funding);
5911
5913
$self.pending_splice = None;
5912
- $self.pending_funding.clear();
5913
5914
$self.context.announcement_sigs_state = AnnouncementSigsState::NotSent;
5914
5915
};
5915
5916
}
@@ -5995,6 +5996,36 @@ where
5995
5996
SP::Target: SignerProvider,
5996
5997
<SP::Target as SignerProvider>::EcdsaSigner: EcdsaChannelSigner,
5997
5998
{
5999
+ #[cfg(splicing)]
6000
+ fn pending_funding(&self) -> &[FundingScope] {
6001
+ if let Some(pending_splice) = &self.pending_splice {
6002
+ pending_splice.pending_funding.as_slice()
6003
+ } else {
6004
+ &[]
6005
+ }
6006
+ }
6007
+
6008
+ #[cfg(not(splicing))]
6009
+ fn pending_funding(&self) -> &[FundingScope] {
6010
+ &[]
6011
+ }
6012
+
6013
+ #[cfg(splicing)]
6014
+ fn funding_and_pending_funding_iter_mut(&mut self) -> impl Iterator<Item = &mut FundingScope> {
6015
+ core::iter::once(&mut self.funding).chain(
6016
+ self.pending_splice
6017
+ .as_mut()
6018
+ .map(|pending_splice| pending_splice.pending_funding.as_mut_slice())
6019
+ .unwrap_or(&mut [])
6020
+ .iter_mut(),
6021
+ )
6022
+ }
6023
+
6024
+ #[cfg(not(splicing))]
6025
+ fn funding_and_pending_funding_iter_mut(&mut self) -> impl Iterator<Item = &mut FundingScope> {
6026
+ core::iter::once(&mut self.funding)
6027
+ }
6028
+
5998
6029
#[rustfmt::skip]
5999
6030
fn check_remote_fee<F: Deref, L: Deref>(
6000
6031
channel_type: &ChannelTypeFeatures, fee_estimator: &LowerBoundedFeeEstimator<F>,
@@ -6559,7 +6590,7 @@ where
6559
6590
}
6560
6591
6561
6592
core::iter::once(&self.funding)
6562
- .chain(self.pending_funding.iter())
6593
+ .chain(self.pending_funding() .iter())
6563
6594
.try_for_each(|funding| self.context.validate_update_add_htlc(funding, msg, fee_estimator))?;
6564
6595
6565
6596
// Now update local state:
@@ -6802,7 +6833,7 @@ where
6802
6833
{
6803
6834
self.commitment_signed_check_state()?;
6804
6835
6805
- if !self.pending_funding.is_empty() {
6836
+ if !self.pending_funding() .is_empty() {
6806
6837
return Err(ChannelError::close(
6807
6838
"Got a single commitment_signed message when expecting a batch".to_owned(),
6808
6839
));
@@ -6861,9 +6892,9 @@ where
6861
6892
6862
6893
// Any commitment_signed not associated with a FundingScope is ignored below if a
6863
6894
// pending splice transaction has confirmed since receiving the batch.
6864
- let mut commitment_txs = Vec::with_capacity(self.pending_funding.len() + 1);
6895
+ let mut commitment_txs = Vec::with_capacity(self.pending_funding() .len() + 1);
6865
6896
let mut htlc_data = None;
6866
- for funding in core::iter::once(&self.funding).chain(self.pending_funding.iter()) {
6897
+ for funding in core::iter::once(&self.funding).chain(self.pending_funding() .iter()) {
6867
6898
let funding_txid =
6868
6899
funding.get_funding_txid().expect("Funding txid must be known for pending scope");
6869
6900
let msg = messages.get(&funding_txid).ok_or_else(|| {
@@ -7265,9 +7296,7 @@ where
7265
7296
7266
7297
#[cfg(any(test, fuzzing))]
7267
7298
{
7268
- for funding in
7269
- core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7270
- {
7299
+ for funding in self.funding_and_pending_funding_iter_mut() {
7271
7300
*funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7272
7301
*funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7273
7302
}
@@ -7470,7 +7499,7 @@ where
7470
7499
}
7471
7500
}
7472
7501
7473
- for funding in core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut() ) {
7502
+ for funding in self.funding_and_pending_funding_iter_mut( ) {
7474
7503
funding.value_to_self_msat =
7475
7504
(funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7476
7505
}
@@ -7735,7 +7764,7 @@ where
7735
7764
}
7736
7765
7737
7766
let can_send_update_fee = core::iter::once(&self.funding)
7738
- .chain(self.pending_funding.iter())
7767
+ .chain(self.pending_funding() .iter())
7739
7768
.all(|funding| self.context.can_send_update_fee(funding, feerate_per_kw, fee_estimator, logger));
7740
7769
if !can_send_update_fee {
7741
7770
return None;
@@ -8024,14 +8053,14 @@ where
8024
8053
}
8025
8054
8026
8055
core::iter::once(&self.funding)
8027
- .chain(self.pending_funding.iter())
8056
+ .chain(self.pending_funding() .iter())
8028
8057
.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))?;
8029
8058
8030
8059
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
8031
8060
self.context.update_time_counter += 1;
8032
8061
8033
8062
core::iter::once(&self.funding)
8034
- .chain(self.pending_funding.iter())
8063
+ .chain(self.pending_funding() .iter())
8035
8064
.try_for_each(|funding| self.context.validate_update_fee(funding, fee_estimator, msg))
8036
8065
}
8037
8066
@@ -9224,7 +9253,7 @@ where
9224
9253
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
9225
9254
9226
9255
core::iter::once(&self.funding)
9227
- .chain(self.pending_funding.iter())
9256
+ .chain(self.pending_funding() .iter())
9228
9257
.try_for_each(|funding| self.context.can_accept_incoming_htlc(funding, msg, dust_exposure_limiting_feerate, &logger))
9229
9258
}
9230
9259
@@ -9513,9 +9542,11 @@ where
9513
9542
L::Target: Logger,
9514
9543
{
9515
9544
debug_assert!(self.pending_splice.is_some());
9516
- debug_assert!(confirmed_funding_index < self.pending_funding.len());
9517
9545
9518
9546
let pending_splice = self.pending_splice.as_mut().unwrap();
9547
+
9548
+ debug_assert!(confirmed_funding_index < pending_splice.pending_funding.len());
9549
+
9519
9550
let splice_txid = match pending_splice.sent_funding_txid {
9520
9551
Some(sent_funding_txid) => sent_funding_txid,
9521
9552
None => {
@@ -9532,7 +9563,7 @@ where
9532
9563
&self.context.channel_id,
9533
9564
);
9534
9565
9535
- let funding = self .pending_funding.get_mut( confirmed_funding_index).unwrap() ;
9566
+ let funding = &mut pending_splice .pending_funding[ confirmed_funding_index] ;
9536
9567
debug_assert_eq!(Some(splice_txid), funding.get_funding_txid());
9537
9568
promote_splice_funding!(self, funding);
9538
9569
@@ -9606,18 +9637,20 @@ where
9606
9637
#[cfg(splicing)]
9607
9638
let mut funding_already_confirmed = false;
9608
9639
#[cfg(splicing)]
9609
- for (index, funding) in self.pending_funding.iter_mut().enumerate() {
9610
- if self.context.check_for_funding_tx_confirmed(
9611
- funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
9612
- )? {
9613
- if funding_already_confirmed || confirmed_funding_index.is_some() {
9614
- let err_reason = "splice tx of another pending funding already confirmed";
9615
- return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9616
- }
9640
+ if let Some(pending_splice) = &mut self.pending_splice {
9641
+ for (index, funding) in pending_splice.pending_funding.iter_mut().enumerate() {
9642
+ if self.context.check_for_funding_tx_confirmed(
9643
+ funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
9644
+ )? {
9645
+ if funding_already_confirmed || confirmed_funding_index.is_some() {
9646
+ let err_reason = "splice tx of another pending funding already confirmed";
9647
+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9648
+ }
9617
9649
9618
- confirmed_funding_index = Some(index);
9619
- } else if funding.funding_tx_confirmation_height != 0 {
9620
- funding_already_confirmed = true;
9650
+ confirmed_funding_index = Some(index);
9651
+ } else if funding.funding_tx_confirmation_height != 0 {
9652
+ funding_already_confirmed = true;
9653
+ }
9621
9654
}
9622
9655
}
9623
9656
@@ -9632,11 +9665,15 @@ where
9632
9665
return Err(ClosureReason::ProcessingError { err });
9633
9666
},
9634
9667
};
9635
- let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9636
9668
9637
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
9669
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9670
+ &self.context,
9671
+ confirmed_funding_index,
9672
+ height,
9673
+ ) {
9638
9674
for &(idx, tx) in txdata.iter() {
9639
9675
if idx > index_in_block {
9676
+ let funding = &pending_splice.pending_funding[confirmed_funding_index];
9640
9677
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9641
9678
}
9642
9679
}
@@ -9665,10 +9702,11 @@ where
9665
9702
9666
9703
self.context.check_for_funding_tx_spent(&self.funding, tx, logger)?;
9667
9704
#[cfg(splicing)]
9668
- for funding in self.pending_funding.iter() {
9669
- self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9705
+ if let Some(pending_splice) = self.pending_splice.as_ref() {
9706
+ for funding in pending_splice.pending_funding.iter() {
9707
+ self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9708
+ }
9670
9709
}
9671
-
9672
9710
}
9673
9711
9674
9712
Ok((None, None))
@@ -9772,7 +9810,7 @@ where
9772
9810
#[cfg(splicing)]
9773
9811
let mut confirmed_funding_index = None;
9774
9812
#[cfg(splicing)]
9775
- for (index, funding) in self.pending_funding.iter().enumerate() {
9813
+ for (index, funding) in self.pending_funding() .iter().enumerate() {
9776
9814
if funding.funding_tx_confirmation_height != 0 {
9777
9815
if confirmed_funding_index.is_some() {
9778
9816
let err_reason = "splice tx of another pending funding already confirmed";
@@ -9794,7 +9832,7 @@ where
9794
9832
return Err(ClosureReason::ProcessingError { err });
9795
9833
},
9796
9834
};
9797
- let funding = self .pending_funding.get_mut( confirmed_funding_index).unwrap() ;
9835
+ let funding = &mut pending_splice .pending_funding[ confirmed_funding_index] ;
9798
9836
9799
9837
// Check if the splice funding transaction was unconfirmed
9800
9838
if funding.get_funding_tx_confirmations(height) == 0 {
@@ -9813,8 +9851,11 @@ where
9813
9851
}
9814
9852
9815
9853
let pending_splice = self.pending_splice.as_mut().unwrap();
9816
- let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9817
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
9854
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9855
+ &self.context,
9856
+ confirmed_funding_index,
9857
+ height,
9858
+ ) {
9818
9859
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9819
9860
9820
9861
let funding_promoted =
@@ -9844,7 +9885,7 @@ where
9844
9885
9845
9886
pub fn get_relevant_txids(&self) -> impl Iterator<Item = (Txid, u32, Option<BlockHash>)> + '_ {
9846
9887
core::iter::once(&self.funding)
9847
- .chain(self.pending_funding.iter())
9888
+ .chain(self.pending_funding() .iter())
9848
9889
.map(|funding| {
9849
9890
(
9850
9891
funding.get_funding_txid(),
@@ -9874,8 +9915,8 @@ where
9874
9915
where
9875
9916
L::Target: Logger,
9876
9917
{
9877
- let unconfirmed_funding = core::iter::once(&mut self.funding)
9878
- .chain(self.pending_funding.iter_mut() )
9918
+ let unconfirmed_funding = self
9919
+ .funding_and_pending_funding_iter_mut( )
9879
9920
.find(|funding| funding.get_funding_txid() == Some(*txid));
9880
9921
9881
9922
if let Some(funding) = unconfirmed_funding {
@@ -10232,6 +10273,7 @@ where
10232
10273
self.pending_splice = Some(PendingSplice {
10233
10274
our_funding_contribution: our_funding_contribution_satoshis,
10234
10275
funding: None,
10276
+ pending_funding: vec![],
10235
10277
sent_funding_txid: None,
10236
10278
received_funding_txid: None,
10237
10279
});
@@ -10348,7 +10390,7 @@ where
10348
10390
10349
10391
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10350
10392
if sent_funding_txid == msg.splice_txid {
10351
- if let Some(funding) = self
10393
+ if let Some(funding) = pending_splice
10352
10394
.pending_funding
10353
10395
.iter_mut()
10354
10396
.find(|funding| funding.get_funding_txid() == Some(sent_funding_txid))
@@ -10547,7 +10589,7 @@ where
10547
10589
F::Target: FeeEstimator,
10548
10590
{
10549
10591
core::iter::once(&self.funding)
10550
- .chain(self.pending_funding.iter())
10592
+ .chain(self.pending_funding() .iter())
10551
10593
.map(|funding| self.context.get_available_balances_for_scope(funding, fee_estimator))
10552
10594
.reduce(|acc, e| {
10553
10595
AvailableBalances {
@@ -10594,7 +10636,7 @@ where
10594
10636
}
10595
10637
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
10596
10638
10597
- let update = if self.pending_funding.is_empty() {
10639
+ let update = if self.pending_funding() .is_empty() {
10598
10640
let (htlcs_ref, counterparty_commitment_tx) =
10599
10641
self.build_commitment_no_state_update(&self.funding, logger);
10600
10642
let htlc_outputs = htlcs_ref.into_iter()
@@ -10617,7 +10659,7 @@ where
10617
10659
} else {
10618
10660
let mut htlc_data = None;
10619
10661
let commitment_txs = core::iter::once(&self.funding)
10620
- .chain(self.pending_funding.iter())
10662
+ .chain(self.pending_funding() .iter())
10621
10663
.map(|funding| {
10622
10664
let (htlcs_ref, counterparty_commitment_tx) =
10623
10665
self.build_commitment_no_state_update(funding, logger);
@@ -10699,7 +10741,7 @@ where
10699
10741
L::Target: Logger,
10700
10742
{
10701
10743
core::iter::once(&self.funding)
10702
- .chain(self.pending_funding.iter())
10744
+ .chain(self.pending_funding() .iter())
10703
10745
.map(|funding| self.send_commitment_no_state_update_for_funding(funding, logger))
10704
10746
.collect::<Result<Vec<_>, ChannelError>>()
10705
10747
}
@@ -11476,7 +11518,6 @@ where
11476
11518
11477
11519
let mut channel = FundedChannel {
11478
11520
funding: self.funding,
11479
- pending_funding: vec![],
11480
11521
context: self.context,
11481
11522
interactive_tx_signing_session: None,
11482
11523
holder_commitment_point,
@@ -11768,7 +11809,6 @@ where
11768
11809
// `ChannelMonitor`.
11769
11810
let mut channel = FundedChannel {
11770
11811
funding: self.funding,
11771
- pending_funding: vec![],
11772
11812
context: self.context,
11773
11813
interactive_tx_signing_session: None,
11774
11814
holder_commitment_point,
@@ -12936,7 +12976,6 @@ where
12936
12976
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
12937
12977
let mut is_manual_broadcast = None;
12938
12978
12939
- let mut pending_funding = Some(Vec::new());
12940
12979
let mut historical_scids = Some(Vec::new());
12941
12980
12942
12981
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
@@ -13160,7 +13199,6 @@ where
13160
13199
short_channel_id,
13161
13200
minimum_depth_override,
13162
13201
},
13163
- pending_funding: pending_funding.unwrap(),
13164
13202
context: ChannelContext {
13165
13203
user_id,
13166
13204
0 commit comments