@@ -1457,49 +1457,49 @@ impl<SP: Deref> Channel<SP> where
1457
1457
1458
1458
pub fn tx_add_input(&mut self, msg: &msgs::TxAddInput) -> Result<InteractiveTxMessageSendResult, &'static str> {
1459
1459
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)),
1461
1461
#[cfg(splicing)]
1462
- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1462
+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
1463
1463
.tx_add_input(msg)),
1464
1464
_ => Err("Got tx_add_input in an invalid phase"),
1465
1465
}
1466
1466
}
1467
1467
1468
1468
pub fn tx_add_output(&mut self, msg: &msgs::TxAddOutput) -> Result<InteractiveTxMessageSendResult, &'static str> {
1469
1469
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)),
1471
1471
#[cfg(splicing)]
1472
- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1472
+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
1473
1473
.tx_add_output(msg)),
1474
1474
_ => Err("Got tx_add_output in an invalid phase"),
1475
1475
}
1476
1476
}
1477
1477
1478
1478
pub fn tx_remove_input(&mut self, msg: &msgs::TxRemoveInput) -> Result<InteractiveTxMessageSendResult, &'static str> {
1479
1479
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)),
1481
1481
#[cfg(splicing)]
1482
- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1482
+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
1483
1483
.tx_remove_input(msg)),
1484
1484
_ => Err("Got tx_remove_input in an invalid phase"),
1485
1485
}
1486
1486
}
1487
1487
1488
1488
pub fn tx_remove_output(&mut self, msg: &msgs::TxRemoveOutput) -> Result<InteractiveTxMessageSendResult, &'static str> {
1489
1489
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)),
1491
1491
#[cfg(splicing)]
1492
- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1492
+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
1493
1493
.tx_remove_output(msg)),
1494
1494
_ => Err("Got tx_remove_output in an invalid phase"),
1495
1495
}
1496
1496
}
1497
1497
1498
1498
pub fn tx_complete(&mut self, msg: &msgs::TxComplete) -> Result<HandleTxCompleteResult, &'static str> {
1499
1499
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)),
1501
1501
#[cfg(splicing)]
1502
- ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_funding ()?
1502
+ ChannelPhase::Funded(chan) => Ok(chan.as_renegotiating_channel ()?
1503
1503
.tx_complete(msg)),
1504
1504
_ => Err("Got tx_complete in an invalid phase"),
1505
1505
}
@@ -1545,13 +1545,13 @@ impl<SP: Deref> Channel<SP> where
1545
1545
match self.phase {
1546
1546
ChannelPhase::UnfundedV2(ref mut chan) => {
1547
1547
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)?;
1549
1549
Ok((commitment_signed, event))
1550
1550
}
1551
1551
#[cfg(splicing)]
1552
1552
ChannelPhase::Funded(ref mut chan) => {
1553
1553
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 ()
1555
1555
.map_err(|err| ChannelError::Warn(err.into()))?
1556
1556
.funding_tx_constructed(signing_session, &&logger)?;
1557
1557
Ok((commitment_signed, event))
@@ -2432,21 +2432,22 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
2432
2432
}
2433
2433
}
2434
2434
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.
2437
2439
#[cfg(splicing)]
2438
- struct FundedChannelRefundingWrapper <'a, SP: Deref> where SP::Target: SignerProvider {
2440
+ struct NegotiatingV2ChannelView <'a, SP: Deref> where SP::Target: SignerProvider {
2439
2441
channel_context: &'a mut ChannelContext<SP>,
2440
2442
funding_scope: &'a mut FundingScope,
2441
2443
funding_negotiation_context: &'a mut FundingNegotiationContext,
2442
2444
interactive_tx_constructor: &'a mut Option<InteractiveTxConstructor>,
2443
2445
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,
2446
2447
}
2447
2448
2448
2449
#[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 {
2450
2451
#[inline]
2451
2452
fn context(&self) -> &ChannelContext<SP> {
2452
2453
&self.channel_context
@@ -2459,7 +2460,7 @@ impl<'a, SP: Deref> ChannelContextProvider<SP> for FundedChannelRefundingWrapper
2459
2460
}
2460
2461
2461
2462
#[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 {
2463
2464
#[inline]
2464
2465
fn funding_scope(&self) -> &FundingScope {
2465
2466
&self.funding_scope
@@ -2486,7 +2487,7 @@ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper
2486
2487
}
2487
2488
2488
2489
fn current_holder_transaction_number(&self) -> u64 {
2489
- self.holder_commitment_point.transaction_number()
2490
+ self.holder_commitment_transaction_number
2490
2491
}
2491
2492
2492
2493
#[inline]
@@ -2814,54 +2815,6 @@ impl<SP: Deref> ChannelContextProvider<SP> for PendingV2Channel<SP> where SP::Ta
2814
2815
}
2815
2816
}
2816
2817
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
-
2865
2818
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
2866
2819
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
2867
2820
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
@@ -5414,21 +5367,19 @@ impl<SP: Deref> FundedChannel<SP> where
5414
5367
SP::Target: SignerProvider,
5415
5368
<SP::Target as SignerProvider>::EcdsaSigner: EcdsaChannelSigner
5416
5369
{
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`].
5420
5371
#[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> {
5422
5373
if let Some(ref mut pending_splice) = &mut self.pending_splice {
5423
5374
if let Some(ref mut funding_scope) = &mut pending_splice.funding_scope {
5424
5375
if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
5425
- Ok(FundedChannelRefundingWrapper {
5376
+ Ok(NegotiatingV2ChannelView {
5426
5377
channel_context: &mut self.context,
5427
5378
funding_scope,
5428
5379
funding_negotiation_context,
5429
5380
interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
5430
5381
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() ,
5432
5383
})
5433
5384
} else {
5434
5385
Err("Channel is not refunding")
@@ -9078,6 +9029,7 @@ impl<SP: Deref> FundedChannel<SP> where
9078
9029
Ok(())
9079
9030
}
9080
9031
9032
+ /// Helper to build the FundingScope for the splicing channel
9081
9033
#[cfg(splicing)]
9082
9034
fn funding_scope_for_splice(&self, our_funding_satoshis: u64, post_channel_value: u64) -> FundingScope {
9083
9035
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
9171
9123
let splice_ack_msg = self.get_splice_ack(our_funding_contribution);
9172
9124
9173
9125
// 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 ()
9175
9127
.map_err(|err| ChannelError::Warn(err.into()))?;
9176
9128
let _msg = refunding.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id.clone(), None, None)
9177
9129
.map_err(|err| ChannelError::Warn(format!("Failed to start interactive transaction construction, {:?}", err)))?;
@@ -9267,7 +9219,7 @@ impl<SP: Deref> FundedChannel<SP> where
9267
9219
self.splice_start(true, logger);
9268
9220
9269
9221
// 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 ()
9271
9223
.map_err(|err| ChannelError::Warn(err.into()))?;
9272
9224
let tx_msg_opt = refunding.begin_interactive_funding_tx_construction(signer_provider, entropy_source, holder_node_id.clone(), None, Some(prev_funding_input))
9273
9225
.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 {
10965
10917
pub fn get_accept_channel_v2_message(&self) -> msgs::AcceptChannelV2 {
10966
10918
self.generate_accept_channel_v2_message()
10967
10919
}
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
+ }
10968
10933
}
10969
10934
10970
10935
// Unfunded channel utilities
0 commit comments