Skip to content

Commit 25dea25

Browse files
committed
Simplify PendingSplice, remove some fields
Some fields -- locktime, feerate, inputs -- can be stored directly in `funding_negotiation_context`.
1 parent 54ddcbe commit 25dea25

File tree

1 file changed

+19
-29
lines changed

1 file changed

+19
-29
lines changed

lightning/src/ln/channel.rs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,16 +1905,11 @@ impl FundingScope {
19051905
struct PendingSplice {
19061906
/// Intended contributions to the splice from our end
19071907
pub our_funding_contribution: i64,
1908-
pub funding_feerate_per_kw: u32,
1909-
pub locktime: u32,
1910-
/// The funding inputs that we plan to contributing to the splice.
1911-
/// Stored between [`splice_channel`] and [`splice_ack`]
1912-
pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
19131908
/// Set when splice_ack has been processed (on the initiator side),
19141909
/// used to prevent processing of multiple splice_ack's.
19151910
awaiting_splice_ack: bool,
19161911
funding_scope: Option<FundingScope>,
1917-
funding_negotiation_context: Option<FundingNegotiationContext>,
1912+
funding_negotiation_context: FundingNegotiationContext,
19181913
/// The current interactive transaction construction session under negotiation.
19191914
interactive_tx_constructor: Option<InteractiveTxConstructor>,
19201915
interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
@@ -5289,18 +5284,21 @@ impl<SP: Deref> FundedChannel<SP> where
52895284
fn as_renegotiating_channel(&mut self) -> Result<NegotiatingV2ChannelView<SP>, &'static str> {
52905285
if let Some(ref mut pending_splice) = &mut self.pending_splice {
52915286
if let Some(ref mut funding) = &mut pending_splice.funding_scope {
5292-
if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
5287+
if
5288+
pending_splice.funding_negotiation_context.our_funding_satoshis != 0 ||
5289+
pending_splice.funding_negotiation_context.their_funding_satoshis.unwrap_or_default() != 0
5290+
{
52935291
Ok(NegotiatingV2ChannelView {
52945292
context: &mut self.context,
52955293
funding,
5296-
funding_negotiation_context,
5294+
funding_negotiation_context: &mut pending_splice.funding_negotiation_context,
52975295
interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
52985296
interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
52995297
holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
53005298
is_splice: true,
53015299
})
53025300
} else {
5303-
Err("Channel is not refunding")
5301+
Err("Channel is not actively refunding")
53045302
}
53055303
} else {
53065304
Err("Channel is not refunding")
@@ -8868,14 +8866,18 @@ impl<SP: Deref> FundedChannel<SP> where
88688866
funding_inputs.push((tx_in.clone(), tx16));
88698867
}
88708868

8869+
let funding_negotiation_context = FundingNegotiationContext {
8870+
our_funding_satoshis: 0, // set at later phase
8871+
their_funding_satoshis: None, // set at later phase
8872+
funding_tx_locktime: LockTime::from_consensus(locktime),
8873+
funding_feerate_sat_per_1000_weight: funding_feerate_per_kw,
8874+
our_funding_inputs: funding_inputs,
8875+
};
88718876
self.pending_splice = Some(PendingSplice {
88728877
our_funding_contribution: our_funding_contribution_satoshis,
8873-
funding_feerate_per_kw,
8874-
locktime,
8875-
our_funding_inputs: funding_inputs,
88768878
awaiting_splice_ack: true, // we await splice_ack
88778879
funding_scope: None,
8878-
funding_negotiation_context: None,
8880+
funding_negotiation_context,
88798881
interactive_tx_constructor: None,
88808882
interactive_tx_signing_session: None,
88818883
});
@@ -9024,12 +9026,9 @@ impl<SP: Deref> FundedChannel<SP> where
90249026

90259027
self.pending_splice = Some(PendingSplice {
90269028
our_funding_contribution,
9027-
funding_feerate_per_kw: msg.funding_feerate_per_kw,
9028-
locktime: msg.locktime,
9029-
our_funding_inputs: Vec::new(), // inputs go directly to [`FundingNegotiationContext`] above
90309029
awaiting_splice_ack: false, // we don't need any additional message for the handshake
90319030
funding_scope: Some(funding_scope),
9032-
funding_negotiation_context: Some(funding_negotiation_context),
9031+
funding_negotiation_context,
90339032
interactive_tx_constructor: None,
90349033
interactive_tx_signing_session: None,
90359034
});
@@ -9099,24 +9098,15 @@ impl<SP: Deref> FundedChannel<SP> where
90999098

91009099
let funding_scope = self.funding_scope_for_splice(our_funding_satoshis, post_channel_value);
91019100

9102-
let mut funding_negotiation_context = FundingNegotiationContext {
9103-
our_funding_satoshis,
9104-
their_funding_satoshis: Some(their_funding_satoshis),
9105-
funding_tx_locktime: LockTime::from_consensus(pending_splice.locktime),
9106-
funding_feerate_sat_per_1000_weight: pending_splice.funding_feerate_per_kw,
9107-
our_funding_inputs: Vec::new(), // set below
9108-
};
9109-
if let Some(ref mut pending_splice_mut) = &mut self.pending_splice {
9110-
funding_negotiation_context.our_funding_inputs = std::mem::take(&mut pending_splice_mut.our_funding_inputs);
9111-
};
9112-
91139101
let pre_funding_transaction = &self.funding.funding_transaction;
91149102
let pre_funding_txo = &self.funding.get_funding_txo();
91159103
// We need the current funding tx as an extra input
91169104
let prev_funding_input = Self::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
91179105
if let Some(ref mut pending_splice) = &mut self.pending_splice {
91189106
pending_splice.funding_scope = Some(funding_scope);
9119-
pending_splice.funding_negotiation_context = Some(funding_negotiation_context);
9107+
// update funding values
9108+
pending_splice.funding_negotiation_context.our_funding_satoshis = our_funding_satoshis;
9109+
pending_splice.funding_negotiation_context.their_funding_satoshis = Some(their_funding_satoshis);
91209110
pending_splice.interactive_tx_constructor = None;
91219111
pending_splice.interactive_tx_signing_session = None;
91229112
debug_assert!(pending_splice.awaiting_splice_ack);

0 commit comments

Comments
 (0)