@@ -1457,49 +1457,49 @@ impl<SP: Deref> Channel<SP> where
14571457
14581458 pub fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> Result<InteractiveTxMessageSendResult, &'static str> {
14591459 match &mut self.phase {
1460- ChannelPhase::UnfundedV2(chan) => Ok(chan.tx_add_input(msg)),
1460+ ChannelPhase::UnfundedV2(chan) => Ok(chan.as_negotiating_channel(). tx_add_input(msg)),
14611461 #[cfg(splicing)]
1462- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1462+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
14631463 .tx_add_input(msg)),
14641464 _ => Err("Got tx_add_input in an invalid phase"),
14651465 }
14661466 }
14671467
14681468 pub fn tx_add_output(&mut self, msg: &msgs::TxAddOutput) -> Result<InteractiveTxMessageSendResult, &'static str> {
14691469 match &mut self.phase {
1470- ChannelPhase::UnfundedV2(chan) => Ok(chan.tx_add_output(msg)),
1470+ ChannelPhase::UnfundedV2(chan) => Ok(chan.as_negotiating_channel(). tx_add_output(msg)),
14711471 #[cfg(splicing)]
1472- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1472+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
14731473 .tx_add_output(msg)),
14741474 _ => Err("Got tx_add_output in an invalid phase"),
14751475 }
14761476 }
14771477
14781478 pub fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput) -> Result<InteractiveTxMessageSendResult, &'static str> {
14791479 match &mut self.phase {
1480- ChannelPhase::UnfundedV2(chan) => Ok(chan.tx_remove_input(msg)),
1480+ ChannelPhase::UnfundedV2(chan) => Ok(chan.as_negotiating_channel(). tx_remove_input(msg)),
14811481 #[cfg(splicing)]
1482- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1482+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
14831483 .tx_remove_input(msg)),
14841484 _ => Err("Got tx_remove_input in an invalid phase"),
14851485 }
14861486 }
14871487
14881488 pub fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput) -> Result<InteractiveTxMessageSendResult, &'static str> {
14891489 match &mut self.phase {
1490- ChannelPhase::UnfundedV2(chan) => Ok(chan.tx_remove_output(msg)),
1490+ ChannelPhase::UnfundedV2(chan) => Ok(chan.as_negotiating_channel(). tx_remove_output(msg)),
14911491 #[cfg(splicing)]
1492- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1492+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
14931493 .tx_remove_output(msg)),
14941494 _ => Err("Got tx_remove_output in an invalid phase"),
14951495 }
14961496 }
14971497
14981498 pub fn tx_complete(&mut self, msg: &msgs::TxComplete) -> Result<HandleTxCompleteResult, &'static str> {
14991499 match &mut self.phase {
1500- ChannelPhase::UnfundedV2(chan) => Ok(chan.tx_complete(msg)),
1500+ ChannelPhase::UnfundedV2(chan) => Ok(chan.as_negotiating_channel(). tx_complete(msg)),
15011501 #[cfg(splicing)]
1502- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1502+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
15031503 .tx_complete(msg)),
15041504 _ => Err("Got tx_complete in an invalid phase"),
15051505 }
@@ -1545,13 +1545,13 @@ impl<SP: Deref> Channel<SP> where
15451545 match self.phase {
15461546 ChannelPhase::UnfundedV2(ref mut chan) => {
15471547 let logger = WithChannelContext::from(logger, &chan.context, None);
1548- let (commitment_signed, event) = chan.funding_tx_constructed(signing_session, &&logger)?;
1548+ let (commitment_signed, event) = chan.as_negotiating_channel(). funding_tx_constructed(signing_session, &&logger)?;
15491549 Ok((commitment_signed, event))
15501550 }
15511551 #[cfg(splicing)]
15521552 ChannelPhase::Funded(ref mut chan) => {
15531553 let logger = WithChannelContext::from(logger, &chan.context, None);
1554- let (commitment_signed, event) = chan.as_renegotiating_funding ()
1554+ let (commitment_signed, event) = chan.as_renegotiating_channel ()
15551555 .map_err(|err| ChannelError::Warn(err.into()))?
15561556 .funding_tx_constructed(signing_session, &&logger)?;
15571557 Ok((commitment_signed, event))
@@ -2432,21 +2432,22 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
24322432 }
24332433}
24342434
2435- /// A temporary internal struct, used to return something from FundedChannel
2436- /// that implements [`FundingTxConstructorV2`], but only when it has the parts for it.
2435+ /// A short-lived subset view of a channel, used for V2 funding negotiation or re-negotiation.
2436+ /// Can be produced by:
2437+ /// - [`PendingV2Channel`], at V2 channel open, and
2438+ /// - [`FundedChannel`], when splicing.
24372439#[cfg(splicing)]
2438- struct FundedChannelRefundingWrapper <'a, SP: Deref> where SP::Target: SignerProvider {
2440+ struct NegotiatingV2ChannelView <'a, SP: Deref> where SP::Target: SignerProvider {
24392441 channel_context: &'a mut ChannelContext<SP>,
24402442 funding_scope: &'a mut FundingScope,
24412443 funding_negotiation_context: &'a mut FundingNegotiationContext,
24422444 interactive_tx_constructor: &'a mut Option<InteractiveTxConstructor>,
24432445 interactive_tx_signing_session: &'a mut Option<InteractiveTxSigningSession>,
2444- /// For accessing commitment transaction number
2445- holder_commitment_point: &'a HolderCommitmentPoint,
2446+ holder_commitment_transaction_number: u64,
24462447}
24472448
24482449#[cfg(splicing)]
2449- impl<'a, SP: Deref> ChannelContextProvider<SP> for FundedChannelRefundingWrapper <'a, SP> where SP::Target: SignerProvider {
2450+ impl<'a, SP: Deref> ChannelContextProvider<SP> for NegotiatingV2ChannelView <'a, SP> where SP::Target: SignerProvider {
24502451 #[inline]
24512452 fn context(&self) -> &ChannelContext<SP> {
24522453 &self.channel_context
@@ -2459,7 +2460,7 @@ impl<'a, SP: Deref> ChannelContextProvider<SP> for FundedChannelRefundingWrapper
24592460}
24602461
24612462#[cfg(splicing)]
2462- impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper <'a, SP> where SP::Target: SignerProvider {
2463+ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for NegotiatingV2ChannelView <'a, SP> where SP::Target: SignerProvider {
24632464 #[inline]
24642465 fn funding_scope(&self) -> &FundingScope {
24652466 &self.funding_scope
@@ -2486,7 +2487,7 @@ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper
24862487 }
24872488
24882489 fn current_holder_transaction_number(&self) -> u64 {
2489- self.holder_commitment_point.transaction_number()
2490+ self.holder_commitment_transaction_number
24902491 }
24912492
24922493 #[inline]
@@ -2814,54 +2815,6 @@ impl<SP: Deref> ChannelContextProvider<SP> for PendingV2Channel<SP> where SP::Ta
28142815 }
28152816}
28162817
2817- impl<SP: Deref> FundingTxConstructorV2<SP> for PendingV2Channel<SP> where SP::Target: SignerProvider {
2818- #[inline]
2819- fn funding_scope(&self) -> &FundingScope {
2820- &self.funding
2821- }
2822-
2823- #[inline]
2824- fn funding_context_mut(&mut self) -> &mut FundingScope {
2825- &mut self.funding
2826- }
2827-
2828- #[inline]
2829- fn funding_and_context_mut(&mut self) -> (&FundingScope, &mut ChannelContext<SP>) {
2830- (&self.funding, &mut self.context)
2831- }
2832-
2833- #[inline]
2834- fn funding_negotiation_context(&self) -> &FundingNegotiationContext {
2835- &self.funding_negotiation_context
2836- }
2837-
2838- #[inline]
2839- fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext {
2840- &mut self.funding_negotiation_context
2841- }
2842-
2843- fn current_holder_transaction_number(&self) -> u64 {
2844- self.unfunded_context.transaction_number()
2845- }
2846-
2847- #[inline]
2848- fn interactive_tx_constructor(&self) -> Option<&InteractiveTxConstructor> {
2849- self.interactive_tx_constructor.as_ref()
2850- }
2851-
2852- #[inline]
2853- fn interactive_tx_constructor_mut(&mut self) -> &mut Option<InteractiveTxConstructor> {
2854- &mut self.interactive_tx_constructor
2855- }
2856-
2857- #[inline]
2858- fn interactive_tx_signing_session_mut(&mut self) -> &mut Option<InteractiveTxSigningSession> {
2859- &mut self.interactive_tx_signing_session
2860- }
2861-
2862- fn is_splice(&self) -> bool { false }
2863- }
2864-
28652818impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28662819 fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
28672820 fee_estimator: &'a LowerBoundedFeeEstimator<F>,
@@ -5414,21 +5367,19 @@ impl<SP: Deref> FundedChannel<SP> where
54145367 SP::Target: SignerProvider,
54155368 <SP::Target as SignerProvider>::EcdsaSigner: EcdsaChannelSigner
54165369{
5417- /// If we are in splicing/refunding, return something that implements [`FundingTxConstructorV2`],
5418- /// or err otherwise.
5419- /// A [`FundedChannelRefundingWrapper`] is returned.
5370+ /// If we are in splicing/refunding, return a short-lived [`NegotiatingV2ChannelView`].
54205371 #[cfg(splicing)]
5421- fn as_renegotiating_funding <'a>(&'a mut self) -> Result<impl FundingTxConstructorV2<SP> + 'a, &'static str> {
5372+ fn as_renegotiating_channel <'a>(&'a mut self) -> Result<impl FundingTxConstructorV2<SP> + 'a, &'static str> {
54225373 if let Some(ref mut pending_splice) = &mut self.pending_splice {
54235374 if let Some(ref mut funding_scope) = &mut pending_splice.funding_scope {
54245375 if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
5425- Ok(FundedChannelRefundingWrapper {
5376+ Ok(NegotiatingV2ChannelView {
54265377 channel_context: &mut self.context,
54275378 funding_scope,
54285379 funding_negotiation_context,
54295380 interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
54305381 interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
5431- holder_commitment_point: & self.holder_commitment_point,
5382+ holder_commitment_transaction_number: self.holder_commitment_point.transaction_number() ,
54325383 })
54335384 } else {
54345385 Err("Channel is not refunding")
@@ -9078,6 +9029,7 @@ impl<SP: Deref> FundedChannel<SP> where
90789029 Ok(())
90799030 }
90809031
9032+ /// Helper to build the FundingScope for the splicing channel
90819033 #[cfg(splicing)]
90829034 fn funding_scope_for_splice(&self, our_funding_satoshis: u64, post_channel_value: u64) -> FundingScope {
90839035 let post_value_to_self_msat = self.funding.value_to_self_msat.saturating_add(our_funding_satoshis);
@@ -9171,7 +9123,7 @@ impl<SP: Deref> FundedChannel<SP> where
91719123 let splice_ack_msg = self.get_splice_ack(our_funding_contribution);
91729124
91739125 // Start interactive funding negotiation. No extra input, as we are not the splice initiator
9174- let mut refunding = self.as_renegotiating_funding ()
9126+ let mut refunding = self.as_renegotiating_channel ()
91759127 .map_err(|err| ChannelError::Warn(err.into()))?;
91769128 let _msg = refunding.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id.clone(), None, None)
91779129 .map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
@@ -9267,7 +9219,7 @@ impl<SP: Deref> FundedChannel<SP> where
92679219 self.splice_start(true, logger);
92689220
92699221 // Start interactive funding negotiation, with the previous funding transaction as an extra shared input
9270- let mut refunding = self.as_renegotiating_funding ()
9222+ let mut refunding = self.as_renegotiating_channel ()
92719223 .map_err(|err| ChannelError::Warn(err.into()))?;
92729224 let tx_msg_opt = refunding.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id.clone(), None, Some(prev_funding_input))
92739225 .map_err(|err| ChannelError::Warn(format!("V2 channel rejected due to sender error, {:?}", err)))?;
@@ -10965,6 +10917,19 @@ impl<SP: Deref> PendingV2Channel<SP> where SP::Target: SignerProvider {
1096510917 pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
1096610918 self.generate_accept_channel_v2_message()
1096710919 }
10920+
10921+ /// Return a short-lived [`NegotiatingV2ChannelView`].
10922+ #[cfg(splicing)]
10923+ fn as_negotiating_channel<'a>(&'a mut self) -> impl FundingTxConstructorV2<SP> + 'a {
10924+ NegotiatingV2ChannelView {
10925+ channel_context: &mut self.context,
10926+ funding_scope: &mut self.funding,
10927+ funding_negotiation_context: &mut self.funding_negotiation_context,
10928+ interactive_tx_constructor: &mut self.interactive_tx_constructor,
10929+ interactive_tx_signing_session: &mut self.interactive_tx_signing_session,
10930+ holder_commitment_transaction_number: self.unfunded_context.transaction_number(),
10931+ }
10932+ }
1096810933}
1096910934
1097010935// Unfunded channel utilities
0 commit comments