Skip to content

Commit 2d2e38d

Browse files
committed
fix Merge RefundingScope into PendingSplice, renames
1 parent 6845e4f commit 2d2e38d

File tree

1 file changed

+71
-72
lines changed

1 file changed

+71
-72
lines changed

lightning/src/ln/channel.rs

+71-72
Original file line numberDiff line numberDiff line change
@@ -1913,7 +1913,11 @@ struct PendingSplice {
19131913
/// Set when splice_ack has been processed (on the initiator side),
19141914
/// used to prevent processing of multiple splice_ack's.
19151915
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>,
19171921
}
19181922

19191923
#[cfg(splicing)]
@@ -2433,7 +2437,10 @@ impl<SP: Deref> InitialRemoteCommitmentReceiver<SP> for FundedChannel<SP> where
24332437
#[cfg(splicing)]
24342438
struct FundedChannelRefundingWrapper<'a, SP: Deref> where SP::Target: SignerProvider {
24352439
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>,
24372444
/// For accessing commitment transaction number
24382445
holder_commitment_point: &'a HolderCommitmentPoint,
24392446
}
@@ -2454,28 +2461,28 @@ impl<'a, SP: Deref> ChannelContextProvider<SP> for FundedChannelRefundingWrapper
24542461
#[cfg(splicing)]
24552462
impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper<'a, SP> where SP::Target: SignerProvider {
24562463
#[inline]
2457-
fn pending_funding(&self) -> &FundingScope {
2458-
&self.refunding_scope.pending_funding
2464+
fn funding_scope(&self) -> &FundingScope {
2465+
&self.funding_scope
24592466
}
24602467

24612468
#[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
24642471
}
24652472

24662473
#[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)
24692476
}
24702477

24712478
#[inline]
24722479
fn funding_negotiation_context(&self) -> &FundingNegotiationContext {
2473-
&self.refunding_scope.pending_funding_negotiation_context
2480+
&self.funding_negotiation_context
24742481
}
24752482

24762483
#[inline]
24772484
fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext {
2478-
&mut self.refunding_scope.pending_funding_negotiation_context
2485+
&mut self.funding_negotiation_context
24792486
}
24802487

24812488
fn current_holder_transaction_number(&self) -> u64 {
@@ -2484,17 +2491,17 @@ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper
24842491

24852492
#[inline]
24862493
fn interactive_tx_constructor(&self) -> Option<&InteractiveTxConstructor> {
2487-
self.refunding_scope.pending_interactive_tx_constructor.as_ref()
2494+
self.interactive_tx_constructor.as_ref()
24882495
}
24892496

24902497
#[inline]
24912498
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
24932500
}
24942501

24952502
#[inline]
24962503
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
24982505
}
24992506

25002507
fn is_splice(&self) -> bool { true }
@@ -2503,9 +2510,9 @@ impl<'a, SP: Deref> FundingTxConstructorV2<SP> for FundedChannelRefundingWrapper
25032510
/// A channel struct implementing this trait can perform V2 transaction negotiation,
25042511
/// either at channel open or during splicing.
25052512
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>);
25092516
fn funding_negotiation_context(&self) -> &FundingNegotiationContext;
25102517
fn funding_negotiation_context_mut(&mut self) -> &mut FundingNegotiationContext;
25112518
fn current_holder_transaction_number(&self) -> u64;
@@ -2548,15 +2555,15 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
25482555
let mut funding_outputs = Vec::new();
25492556
let mut expected_remote_shared_funding_output = None;
25502557

2551-
let pending_funding = self.pending_funding();
2558+
let funding_scope = self.funding_scope();
25522559

25532560
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(),
25562563
};
25572564

