@@ -2438,90 +2438,16 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
2438
2438
/// - [`FundedChannel`], when splicing.
2439
2439
#[cfg(splicing)]
2440
2440
struct NegotiatingV2ChannelView<'a, SP: Deref> where SP::Target: SignerProvider {
2441
- channel_context : &'a mut ChannelContext<SP>,
2442
- funding_scope : &'a mut FundingScope,
2441
+ context : &'a mut ChannelContext<SP>,
2442
+ funding : &'a mut FundingScope,
2443
2443
funding_negotiation_context: &'a mut FundingNegotiationContext,
2444
2444
interactive_tx_constructor: &'a mut Option<InteractiveTxConstructor>,
2445
2445
interactive_tx_signing_session: &'a mut Option<InteractiveTxSigningSession>,
2446
2446
holder_commitment_transaction_number: u64,
2447
+ is_splice: bool,
2447
2448
}
2448
2449
2449
- #[cfg(splicing)]
2450
- impl<'a, SP: Deref> ChannelContextProvider<SP> for NegotiatingV2ChannelView<'a, SP> where SP::Target: SignerProvider {
2451
- #[inline]
2452
- fn context(&self) -> &ChannelContext<SP> {
2453
- &self.channel_context
2454
- }
2455
-
2456
- #[inline]
2457
- fn context_mut(&mut self) -> &mut ChannelContext<SP> {
2458
- &mut self.channel_context
2459
- }
2460
- }
2461
-
2462
- #[cfg(splicing)]
2463
- impl<'a, SP: Deref> FundingTxConstructorV2<SP> for NegotiatingV2ChannelView<'a, SP> where SP::Target: SignerProvider {
2464
- #[inline]
2465
- fn funding_scope(&self) -> &FundingScope {
2466
- &self.funding_scope
2467
- }
2468
-
2469
- #[inline]
2470
- fn funding_context_mut(&mut self) -> &mut FundingScope {
2471
- &mut self.funding_scope
2472
- }
2473
-
2474
- #[inline]
2475
- fn funding_and_context_mut(&mut self) -> (&FundingScope, &mut ChannelContext<SP>) {
2476
- (&self.funding_scope, &mut self.channel_context)
2477
- }
2478
-
2479
- #[inline]
2480
- fn funding_negotiation_context(&self) -> &FundingNegotiationContext {
2481
- &self.funding_negotiation_context
2482
- }
2483
-
2484
- #[inline]
2485
- fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext {
2486
- &mut self.funding_negotiation_context
2487
- }
2488
-
2489
- fn current_holder_transaction_number(&self) -> u64 {
2490
- self.holder_commitment_transaction_number
2491
- }
2492
-
2493
- #[inline]
2494
- fn interactive_tx_constructor(&self) -> Option<&InteractiveTxConstructor> {
2495
- self.interactive_tx_constructor.as_ref()
2496
- }
2497
-
2498
- #[inline]
2499
- fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
2500
- &mut self.interactive_tx_constructor
2501
- }
2502
-
2503
- #[inline]
2504
- fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession> {
2505
- &mut self.interactive_tx_signing_session
2506
- }
2507
-
2508
- fn is_splice(&self) -> bool { true }
2509
- }
2510
-
2511
- /// A channel struct implementing this trait can perform V2 transaction negotiation,
2512
- /// either at channel open or during splicing.
2513
- pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> where SP::Target: SignerProvider {
2514
- fn funding_scope(&self) -> &FundingScope;
2515
- fn funding_context_mut(&mut self) -> &mut FundingScope;
2516
- fn funding_and_context_mut(&mut self) -> (&FundingScope, &mut ChannelContext<SP>);
2517
- fn funding_negotiation_context(&self) -> &FundingNegotiationContext;
2518
- fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext;
2519
- fn current_holder_transaction_number(&self) -> u64;
2520
- fn interactive_tx_constructor(&self) -> Option<&InteractiveTxConstructor>;
2521
- fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor>;
2522
- fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession>;
2523
- fn is_splice(&self) -> bool;
2524
-
2450
+ impl<'a, SP: Deref> NegotiatingV2ChannelView<'a, SP> where SP::Target: SignerProvider {
2525
2451
/// Prepare and start interactive transaction negotiation.
2526
2452
/// `change_destination_opt` - Optional destination for optional change; if None,
2527
2453
/// default destination address is used.
@@ -2534,17 +2460,16 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2534
2460
) -> Result<Option<InteractiveTxMessageSend>, AbortReason>
2535
2461
where ES::Target: EntropySource
2536
2462
{
2537
- if self.is_splice() {
2538
- debug_assert!(matches!(self.context() .channel_state, ChannelState::ChannelReady(_)));
2463
+ if self.is_splice {
2464
+ debug_assert!(matches!(self.context.channel_state, ChannelState::ChannelReady(_)));
2539
2465
} else {
2540
- debug_assert!(matches!(self.context() .channel_state, ChannelState::NegotiatingFunding(_)));
2466
+ debug_assert!(matches!(self.context.channel_state, ChannelState::NegotiatingFunding(_)));
2541
2467
}
2542
2468
2543
- debug_assert!(self.interactive_tx_constructor() .is_none());
2469
+ debug_assert!(self.interactive_tx_constructor.is_none());
2544
2470
2545
2471
let mut funding_inputs = Vec::new();
2546
- let funding_negotiation_context_mut = self.funding_negotiation_context_mut();
2547
- mem::swap(&mut funding_negotiation_context_mut.our_funding_inputs, &mut funding_inputs);
2472
+ mem::swap(&mut self.funding_negotiation_context.our_funding_inputs, &mut funding_inputs);
2548
2473
2549
2474
if let Some(prev_funding_input) = prev_funding_input {
2550
2475
funding_inputs.push(prev_funding_input);
@@ -2556,18 +2481,15 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2556
2481
let mut funding_outputs = Vec::new();
2557
2482
let mut expected_remote_shared_funding_output = None;
2558
2483
2559
- let funding_scope = self.funding_scope();
2560
-
2561
2484
let shared_funding_output = TxOut {
2562
- value: Amount::from_sat(funding_scope .get_value_satoshis()),
2563
- script_pubkey: funding_scope .get_funding_redeemscript().to_p2wsh(),
2485
+ value: Amount::from_sat(self.funding .get_value_satoshis()),
2486
+ script_pubkey: self.funding .get_funding_redeemscript().to_p2wsh(),
2564
2487
};
2565
2488
2566
- let funding_negotiation_context = &self.funding_negotiation_context();
2567
- if funding_scope.is_outbound() {
2489
+ if self.funding.is_outbound() {
2568
2490
funding_outputs.push(
2569
2491
OutputOwned::Shared(SharedOwnedOutput::new(
2570
- shared_funding_output, funding_negotiation_context.our_funding_satoshis,
2492
+ shared_funding_output, self. funding_negotiation_context.our_funding_satoshis,
2571
2493
))
2572
2494
);
2573
2495
} else {
@@ -2579,13 +2501,13 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2579
2501
let change_script = if let Some(script) = change_destination_opt {
2580
2502
script
2581
2503
} else {
2582
- signer_provider.get_destination_script(self.context() .channel_keys_id)
2504
+ signer_provider.get_destination_script(self.context.channel_keys_id)
2583
2505
.map_err(|_err| AbortReason::InternalError("Error getting destination script"))?
2584
2506
};
2585
2507
let change_value_opt = calculate_change_output_value(
2586
- funding_scope. is_outbound(), funding_negotiation_context.our_funding_satoshis,
2508
+ self.funding. is_outbound(), self. funding_negotiation_context.our_funding_satoshis,
2587
2509
&funding_inputs, &funding_outputs,
2588
- funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2510
+ self. funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2589
2511
change_script.minimal_non_dust().to_sat(),
2590
2512
)?;
2591
2513
if let Some(change_value) = change_value_opt {
@@ -2594,10 +2516,10 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2594
2516
script_pubkey: change_script,
2595
2517
};
2596
2518
let change_output_weight = get_output_weight(&change_output.script_pubkey).to_wu();
2597
- let change_output_fee = fee_for_weight(funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
2519
+ let change_output_fee = fee_for_weight(self. funding_negotiation_context.funding_feerate_sat_per_1000_weight, change_output_weight);
2598
2520
let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
2599
2521
// Check dust limit again
2600
- if change_value_decreased_with_fee > self.context() .holder_dust_limit_satoshis {
2522
+ if change_value_decreased_with_fee > self.context.holder_dust_limit_satoshis {
2601
2523
change_output.value = Amount::from_sat(change_value_decreased_with_fee);
2602
2524
funding_outputs.push(OutputOwned::Single(change_output));
2603
2525
}
@@ -2606,70 +2528,69 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2606
2528
let constructor_args = InteractiveTxConstructorArgs {
2607
2529
entropy_source,
2608
2530
holder_node_id,
2609
- counterparty_node_id: self.context() .counterparty_node_id,
2610
- channel_id: self.context() .channel_id(),
2611
- feerate_sat_per_kw: funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2612
- is_initiator: funding_scope .is_outbound(),
2613
- funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
2531
+ counterparty_node_id: self.context.counterparty_node_id,
2532
+ channel_id: self.context.channel_id(),
2533
+ feerate_sat_per_kw: self. funding_negotiation_context.funding_feerate_sat_per_1000_weight,
2534
+ is_initiator: self.funding .is_outbound(),
2535
+ funding_tx_locktime: self. funding_negotiation_context.funding_tx_locktime,
2614
2536
inputs_to_contribute: funding_inputs,
2615
2537
outputs_to_contribute: funding_outputs,
2616
2538
expected_remote_shared_funding_output,
2617
2539
};
2618
2540
let mut tx_constructor = InteractiveTxConstructor::new(constructor_args)?;
2619
2541
let msg = tx_constructor.take_initiator_first_message();
2620
2542
2621
- *self.interactive_tx_constructor_mut() = Some(tx_constructor);
2543
+ *self.interactive_tx_constructor = Some(tx_constructor);
2622
2544
2623
2545
Ok(msg)
2624
2546
}
2625
2547
2626
2548
fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> InteractiveTxMessageSendResult {
2627
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
2549
+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor {
2628
2550
Some(ref mut tx_constructor) => tx_constructor.handle_tx_add_input(msg).map_err(
2629
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
2551
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2630
2552
None => Err(msgs::TxAbort {
2631
- channel_id: self.context() .channel_id(),
2553
+ channel_id: self.context.channel_id(),
2632
2554
data: b"No interactive transaction negotiation in progress".to_vec()
2633
2555
}),
2634
2556
})
2635
2557
}
2636
2558
2637
2559
fn tx_add_output(&mut self, msg: &msgs::TxAddOutput)-> InteractiveTxMessageSendResult {
2638
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
2560
+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor {
2639
2561
Some(ref mut tx_constructor) => tx_constructor.handle_tx_add_output(msg).map_err(
2640
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
2562
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2641
2563
None => Err(msgs::TxAbort {
2642
- channel_id: self.context() .channel_id(),
2564
+ channel_id: self.context.channel_id(),
2643
2565
data: b"No interactive transaction negotiation in progress".to_vec()
2644
2566
}),
2645
2567
})
2646
2568
}
2647
2569
2648
2570
fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput)-> InteractiveTxMessageSendResult {
2649
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
2571
+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor {
2650
2572
Some(ref mut tx_constructor) => tx_constructor.handle_tx_remove_input(msg).map_err(
2651
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
2573
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2652
2574
None => Err(msgs::TxAbort {
2653
- channel_id: self.context() .channel_id(),
2575
+ channel_id: self.context.channel_id(),
2654
2576
data: b"No interactive transaction negotiation in progress".to_vec()
2655
2577
}),
2656
2578
})
2657
2579
}
2658
2580
2659
2581
fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput)-> InteractiveTxMessageSendResult {
2660
- InteractiveTxMessageSendResult(match self.interactive_tx_constructor_mut() {
2582
+ InteractiveTxMessageSendResult(match self.interactive_tx_constructor {
2661
2583
Some(ref mut tx_constructor) => tx_constructor.handle_tx_remove_output(msg).map_err(
2662
- |reason| reason.into_tx_abort_msg(self.context() .channel_id())),
2584
+ |reason| reason.into_tx_abort_msg(self.context.channel_id())),
2663
2585
None => Err(msgs::TxAbort {
2664
- channel_id: self.context() .channel_id(),
2586
+ channel_id: self.context.channel_id(),
2665
2587
data: b"No interactive transaction negotiation in progress".to_vec()
2666
2588
}),
2667
2589
})
2668
2590
}
2669
2591
2670
2592
fn tx_complete(&mut self, msg: &msgs::TxComplete) -> HandleTxCompleteResult {
2671
- let interactive_tx_constructor = self.interactive_tx_constructor_mut();
2672
- let tx_constructor = match interactive_tx_constructor {
2593
+ let tx_constructor = match self.interactive_tx_constructor {
2673
2594
Some(tx_constructor) => tx_constructor,
2674
2595
None => {
2675
2596
let tx_abort = msgs::TxAbort {
@@ -2688,7 +2609,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2688
2609
};
2689
2610
2690
2611
if let HandleTxCompleteValue::SendTxComplete(_, ref signing_session) = tx_complete {
2691
- self.context_mut() .next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
2612
+ self.context .next_funding_txid = Some(signing_session.unsigned_tx.compute_txid());
2692
2613
};
2693
2614
2694
2615
HandleTxCompleteResult(Ok(tx_complete))
@@ -2700,15 +2621,13 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2700
2621
where
2701
2622
L::Target: Logger
2702
2623
{
2703
- let our_funding_satoshis = self.funding_negotiation_context()
2624
+ let our_funding_satoshis = self.funding_negotiation_context
2704
2625
.our_funding_satoshis;
2705
- let transaction_number = self.current_holder_transaction_number();
2706
- let funding_scope = self.funding_scope();
2707
2626
2708
2627
let mut output_index = None;
2709
- let expected_spk = funding_scope .get_funding_redeemscript().to_p2wsh();
2628
+ let expected_spk = self.funding .get_funding_redeemscript().to_p2wsh();
2710
2629
for (idx, outp) in signing_session.unsigned_tx.outputs().enumerate() {
2711
- if outp.script_pubkey() == &expected_spk && outp.value() == funding_scope .get_value_satoshis() {
2630
+ if outp.script_pubkey() == &expected_spk && outp.value() == self.funding .get_value_satoshis() {
2712
2631
if output_index.is_some() {
2713
2632
return Err(ChannelError::Close(
2714
2633
(
@@ -2728,36 +2647,35 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2728
2647
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
2729
2648
)));
2730
2649
};
2731
- self.funding_context_mut()
2650
+ self.funding
2732
2651
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
2733
2652
2734
- if self.is_splice() {
2653
+ if self.is_splice {
2735
2654
// TODO(splicing) Forced error, as the use case is not complete
2736
2655
return Err(ChannelError::Close((
2737
2656
"TODO Forced error, incomplete implementation".into(),
2738
2657
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
2739
2658
)));
2740
2659
}
2741
2660
2742
- self.context().assert_no_commitment_advancement(transaction_number, "initial commitment_signed");
2743
- let (funding, context_mut) = self.funding_and_context_mut();
2744
- let commitment_signed = context_mut.get_initial_commitment_signed(&funding, logger);
2661
+ self.context.assert_no_commitment_advancement(self.holder_commitment_transaction_number, "initial commitment_signed");
2662
+ let commitment_signed = self.context.get_initial_commitment_signed(&self.funding, logger);
2745
2663
let commitment_signed = match commitment_signed {
2746
2664
Ok(commitment_signed) => {
2747
- self.funding_context_mut()
2665
+ self.funding
2748
2666
.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
2749
2667
commitment_signed
2750
2668
},
2751
2669
Err(err) => {
2752
- self.funding_context_mut()
2670
+ self.funding
2753
2671
.channel_transaction_parameters.funding_outpoint = None;
2754
2672
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
2755
2673
},
2756
2674
};
2757
2675
2758
2676
let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
2759
2677
debug_assert_eq!(our_funding_satoshis, 0);
2760
- if signing_session.provide_holder_witnesses(self.context() .channel_id, Vec::new()).is_err() {
2678
+ if signing_session.provide_holder_witnesses(self.context.channel_id, Vec::new()).is_err() {
2761
2679
debug_assert!(
2762
2680
false,
2763
2681
"Zero inputs were provided & zero witnesses were provided, but a count mismatch was somehow found",
@@ -2793,11 +2711,11 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
2793
2711
)));
2794
2712
};
2795
2713
2796
- self.context_mut() .channel_state = ChannelState::FundingNegotiated;
2714
+ self.context .channel_state = ChannelState::FundingNegotiated;
2797
2715
2798
2716
// Clear the interactive transaction constructor
2799
- *self.interactive_tx_constructor_mut() = None;
2800
- *self.interactive_tx_signing_session_mut() = Some(signing_session);
2717
+ *self.interactive_tx_constructor = None;
2718
+ *self.interactive_tx_signing_session = Some(signing_session);
2801
2719
2802
2720
Ok((commitment_signed, funding_ready_for_sig_event))
2803
2721
}
@@ -5369,17 +5287,18 @@ impl<SP: Deref> FundedChannel<SP> where
5369
5287
{
5370
5288
/// If we are in splicing/refunding, return a short-lived [`NegotiatingV2ChannelView`].
5371
5289
#[cfg(splicing)]
5372
- fn as_renegotiating_channel<'a>(&'a mut self) -> Result<impl FundingTxConstructorV2 <SP> + 'a , &'static str> {
5290
+ fn as_renegotiating_channel(& mut self) -> Result<NegotiatingV2ChannelView <SP>, &'static str> {
5373
5291
if let Some(ref mut pending_splice) = &mut self.pending_splice {
5374
- if let Some(ref mut funding_scope ) = &mut pending_splice.funding_scope {
5292
+ if let Some(ref mut funding ) = &mut pending_splice.funding_scope {
5375
5293
if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
5376
5294
Ok(NegotiatingV2ChannelView {
5377
- channel_context : &mut self.context,
5378
- funding_scope ,
5295
+ context : &mut self.context,
5296
+ funding ,
5379
5297
funding_negotiation_context,
5380
5298
interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
5381
5299
interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
5382
5300
holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
5301
+ is_splice: true,
5383
5302
})
5384
5303
} else {
5385
5304
Err("Channel is not refunding")
@@ -10920,14 +10839,15 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
10920
10839
10921
10840
/// Return a short-lived [`NegotiatingV2ChannelView`].
10922
10841
#[cfg(splicing)]
10923
- fn as_negotiating_channel<'a>(&'a mut self) -> impl FundingTxConstructorV2 <SP> + 'a {
10842
+ fn as_negotiating_channel(& mut self) -> NegotiatingV2ChannelView <SP> {
10924
10843
NegotiatingV2ChannelView {
10925
- channel_context : &mut self.context,
10926
- funding_scope : &mut self.funding,
10844
+ context : &mut self.context,
10845
+ funding : &mut self.funding,
10927
10846
funding_negotiation_context: &mut self.funding_negotiation_context,
10928
10847
interactive_tx_constructor: &mut self.interactive_tx_constructor,
10929
10848
interactive_tx_signing_session: &mut self.interactive_tx_signing_session,
10930
10849
holder_commitment_transaction_number: self.unfunded_context.transaction_number(),
10850
+ is_splice: false,
10931
10851
}
10932
10852
}
10933
10853
}
0 commit comments