@@ -2438,90 +2438,16 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
24382438/// - [`FundedChannel`], when splicing.
24392439#[cfg(splicing)]
24402440struct 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,
24432443 funding_negotiation_context: &'a mut FundingNegotiationContext,
24442444 interactive_tx_constructor: &'a mut Option<InteractiveTxConstructor>,
24452445 interactive_tx_signing_session: &'a mut Option<InteractiveTxSigningSession>,
24462446 holder_commitment_transaction_number: u64,
2447+ is_splice: bool,
24472448}
24482449
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 {
25252451 /// Prepare and start interactive transaction negotiation.
25262452 /// `change_destination_opt` - Optional destination for optional change; if None,
25272453 /// default destination address is used.
@@ -2534,17 +2460,16 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
25342460 ) -> Result<Option<InteractiveTxMessageSend>, AbortReason>
25352461 where ES::Target: EntropySource
25362462 {
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(_)));
25392465 } else {
2540- debug_assert!(matches!(self.context() .channel_state, ChannelState::NegotiatingFunding(_)));
2466+ debug_assert!(matches!(self.context.channel_state, ChannelState::NegotiatingFunding(_)));
25412467 }
25422468
2543- debug_assert!(self.interactive_tx_constructor() .is_none());
2469+ debug_assert!(self.interactive_tx_constructor.is_none());
25442470
25452471 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);
25482473
25492474 if let Some(prev_funding_input) = prev_funding_input {
25502475 funding_inputs.push(prev_funding_input);
@@ -2556,18 +2481,15 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
25562481 let mut funding_outputs = Vec::new();
25572482 let mut expected_remote_shared_funding_output = None;
25582483
2559- let funding_scope = self.funding_scope();
2560-
25612484 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(),
25642487 };
25652488
2566- let funding_negotiation_context = &self.funding_negotiation_context();
2567- if funding_scope.is_outbound() {
2489+ if self.funding.is_outbound() {
25682490 funding_outputs.push(
25692491 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,
25712493 ))
25722494 );
25732495 } else {
@@ -2579,13 +2501,13 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
25792501 let change_script = if let Some(script) = change_destination_opt {
25802502 script
25812503 } else {
2582- signer_provider.get_destination_script(self.context() .channel_keys_id)
2504+ signer_provider.get_destination_script(self.context.channel_keys_id)
25832505 .map_err(|_err| AbortReason::InternalError("Error getting destination script"))?
25842506 };
25852507 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,
25872509 &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,
25892511 change_script.minimal_non_dust().to_sat(),
25902512 )?;
25912513 if let Some(change_value) = change_value_opt {
@@ -2594,10 +2516,10 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
25942516 script_pubkey: change_script,
25952517 };
25962518 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);
25982520 let change_value_decreased_with_fee = change_value.saturating_sub(change_output_fee);
25992521 // 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 {
26012523 change_output.value = Amount::from_sat(change_value_decreased_with_fee);
26022524 funding_outputs.push(OutputOwned::Single(change_output));
26032525 }
@@ -2606,70 +2528,69 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
26062528 let constructor_args = InteractiveTxConstructorArgs {
26072529 entropy_source,
26082530 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,
26142536 inputs_to_contribute: funding_inputs,
26152537 outputs_to_contribute: funding_outputs,
26162538 expected_remote_shared_funding_output,
26172539 };
26182540 let mut tx_constructor = InteractiveTxConstructor::new(constructor_args)?;
26192541 let msg = tx_constructor.take_initiator_first_message();
26202542
2621- *self.interactive_tx_constructor_mut() = Some(tx_constructor);
2543+ *self.interactive_tx_constructor = Some(tx_constructor);
26222544
26232545 Ok(msg)
26242546 }
26252547
26262548 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 {
26282550 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())),
26302552 None => Err(msgs::TxAbort {
2631- channel_id: self.context() .channel_id(),
2553+ channel_id: self.context.channel_id(),
26322554 data: b"No interactive transaction negotiation in progress".to_vec()
26332555 }),
26342556 })
26352557 }
26362558
26372559 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 {
26392561 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())),
26412563 None => Err(msgs::TxAbort {
2642- channel_id: self.context() .channel_id(),
2564+ channel_id: self.context.channel_id(),
26432565 data: b"No interactive transaction negotiation in progress".to_vec()
26442566 }),
26452567 })
26462568 }
26472569
26482570 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 {
26502572 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())),
26522574 None => Err(msgs::TxAbort {
2653- channel_id: self.context() .channel_id(),
2575+ channel_id: self.context.channel_id(),
26542576 data: b"No interactive transaction negotiation in progress".to_vec()
26552577 }),
26562578 })
26572579 }
26582580
26592581 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 {
26612583 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())),
26632585 None => Err(msgs::TxAbort {
2664- channel_id: self.context() .channel_id(),
2586+ channel_id: self.context.channel_id(),
26652587 data: b"No interactive transaction negotiation in progress".to_vec()
26662588 }),
26672589 })
26682590 }
26692591
26702592 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 {
26732594 Some(tx_constructor) => tx_constructor,
26742595 None => {
26752596 let tx_abort = msgs::TxAbort {
@@ -2688,7 +2609,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
26882609 };
26892610
26902611 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());
26922613 };
26932614
26942615 HandleTxCompleteResult(Ok(tx_complete))
@@ -2700,15 +2621,13 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
27002621 where
27012622 L::Target: Logger
27022623 {
2703- let our_funding_satoshis = self.funding_negotiation_context()
2624+ let our_funding_satoshis = self.funding_negotiation_context
27042625 .our_funding_satoshis;
2705- let transaction_number = self.current_holder_transaction_number();
2706- let funding_scope = self.funding_scope();
27072626
27082627 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();
27102629 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() {
27122631 if output_index.is_some() {
27132632 return Err(ChannelError::Close(
27142633 (
@@ -2728,36 +2647,35 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
27282647 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
27292648 )));
27302649 };
2731- self.funding_context_mut()
2650+ self.funding
27322651 .channel_transaction_parameters.funding_outpoint = Some(outpoint);
27332652
2734- if self.is_splice() {
2653+ if self.is_splice {
27352654 // TODO(splicing) Forced error, as the use case is not complete
27362655 return Err(ChannelError::Close((
27372656 "TODO Forced error, incomplete implementation".into(),
27382657 ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) }
27392658 )));
27402659 }
27412660
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);
27452663 let commitment_signed = match commitment_signed {
27462664 Ok(commitment_signed) => {
2747- self.funding_context_mut()
2665+ self.funding
27482666 .funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
27492667 commitment_signed
27502668 },
27512669 Err(err) => {
2752- self.funding_context_mut()
2670+ self.funding
27532671 .channel_transaction_parameters.funding_outpoint = None;
27542672 return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
27552673 },
27562674 };
27572675
27582676 let funding_ready_for_sig_event = if signing_session.local_inputs_count() == 0 {
27592677 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() {
27612679 debug_assert!(
27622680 false,
27632681 "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
27932711 )));
27942712 };
27952713
2796- self.context_mut() .channel_state = ChannelState::FundingNegotiated;
2714+ self.context .channel_state = ChannelState::FundingNegotiated;
27972715
27982716 // 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);
28012719
28022720 Ok((commitment_signed, funding_ready_for_sig_event))
28032721 }
@@ -5369,17 +5287,18 @@ impl<SP: Deref> FundedChannel<SP> where
53695287{
53705288 /// If we are in splicing/refunding, return a short-lived [`NegotiatingV2ChannelView`].
53715289 #[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> {
53735291 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 {
53755293 if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
53765294 Ok(NegotiatingV2ChannelView {
5377- channel_context : &mut self.context,
5378- funding_scope ,
5295+ context : &mut self.context,
5296+ funding ,
53795297 funding_negotiation_context,
53805298 interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
53815299 interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
53825300 holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
5301+ is_splice: true,
53835302 })
53845303 } else {
53855304 Err("Channel is not refunding")
@@ -10919,15 +10838,15 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1091910838 }
1092010839
1092110840 /// Return a short-lived [`NegotiatingV2ChannelView`].
10922- #[cfg(splicing)]
10923- fn as_negotiating_channel<'a>(&'a mut self) -> impl FundingTxConstructorV2<SP> + 'a {
10841+ fn as_negotiating_channel(&mut self) -> NegotiatingV2ChannelView<SP> {
1092410842 NegotiatingV2ChannelView {
10925- channel_context : &mut self.context,
10926- funding_scope : &mut self.funding,
10843+ context : &mut self.context,
10844+ funding : &mut self.funding,
1092710845 funding_negotiation_context: &mut self.funding_negotiation_context,
1092810846 interactive_tx_constructor: &mut self.interactive_tx_constructor,
1092910847 interactive_tx_signing_session: &mut self.interactive_tx_signing_session,
1093010848 holder_commitment_transaction_number: self.unfunded_context.transaction_number(),
10849+ is_splice: false,
1093110850 }
1093210851 }
1093310852}
0 commit comments