@@ -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.get(confirmed_funding_index).unwrap();
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,14 @@ where
5995
5996
SP::Target: SignerProvider,
5996
5997
<SP::Target as SignerProvider>::EcdsaSigner: EcdsaChannelSigner,
5997
5998
{
5999
+ fn pending_funding(&self) -> &[FundingScope] {
6000
+ if let Some(pending_splice) = &self.pending_splice {
6001
+ pending_splice.pending_funding.as_slice()
6002
+ } else {
6003
+ &[]
6004
+ }
6005
+ }
6006
+
5998
6007
#[rustfmt::skip]
5999
6008
fn check_remote_fee<F: Deref, L: Deref>(
6000
6009
channel_type: &ChannelTypeFeatures, fee_estimator: &LowerBoundedFeeEstimator<F>,
@@ -6559,7 +6568,7 @@ where
6559
6568
}
6560
6569
6561
6570
core::iter::once(&self.funding)
6562
- .chain(self.pending_funding.iter())
6571
+ .chain(self.pending_funding() .iter())
6563
6572
.try_for_each(|funding| self.context.validate_update_add_htlc(funding, msg, fee_estimator))?;
6564
6573
6565
6574
// Now update local state:
@@ -6802,7 +6811,7 @@ where
6802
6811
{
6803
6812
self.commitment_signed_check_state()?;
6804
6813
6805
- if !self.pending_funding.is_empty() {
6814
+ if !self.pending_funding() .is_empty() {
6806
6815
return Err(ChannelError::close(
6807
6816
"Got a single commitment_signed message when expecting a batch".to_owned(),
6808
6817
));
@@ -6861,9 +6870,9 @@ where
6861
6870
6862
6871
// Any commitment_signed not associated with a FundingScope is ignored below if a
6863
6872
// pending splice transaction has confirmed since receiving the batch.
6864
- let mut commitment_txs = Vec::with_capacity(self.pending_funding.len() + 1);
6873
+ let mut commitment_txs = Vec::with_capacity(self.pending_funding() .len() + 1);
6865
6874
let mut htlc_data = None;
6866
- for funding in core::iter::once(&self.funding).chain(self.pending_funding.iter()) {
6875
+ for funding in core::iter::once(&self.funding).chain(self.pending_funding() .iter()) {
6867
6876
let funding_txid =
6868
6877
funding.get_funding_txid().expect("Funding txid must be known for pending scope");
6869
6878
let msg = messages.get(&funding_txid).ok_or_else(|| {
@@ -7265,11 +7274,13 @@ where
7265
7274
7266
7275
#[cfg(any(test, fuzzing))]
7267
7276
{
7268
- for funding in
7269
- core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut())
7270
- {
7271
- *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7272
- *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7277
+ *self.funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7278
+ *self.funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7279
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
7280
+ for funding in pending_splice.pending_funding.iter_mut() {
7281
+ *funding.next_local_commitment_tx_fee_info_cached.lock().unwrap() = None;
7282
+ *funding.next_remote_commitment_tx_fee_info_cached.lock().unwrap() = None;
7283
+ }
7273
7284
}
7274
7285
}
7275
7286
@@ -7470,9 +7481,13 @@ where
7470
7481
}
7471
7482
}
7472
7483
7473
- for funding in core::iter::once(&mut self.funding).chain(self.pending_funding.iter_mut()) {
7474
- funding.value_to_self_msat =
7475
- (funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7484
+ self.funding.value_to_self_msat =
7485
+ (self.funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7486
+ if let Some(pending_splice) = self.pending_splice.as_mut() {
7487
+ for funding in pending_splice.pending_funding.iter_mut() {
7488
+ funding.value_to_self_msat =
7489
+ (funding.value_to_self_msat as i64 + value_to_self_msat_diff) as u64;
7490
+ }
7476
7491
}
7477
7492
7478
7493
if let Some((feerate, update_state)) = self.context.pending_update_fee {
@@ -7735,7 +7750,7 @@ where
7735
7750
}
7736
7751
7737
7752
let can_send_update_fee = core::iter::once(&self.funding)
7738
- .chain(self.pending_funding.iter())
7753
+ .chain(self.pending_funding() .iter())
7739
7754
.all(|funding| self.context.can_send_update_fee(funding, feerate_per_kw, fee_estimator, logger));
7740
7755
if !can_send_update_fee {
7741
7756
return None;
@@ -8024,14 +8039,14 @@ where
8024
8039
}
8025
8040
8026
8041
core::iter::once(&self.funding)
8027
- .chain(self.pending_funding.iter())
8042
+ .chain(self.pending_funding() .iter())
8028
8043
.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
8044
8030
8045
self.context.pending_update_fee = Some((msg.feerate_per_kw, FeeUpdateState::RemoteAnnounced));
8031
8046
self.context.update_time_counter += 1;
8032
8047
8033
8048
core::iter::once(&self.funding)
8034
- .chain(self.pending_funding.iter())
8049
+ .chain(self.pending_funding() .iter())
8035
8050
.try_for_each(|funding| self.context.validate_update_fee(funding, fee_estimator, msg))
8036
8051
}
8037
8052
@@ -9224,7 +9239,7 @@ where
9224
9239
let dust_exposure_limiting_feerate = self.context.get_dust_exposure_limiting_feerate(&fee_estimator);
9225
9240
9226
9241
core::iter::once(&self.funding)
9227
- .chain(self.pending_funding.iter())
9242
+ .chain(self.pending_funding() .iter())
9228
9243
.try_for_each(|funding| self.context.can_accept_incoming_htlc(funding, msg, dust_exposure_limiting_feerate, &logger))
9229
9244
}
9230
9245
@@ -9513,9 +9528,11 @@ where
9513
9528
L::Target: Logger,
9514
9529
{
9515
9530
debug_assert!(self.pending_splice.is_some());
9516
- debug_assert!(confirmed_funding_index < self.pending_funding.len());
9517
9531
9518
9532
let pending_splice = self.pending_splice.as_mut().unwrap();
9533
+
9534
+ debug_assert!(confirmed_funding_index < pending_splice.pending_funding.len());
9535
+
9519
9536
let splice_txid = match pending_splice.sent_funding_txid {
9520
9537
Some(sent_funding_txid) => sent_funding_txid,
9521
9538
None => {
@@ -9532,7 +9549,7 @@ where
9532
9549
&self.context.channel_id,
9533
9550
);
9534
9551
9535
- let funding = self .pending_funding.get_mut(confirmed_funding_index).unwrap();
9552
+ let funding = pending_splice .pending_funding.get_mut(confirmed_funding_index).unwrap();
9536
9553
debug_assert_eq!(Some(splice_txid), funding.get_funding_txid());
9537
9554
promote_splice_funding!(self, funding);
9538
9555
@@ -9606,18 +9623,20 @@ where
9606
9623
#[cfg(splicing)]
9607
9624
let mut funding_already_confirmed = false;
9608
9625
#[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
- }
9626
+ if let Some(pending_splice) = &mut self.pending_splice {
9627
+ for (index, funding) in pending_splice.pending_funding.iter_mut().enumerate() {
9628
+ if self.context.check_for_funding_tx_confirmed(
9629
+ funding, block_hash, height, index_in_block, &mut confirmed_tx, logger,
9630
+ )? {
9631
+ if funding_already_confirmed || confirmed_funding_index.is_some() {
9632
+ let err_reason = "splice tx of another pending funding already confirmed";
9633
+ return Err(ClosureReason::ProcessingError { err: err_reason.to_owned() });
9634
+ }
9617
9635
9618
- confirmed_funding_index = Some(index);
9619
- } else if funding.funding_tx_confirmation_height != 0 {
9620
- funding_already_confirmed = true;
9636
+ confirmed_funding_index = Some(index);
9637
+ } else if funding.funding_tx_confirmation_height != 0 {
9638
+ funding_already_confirmed = true;
9639
+ }
9621
9640
}
9622
9641
}
9623
9642
@@ -9632,11 +9651,15 @@ where
9632
9651
return Err(ClosureReason::ProcessingError { err });
9633
9652
},
9634
9653
};
9635
- let funding = self.pending_funding.get(confirmed_funding_index).unwrap();
9636
9654
9637
- if let Some(splice_locked) = pending_splice.check_get_splice_locked(&self.context, funding, height) {
9655
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9656
+ &self.context,
9657
+ confirmed_funding_index,
9658
+ height,
9659
+ ) {
9638
9660
for &(idx, tx) in txdata.iter() {
9639
9661
if idx > index_in_block {
9662
+ let funding = pending_splice.pending_funding.get(confirmed_funding_index).unwrap();
9640
9663
self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9641
9664
}
9642
9665
}
@@ -9665,10 +9688,11 @@ where
9665
9688
9666
9689
self.context.check_for_funding_tx_spent(&self.funding, tx, logger)?;
9667
9690
#[cfg(splicing)]
9668
- for funding in self.pending_funding.iter() {
9669
- self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9691
+ if let Some(pending_splice) = self.pending_splice.as_ref() {
9692
+ for funding in pending_splice.pending_funding.iter() {
9693
+ self.context.check_for_funding_tx_spent(funding, tx, logger)?;
9694
+ }
9670
9695
}
9671
-
9672
9696
}
9673
9697
9674
9698
Ok((None, None))
@@ -9772,7 +9796,7 @@ where
9772
9796
#[cfg(splicing)]
9773
9797
let mut confirmed_funding_index = None;
9774
9798
#[cfg(splicing)]
9775
- for (index, funding) in self.pending_funding.iter().enumerate() {
9799
+ for (index, funding) in self.pending_funding() .iter().enumerate() {
9776
9800
if funding.funding_tx_confirmation_height != 0 {
9777
9801
if confirmed_funding_index.is_some() {
9778
9802
let err_reason = "splice tx of another pending funding already confirmed";
@@ -9794,7 +9818,7 @@ where
9794
9818
return Err(ClosureReason::ProcessingError { err });
9795
9819
},
9796
9820
};
9797
- let funding = self .pending_funding.get_mut(confirmed_funding_index).unwrap();
9821
+ let funding = pending_splice .pending_funding.get_mut(confirmed_funding_index).unwrap();
9798
9822
9799
9823
// Check if the splice funding transaction was unconfirmed
9800
9824
if funding.get_funding_tx_confirmations(height) == 0 {
@@ -9813,8 +9837,11 @@ where
9813
9837
}
9814
9838
9815
9839
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) {
9840
+ if let Some(splice_locked) = pending_splice.check_get_splice_locked(
9841
+ &self.context,
9842
+ confirmed_funding_index,
9843
+ height,
9844
+ ) {
9818
9845
log_info!(logger, "Sending a splice_locked to our peer for channel {}", &self.context.channel_id);
9819
9846
9820
9847
let funding_promoted =
@@ -9844,7 +9871,7 @@ where
9844
9871
9845
9872
pub fn get_relevant_txids(&self) -> impl Iterator<Item = (Txid, u32, Option<BlockHash>)> + '_ {
9846
9873
core::iter::once(&self.funding)
9847
- .chain(self.pending_funding.iter())
9874
+ .chain(self.pending_funding() .iter())
9848
9875
.map(|funding| {
9849
9876
(
9850
9877
funding.get_funding_txid(),
@@ -9874,9 +9901,16 @@ where
9874
9901
where
9875
9902
L::Target: Logger,
9876
9903
{
9877
- let unconfirmed_funding = core::iter::once(&mut self.funding)
9878
- .chain(self.pending_funding.iter_mut())
9879
- .find(|funding| funding.get_funding_txid() == Some(*txid));
9904
+ let unconfirmed_funding = (self.funding.get_funding_txid() == Some(*txid))
9905
+ .then(|| &mut self.funding)
9906
+ .or_else(|| {
9907
+ self.pending_splice.as_mut().and_then(|pending_splice| {
9908
+ pending_splice
9909
+ .pending_funding
9910
+ .iter_mut()
9911
+ .find(|funding| funding.get_funding_txid() == Some(*txid))
9912
+ })
9913
+ });
9880
9914
9881
9915
if let Some(funding) = unconfirmed_funding {
9882
9916
if funding.funding_tx_confirmation_height != 0 {
@@ -10232,6 +10266,7 @@ where
10232
10266
self.pending_splice = Some(PendingSplice {
10233
10267
our_funding_contribution: our_funding_contribution_satoshis,
10234
10268
funding: None,
10269
+ pending_funding: vec![],
10235
10270
sent_funding_txid: None,
10236
10271
received_funding_txid: None,
10237
10272
});
@@ -10348,7 +10383,7 @@ where
10348
10383
10349
10384
if let Some(sent_funding_txid) = pending_splice.sent_funding_txid {
10350
10385
if sent_funding_txid == msg.splice_txid {
10351
- if let Some(funding) = self
10386
+ if let Some(funding) = pending_splice
10352
10387
.pending_funding
10353
10388
.iter_mut()
10354
10389
.find(|funding| funding.get_funding_txid() == Some(sent_funding_txid))
@@ -10547,7 +10582,7 @@ where
10547
10582
F::Target: FeeEstimator,
10548
10583
{
10549
10584
core::iter::once(&self.funding)
10550
- .chain(self.pending_funding.iter())
10585
+ .chain(self.pending_funding() .iter())
10551
10586
.map(|funding| self.context.get_available_balances_for_scope(funding, fee_estimator))
10552
10587
.reduce(|acc, e| {
10553
10588
AvailableBalances {
@@ -10594,7 +10629,7 @@ where
10594
10629
}
10595
10630
self.context.resend_order = RAACommitmentOrder::RevokeAndACKFirst;
10596
10631
10597
- let update = if self.pending_funding.is_empty() {
10632
+ let update = if self.pending_funding() .is_empty() {
10598
10633
let (htlcs_ref, counterparty_commitment_tx) =
10599
10634
self.build_commitment_no_state_update(&self.funding, logger);
10600
10635
let htlc_outputs = htlcs_ref.into_iter()
@@ -10617,7 +10652,7 @@ where
10617
10652
} else {
10618
10653
let mut htlc_data = None;
10619
10654
let commitment_txs = core::iter::once(&self.funding)
10620
- .chain(self.pending_funding.iter())
10655
+ .chain(self.pending_funding() .iter())
10621
10656
.map(|funding| {
10622
10657
let (htlcs_ref, counterparty_commitment_tx) =
10623
10658
self.build_commitment_no_state_update(funding, logger);
@@ -10699,7 +10734,7 @@ where
10699
10734
L::Target: Logger,
10700
10735
{
10701
10736
core::iter::once(&self.funding)
10702
- .chain(self.pending_funding.iter())
10737
+ .chain(self.pending_funding() .iter())
10703
10738
.map(|funding| self.send_commitment_no_state_update_for_funding(funding, logger))
10704
10739
.collect::<Result<Vec<_>, ChannelError>>()
10705
10740
}
@@ -11476,7 +11511,6 @@ where
11476
11511
11477
11512
let mut channel = FundedChannel {
11478
11513
funding: self.funding,
11479
- pending_funding: vec![],
11480
11514
context: self.context,
11481
11515
interactive_tx_signing_session: None,
11482
11516
holder_commitment_point,
@@ -11768,7 +11802,6 @@ where
11768
11802
// `ChannelMonitor`.
11769
11803
let mut channel = FundedChannel {
11770
11804
funding: self.funding,
11771
- pending_funding: vec![],
11772
11805
context: self.context,
11773
11806
interactive_tx_signing_session: None,
11774
11807
holder_commitment_point,
@@ -12936,7 +12969,6 @@ where
12936
12969
let mut next_holder_commitment_point_opt: Option<PublicKey> = None;
12937
12970
let mut is_manual_broadcast = None;
12938
12971
12939
- let mut pending_funding = Some(Vec::new());
12940
12972
let mut historical_scids = Some(Vec::new());
12941
12973
12942
12974
let mut interactive_tx_signing_session: Option<InteractiveTxSigningSession> = None;
@@ -13160,7 +13192,6 @@ where
13160
13192
short_channel_id,
13161
13193
minimum_depth_override,
13162
13194
},
13163
- pending_funding: pending_funding.unwrap(),
13164
13195
context: ChannelContext {
13165
13196
user_id,
13166
13197
0 commit comments