@@ -1913,7 +1913,11 @@ struct PendingSplice {
1913
1913
/// Set when splice_ack has been processed (on the initiator side),
1914
1914
/// used to prevent processing of multiple splice_ack's.
1915
1915
awaiting_splice_ack: bool,
1916
- pub refunding_scope: Option<RefundingScope>,
1916
+ funding_scope: Option<FundingScope>,
1917
+ funding_negotiation_context: Option<FundingNegotiationContext>,
1918
+ /// The current interactive transaction construction session under negotiation.
1919
+ interactive_tx_constructor: Option<InteractiveTxConstructor>,
1920
+ interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
1917
1921
}
1918
1922
1919
1923
#[cfg(splicing)]
@@ -2433,7 +2437,10 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
2433
2437
#[cfg(splicing)]
2434
2438
struct FundedChannelRefundingWrapper<'a, SP: Deref> where SP::Target: SignerProvider {
2435
2439
channel_context: &'a mut ChannelContext<SP>,
2436
- refunding_scope: &'a mut RefundingScope,
2440
+ funding_scope: &'a mut FundingScope,
2441
+ funding_negotiation_context: &'a mut FundingNegotiationContext,
2442
+ interactive_tx_constructor: &'a mut Option<InteractiveTxConstructor>,
2443
+ interactive_tx_signing_session: &'a mut Option<InteractiveTxSigningSession>,
2437
2444
/// For accessing commitment transaction number
2438
2445
holder_commitment_point: &'a HolderCommitmentPoint,
2439
2446
}
@@ -2454,28 +2461,28 @@ impl<'a, SP: Deref> ChannelContextProvider<SP> for FundedChannelRefundingWrapper
2454
2461
#[cfg(splicing)]
2455
2462
impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper<'a, SP> where SP::Target: SignerProvider {
2456
2463
#[inline]
2457
- fn pending_funding (&self) -> &FundingScope {
2458
- &self.refunding_scope.pending_funding
2464
+ fn funding_scope (&self) -> &FundingScope {
2465
+ &self.funding_scope
2459
2466
}
2460
2467
2461
2468
#[inline]
2462
- fn pending_funding_mut (&mut self) -> &mut FundingScope {
2463
- &mut self.refunding_scope.pending_funding
2469
+ fn funding_context_mut (&mut self) -> &mut FundingScope {
2470
+ &mut self.funding_scope
2464
2471
}
2465
2472
2466
2473
#[inline]
2467
- fn pending_funding_and_context_mut (&mut self) -> (&FundingScope, &mut ChannelContext<SP>) {
2468
- (&self.refunding_scope.pending_funding , &mut self.channel_context)
2474
+ fn funding_and_context_mut (&mut self) -> (&FundingScope, &mut ChannelContext<SP>) {
2475
+ (&self.funding_scope , &mut self.channel_context)
2469
2476
}
2470
2477
2471
2478
#[inline]
2472
2479
fn funding_negotiation_context(&self) -> &FundingNegotiationContext {
2473
- &self.refunding_scope.pending_funding_negotiation_context
2480
+ &self.funding_negotiation_context
2474
2481
}
2475
2482
2476
2483
#[inline]
2477
2484
fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext {
2478
- &mut self.refunding_scope.pending_funding_negotiation_context
2485
+ &mut self.funding_negotiation_context
2479
2486
}
2480
2487
2481
2488
fn current_holder_transaction_number(&self) -> u64 {
@@ -2484,17 +2491,17 @@ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper
2484
2491
2485
2492
#[inline]
2486
2493
fn interactive_tx_constructor(&self) -> Option<&InteractiveTxConstructor> {
2487
- self.refunding_scope.pending_interactive_tx_constructor .as_ref()
2494
+ self.interactive_tx_constructor .as_ref()
2488
2495
}
2489
2496
2490
2497
#[inline]
2491
2498
fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
2492
- &mut self.refunding_scope.pending_interactive_tx_constructor
2499
+ &mut self.interactive_tx_constructor
2493
2500
}
2494
2501
2495
2502
#[inline]
2496
2503
fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession> {
2497
- &mut self.refunding_scope.pending_interactive_tx_signing_session
2504
+ &mut self.interactive_tx_signing_session
2498
2505
}
2499
2506
2500
2507
fn is_splice(&self) -> bool { true }
@@ -2503,9 +2510,9 @@ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper
2503
2510
/// A channel struct implementing this trait can perform V2 transaction negotiation,
2504
2511
/// either at channel open or during splicing.
2505
2512
pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> where SP::Target: SignerProvider {
2506
- fn pending_funding (&self) -> &FundingScope;
2507
- fn pending_funding_mut (&mut self) -> &mut FundingScope;
2508
- fn pending_funding_and_context_mut (&mut self) -> (&FundingScope, &mut ChannelContext<SP>);
2513
+ fn funding_scope (&self) -> &FundingScope;
2514
+ fn funding_context_mut (&mut self) -> &mut FundingScope;
2515
+ fn funding_and_context_mut (&mut self) -> (&FundingScope, &mut ChannelContext<SP>);
2509
2516
fn funding_negotiation_context(&self) -> &FundingNegotiationContext;
2510
2517
fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext;
2511
2518
fn current_holder_transaction_number(&self) -> u64;
@@ -2548,15 +2555,15 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2548
2555
let mut funding_outputs = Vec::new();
2549
2556
let mut expected_remote_shared_funding_output = None;
2550
2557
2551
- let pending_funding = self.pending_funding ();
2558
+ let funding_scope = self.funding_scope ();
2552
2559
2553
2560
let shared_funding_output = TxOut {
2554
- value: Amount::from_sat(pending_funding .get_value_satoshis()),
2555
- script_pubkey: pending_funding .get_funding_redeemscript().to_p2wsh(),
2561
+ value: Amount::from_sat(funding_scope .get_value_satoshis()),
2562
+ script_pubkey: funding_scope .get_funding_redeemscript().to_p2wsh(),
2556
2563
};
2557
2564
2558
2565
let funding_negotiation_context = &self.funding_negotiation_context();
2559
- if pending_funding .is_outbound() {
2566
+ if funding_scope .is_outbound() {
2560
2567
funding_outputs.push(
2561
2568
OutputOwned::Shared(SharedOwnedOutput::new(
2562
2569
shared_funding_output, funding_negotiation_context.our_funding_satoshis,
@@ -2575,7 +2582,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2575
2582
.map_err(|_err| AbortReason::InternalError("Error getting destination script"))?
2576
2583
};
2577
2584
let change_value_opt = calculate_change_output_value(
2578
- pending_funding .is_outbound(), funding_negotiation_context.our_funding_satoshis,
2585
+ funding_scope .is_outbound(), funding_negotiation_context.our_funding_satoshis,
2579
2586
&funding_inputs, &funding_outputs,
2580
2587
funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2581
2588
change_script.minimal_non_dust().to_sat(),
@@ -2601,7 +2608,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2601
2608
counterparty_node_id: self.context().counterparty_node_id,
2602
2609
channel_id: self.context().channel_id(),
2603
2610
feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2604
- is_initiator: pending_funding .is_outbound(),
2611
+ is_initiator: funding_scope .is_outbound(),
2605
2612
funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
2606
2613
inputs_to_contribute: funding_inputs,
2607
2614
outputs_to_contribute: funding_outputs,
@@ -2695,12 +2702,12 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2695
2702
let our_funding_satoshis = self.funding_negotiation_context()
2696
2703
.our_funding_satoshis;
2697
2704
let transaction_number = self.current_holder_transaction_number();
2698
- let pending_funding = self.pending_funding ();
2705
+ let funding_scope = self.funding_scope ();
2699
2706
2700
2707
let mut output_index = None;
2701
- let expected_spk = pending_funding .get_funding_redeemscript().to_p2wsh();
2708
+ let expected_spk = funding_scope .get_funding_redeemscript().to_p2wsh();
2702
2709
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2703
- if outp.script_pubkey() == &expected_spk && outp.value() == pending_funding .get_value_satoshis() {
2710
+ if outp.script_pubkey() == &expected_spk && outp.value() == funding_scope .get_value_satoshis() {
2704
2711
if output_index.is_some() {
2705
2712
return Err(ChannelError::Close(
2706
2713
(
@@ -2720,7 +2727,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2720
2727
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2721
2728
)));
2722
2729
};
2723
- self.pending_funding_mut ()
2730
+ self.funding_context_mut ()
2724
2731
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2725
2732
2726
2733
if self.is_splice() {
@@ -2732,16 +2739,16 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2732
2739
}
2733
2740
2734
2741
self.context().assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
2735
- let (funding, context_mut) = self.pending_funding_and_context_mut ();
2742
+ let (funding, context_mut) = self.funding_and_context_mut ();
2736
2743
let commitment_signed = context_mut.get_initial_commitment_signed(&funding, logger);
2737
2744
let commitment_signed = match commitment_signed {
2738
2745
Ok(commitment_signed) => {
2739
- self.pending_funding_mut ()
2746
+ self.funding_context_mut ()
2740
2747
.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2741
2748
commitment_signed
2742
2749
},
2743
2750
Err(err) => {
2744
- self.pending_funding_mut ()
2751
+ self.funding_context_mut ()
2745
2752
.channel_transaction_parameters.funding_outpoint = None;
2746
2753
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2747
2754
},
@@ -2809,17 +2816,17 @@ impl<SP: Deref> ChannelContextProvider<SP> for PendingV2Channel<SP> where SP::Ta
2809
2816
2810
2817
impl<SP: Deref> FundingTxConstructorV2<SP> for PendingV2Channel<SP> where SP::Target: SignerProvider {
2811
2818
#[inline]
2812
- fn pending_funding (&self) -> &FundingScope {
2819
+ fn funding_scope (&self) -> &FundingScope {
2813
2820
&self.funding
2814
2821
}
2815
2822
2816
2823
#[inline]
2817
- fn pending_funding_mut (&mut self) -> &mut FundingScope {
2824
+ fn funding_context_mut (&mut self) -> &mut FundingScope {
2818
2825
&mut self.funding
2819
2826
}
2820
2827
2821
2828
#[inline]
2822
- fn pending_funding_and_context_mut (&mut self) -> (&FundingScope, &mut ChannelContext<SP>) {
2829
+ fn funding_and_context_mut (&mut self) -> (&FundingScope, &mut ChannelContext<SP>) {
2823
2830
(&self.funding, &mut self.context)
2824
2831
}
2825
2832
@@ -2855,18 +2862,6 @@ impl<SP: Deref> FundingTxConstructorV2<SP> for PendingV2Channel<SP> where SP::Ta
2855
2862
fn is_splice(&self) -> bool { false }
2856
2863
}
2857
2864
2858
- /// Data needed during splicing --
2859
- /// when the funding transaction is being renegotiated in a funded channel.
2860
- #[cfg(splicing)]
2861
- struct RefundingScope {
2862
- // Fields belonging for [`PendingV2Channel`], except the context
2863
- pending_funding: FundingScope,
2864
- pending_funding_negotiation_context: FundingNegotiationContext,
2865
- /// The current interactive transaction construction session under negotiation.
2866
- pending_interactive_tx_constructor: Option<InteractiveTxConstructor>,
2867
- pending_interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
2868
- }
2869
-
2870
2865
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2871
2866
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
2872
2867
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
@@ -5425,12 +5420,19 @@ impl<SP: Deref> FundedChannel<SP> where
5425
5420
#[cfg(splicing)]
5426
5421
fn as_renegotiating_funding<'a>(&'a mut self) -> Result<impl FundingTxConstructorV2<SP> + 'a, &'static str> {
5427
5422
if let Some(ref mut pending_splice) = &mut self.pending_splice {
5428
- if let Some(ref mut refunding_scope) = &mut pending_splice.refunding_scope {
5429
- Ok(FundedChannelRefundingWrapper {
5430
- channel_context: &mut self.context,
5431
- refunding_scope,
5432
- holder_commitment_point: &self.holder_commitment_point,
5433
- })
5423
+ if let Some(ref mut funding_scope) = &mut pending_splice.funding_scope {
5424
+ if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
5425
+ Ok(FundedChannelRefundingWrapper {
5426
+ channel_context: &mut self.context,
5427
+ funding_scope,
5428
+ funding_negotiation_context,
5429
+ interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
5430
+ interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
5431
+ holder_commitment_point: &self.holder_commitment_point,
5432
+ })
5433
+ } else {
5434
+ Err("Channel is not refunding")
5435
+ }
5434
5436
} else {
5435
5437
Err("Channel is not refunding")
5436
5438
}
@@ -9003,7 +9005,10 @@ impl<SP: Deref> FundedChannel<SP> where
9003
9005
locktime,
9004
9006
our_funding_inputs: funding_inputs,
9005
9007
awaiting_splice_ack: true, // we await splice_ack
9006
- refunding_scope: None,
9008
+ funding_scope: None,
9009
+ funding_negotiation_context: None,
9010
+ interactive_tx_constructor: None,
9011
+ interactive_tx_signing_session: None,
9007
9012
});
9008
9013
9009
9014
let msg = self.get_splice_init(our_funding_contribution_satoshis, funding_feerate_per_kw, locktime);
@@ -9137,29 +9142,26 @@ impl<SP: Deref> FundedChannel<SP> where
9137
9142
false, // is_outbound
9138
9143
)?;
9139
9144
9140
- let pending_funding = self.funding_scope_for_splice(our_funding_satoshis, post_channel_value);
9145
+ let funding_scope = self.funding_scope_for_splice(our_funding_satoshis, post_channel_value);
9141
9146
9142
- let pending_funding_negotiation_context = FundingNegotiationContext {
9147
+ let funding_negotiation_context = FundingNegotiationContext {
9143
9148
our_funding_satoshis,
9144
9149
their_funding_satoshis: Some(their_funding_satoshis),
9145
9150
funding_tx_locktime: LockTime::from_consensus(msg.locktime),
9146
9151
funding_feerate_sat_per_1000_weight: msg.funding_feerate_per_kw,
9147
9152
our_funding_inputs: Vec::new(),
9148
9153
};
9149
9154
9150
- let refunding_scope = Some(RefundingScope {
9151
- pending_funding,
9152
- pending_funding_negotiation_context,
9153
- pending_interactive_tx_constructor: None,
9154
- pending_interactive_tx_signing_session: None,
9155
- });
9156
9155
self.pending_splice = Some(PendingSplice {
9157
9156
our_funding_contribution,
9158
9157
funding_feerate_per_kw: msg.funding_feerate_per_kw,
9159
9158
locktime: msg.locktime,
9160
9159
our_funding_inputs: Vec::new(), // inputs go directly to [`FundingNegotiationContext`] above
9161
9160
awaiting_splice_ack: false, // we don't need any additional message for the handshake
9162
- refunding_scope,
9161
+ funding_scope: Some(funding_scope),
9162
+ funding_negotiation_context: Some(funding_negotiation_context),
9163
+ interactive_tx_constructor: None,
9164
+ interactive_tx_signing_session: None,
9163
9165
});
9164
9166
// TODO(splicing): Store msg.funding_pubkey
9165
9167
@@ -9225,31 +9227,28 @@ impl<SP: Deref> FundedChannel<SP> where
9225
9227
true, // is_outbound
9226
9228
)?;
9227
9229
9228
- let pending_funding = self.funding_scope_for_splice(our_funding_satoshis, post_channel_value);
9230
+ let funding_scope = self.funding_scope_for_splice(our_funding_satoshis, post_channel_value);
9229
9231
9230
- let mut pending_funding_negotiation_context = FundingNegotiationContext {
9232
+ let mut funding_negotiation_context = FundingNegotiationContext {
9231
9233
our_funding_satoshis,
9232
9234
their_funding_satoshis: Some(their_funding_satoshis),
9233
9235
funding_tx_locktime: LockTime::from_consensus(pending_splice.locktime),
9234
9236
funding_feerate_sat_per_1000_weight: pending_splice.funding_feerate_per_kw,
9235
9237
our_funding_inputs: Vec::new(), // set below
9236
9238
};
9237
9239
if let Some(ref mut pending_splice_mut) = &mut self.pending_splice {
9238
- pending_funding_negotiation_context .our_funding_inputs = std::mem::take(&mut pending_splice_mut.our_funding_inputs);
9240
+ funding_negotiation_context .our_funding_inputs = std::mem::take(&mut pending_splice_mut.our_funding_inputs);
9239
9241
};
9240
9242
9241
- let refunding_scope = RefundingScope {
9242
- pending_funding,
9243
- pending_funding_negotiation_context,
9244
- pending_interactive_tx_constructor: None,
9245
- pending_interactive_tx_signing_session: None,
9246
- };
9247
9243
let pre_funding_transaction = &self.funding.funding_transaction;
9248
9244
let pre_funding_txo = &self.funding.get_funding_txo();
9249
9245
// We need the current funding tx as an extra input
9250
9246
let prev_funding_input = Self::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
9251
9247
if let Some(ref mut pending_splice) = &mut self.pending_splice {
9252
- pending_splice.refunding_scope = Some(refunding_scope);
9248
+ pending_splice.funding_scope = Some(funding_scope);
9249
+ pending_splice.funding_negotiation_context = Some(funding_negotiation_context);
9250
+ pending_splice.interactive_tx_constructor = None;
9251
+ pending_splice.interactive_tx_signing_session = None;
9253
9252
debug_assert!(pending_splice.awaiting_splice_ack);
9254
9253
pending_splice.awaiting_splice_ack = false;
9255
9254
} else {
@@ -9307,10 +9306,10 @@ impl<SP: Deref> FundedChannel<SP> where
9307
9306
// NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
9308
9307
// );
9309
9308
if let Some(pending_splice) = &self.pending_splice {
9310
- if let Some(refund ) = &pending_splice.refunding_scope {
9309
+ if let Some(funding_scope ) = &pending_splice.funding_scope {
9311
9310
let old_value = self.funding.get_value_satoshis();
9312
9311
log_info!(logger, "Splicing process started, new channel value {}, old {}, outgoing {}, channel_id {}",
9313
- refund.pending_funding .get_value_satoshis(), old_value, is_outgoing, self.context().channel_id);
9312
+ funding_scope .get_value_satoshis(), old_value, is_outgoing, self.context().channel_id);
9314
9313
}
9315
9314
}
9316
9315
}
0 commit comments