25582565
let funding_negotiation_context = &self.funding_negotiation_context();
2559-
if pending_funding.is_outbound() {
2566+
if funding_scope.is_outbound() {
25602567
funding_outputs.push(
25612568
OutputOwned::Shared(SharedOwnedOutput::new(
25622569
shared_funding_output, funding_negotiation_context.our_funding_satoshis,
@@ -2575,7 +2582,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
25752582
.map_err(|_err| AbortReason::InternalError("Error getting destination script"))?
25762583
};
25772584
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,
25792586
&funding_inputs, &funding_outputs,
25802587
funding_negotiation_context.funding_feerate_sat_per_1000_weight,
25812588
change_script.minimal_non_dust().to_sat(),
@@ -2601,7 +2608,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
26012608
counterparty_node_id: self.context().counterparty_node_id,
26022609
channel_id: self.context().channel_id(),
26032610
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(),
26052612
funding_tx_locktime: funding_negotiation_context.funding_tx_locktime,
26062613
inputs_to_contribute: funding_inputs,
26072614
outputs_to_contribute: funding_outputs,
@@ -2695,12 +2702,12 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
26952702
let our_funding_satoshis = self.funding_negotiation_context()
26962703
.our_funding_satoshis;
26972704
let transaction_number = self.current_holder_transaction_number();
2698-
let pending_funding = self.pending_funding();
2705+
let funding_scope = self.funding_scope();
26992706

27002707
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();
27022709
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() {
27042711
if output_index.is_some() {
27052712
return Err(ChannelError::Close(
27062713
(
@@ -2720,7 +2727,7 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
27202727
ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) },
27212728
)));
27222729
};
2723-
self.pending_funding_mut()
2730+
self.funding_context_mut()
27242731
.channel_transaction_parameters.funding_outpoint = Some(outpoint);
27252732

27262733
if self.is_splice() {
@@ -2732,16 +2739,16 @@ pub(super) trait FundingTxConstructorV2<SP: Deref>: ChannelContextProvider<SP> w
27322739
}
27332740

27342741
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();
27362743
let commitment_signed = context_mut.get_initial_commitment_signed(&funding, logger);
27372744
let commitment_signed = match commitment_signed {
27382745
Ok(commitment_signed) => {
2739-
self.pending_funding_mut()
2746+
self.funding_context_mut()
27402747
.funding_transaction = Some(signing_session.unsigned_tx.build_unsigned_tx());
27412748
commitment_signed
27422749
},
27432750
Err(err) => {
2744-
self.pending_funding_mut()
2751+
self.funding_context_mut()
27452752
.channel_transaction_parameters.funding_outpoint = None;
27462753
return Err(ChannelError::Close((err.to_string(), ClosureReason::HolderForceClosed { broadcasted_latest_txn: Some(false) })));
27472754
},
@@ -2809,17 +2816,17 @@ impl<SP: Deref> ChannelContextProvider<SP> for PendingV2Channel<SP> where SP::Ta
28092816

28102817
impl<SP: Deref> FundingTxConstructorV2<SP> for PendingV2Channel<SP> where SP::Target: SignerProvider {
28112818
#[inline]
2812-
fn pending_funding(&self) -> &FundingScope {
2819+
fn funding_scope(&self) -> &FundingScope {
28132820
&self.funding
28142821
}
28152822

28162823
#[inline]
2817-
fn pending_funding_mut(&mut self) -> &mut FundingScope {
2824+
fn funding_context_mut(&mut self) -> &mut FundingScope {
28182825
&mut self.funding
28192826
}
28202827

28212828
#[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>) {
28232830
(&self.funding, &mut self.context)
28242831
}
28252832

@@ -2855,18 +2862,6 @@ impl<SP: Deref> FundingTxConstructorV2<SP> for PendingV2Channel<SP> where SP::Ta
28552862
fn is_splice(&self) -> bool { false }
28562863
}
28572864

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-
28702865
impl<SP: Deref> ChannelContext<SP> where SP::Target: SignerProvider {
28712866
fn new_for_inbound_channel<'a, ES: Deref, F: Deref, L: Deref>(
28722867
fee_estimator: &'a LowerBoundedFeeEstimator<F>,
@@ -5425,12 +5420,19 @@ impl<SP: Deref> FundedChannel<SP> where
54255420
#[cfg(splicing)]
54265421
fn as_renegotiating_funding<'a>(&'a mut self) -> Result<impl FundingTxConstructorV2<SP> + 'a, &'static str> {
54275422
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+
}
54345436
} else {
54355437
Err("Channel is not refunding")
54365438
}
@@ -9003,7 +9005,10 @@ impl<SP: Deref> FundedChannel<SP> where
90039005
locktime,
90049006
our_funding_inputs: funding_inputs,
90059007
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,
90079012
});
90089013

90099014
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
91379142
false, // is_outbound
91389143
)?;
91399144

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);
91419146

9142-
let pending_funding_negotiation_context = FundingNegotiationContext {
9147+
let funding_negotiation_context = FundingNegotiationContext {
91439148
our_funding_satoshis,
91449149
their_funding_satoshis: Some(their_funding_satoshis),
91459150
funding_tx_locktime: LockTime::from_consensus(msg.locktime),
91469151
funding_feerate_sat_per_1000_weight: msg.funding_feerate_per_kw,
91479152
our_funding_inputs: Vec::new(),
91489153
};
91499154

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-
});
91569155
self.pending_splice = Some(PendingSplice {
91579156
our_funding_contribution,
91589157
funding_feerate_per_kw: msg.funding_feerate_per_kw,
91599158
locktime: msg.locktime,
91609159
our_funding_inputs: Vec::new(), // inputs go directly to [`FundingNegotiationContext`] above
91619160
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,
91639165
});
91649166
// TODO(splicing): Store msg.funding_pubkey
91659167

@@ -9225,31 +9227,28 @@ impl<SP: Deref> FundedChannel<SP> where
92259227
true, // is_outbound
92269228
)?;
92279229

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);
92299231

9230-
let mut pending_funding_negotiation_context = FundingNegotiationContext {
9232+
let mut funding_negotiation_context = FundingNegotiationContext {
92319233
our_funding_satoshis,
92329234
their_funding_satoshis: Some(their_funding_satoshis),
92339235
funding_tx_locktime: LockTime::from_consensus(pending_splice.locktime),
92349236
funding_feerate_sat_per_1000_weight: pending_splice.funding_feerate_per_kw,
92359237
our_funding_inputs: Vec::new(), // set below
92369238
};
92379239
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);
92399241
};
92409242

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-
};
92479243
let pre_funding_transaction = &self.funding.funding_transaction;
92489244
let pre_funding_txo = &self.funding.get_funding_txo();
92499245
// We need the current funding tx as an extra input
92509246
let prev_funding_input = Self::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
92519247
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;
92539252
debug_assert!(pending_splice.awaiting_splice_ack);
92549253
pending_splice.awaiting_splice_ack = false;
92559254
} else {
@@ -9307,10 +9306,10 @@ impl<SP: Deref> FundedChannel<SP> where
93079306
// NegotiatingFundingFlags::OUR_INIT_SENT | NegotiatingFundingFlags::THEIR_INIT_SENT
93089307
// );
93099308
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 {
93119310
let old_value = self.funding.get_value_satoshis();
93129311
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);
93149313
}
93159314
}
93169315
}

0 commit comments

Comments
 (0)