Skip to content

Commit 60e2cca

Browse files
committed
Simplify PendingSplice, remove some fields
Some fields -- locktime, feerate, inputs -- can be stored directly in `funding_negotiation_context`.
1 parent 430109a commit 60e2cca

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
@@ -2036,16 +2036,11 @@ impl FundingScope {
20362036
struct PendingSplice {
20372037
/// Intended contributions to the splice from our end
20382038
pub our_funding_contribution: i64,
2039-
pub funding_feerate_per_kw: u32,
2040-
pub locktime: u32,
2041-
/// The funding inputs that we plan to contributing to the splice.
2042-
/// Stored between [`splice_channel`] and [`splice_ack`]
2043-
pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
20442039
/// Set when splice_ack has been processed (on the initiator side),
20452040
/// used to prevent processing of multiple splice_ack's.
20462041
awaiting_splice_ack: bool,
20472042
funding_scope: Option<FundingScope>,
2048-
funding_negotiation_context: Option<FundingNegotiationContext>,
2043+
funding_negotiation_context: FundingNegotiationContext,
20492044
/// The current interactive transaction construction session under negotiation.
20502045
interactive_tx_constructor: Option<InteractiveTxConstructor>,
20512046
interactive_tx_signing_session: Option<InteractiveTxSigningSession>,
@@ -5450,18 +5445,21 @@ impl<SP: Deref> FundedChannel<SP> where
54505445
fn as_renegotiating_channel(&mut self) -> Result<NegotiatingV2ChannelView<SP>, &'static str> {
54515446
if let Some(ref mut pending_splice) = &mut self.pending_splice {
54525447
if let Some(ref mut funding) = &mut pending_splice.funding_scope {
5453-
if let Some(ref mut funding_negotiation_context) = &mut pending_splice.funding_negotiation_context {
5448+
if
5449+
pending_splice.funding_negotiation_context.our_funding_satoshis != 0 ||
5450+
pending_splice.funding_negotiation_context.their_funding_satoshis.unwrap_or_default() != 0
5451+
{
54545452
Ok(NegotiatingV2ChannelView {
54555453
context: &mut self.context,
54565454
funding,
5457-
funding_negotiation_context,
5455+
funding_negotiation_context: &mut pending_splice.funding_negotiation_context,
54585456
interactive_tx_constructor: &mut pending_splice.interactive_tx_constructor,
54595457
interactive_tx_signing_session: &mut pending_splice.interactive_tx_signing_session,
54605458
holder_commitment_transaction_number: self.holder_commitment_point.transaction_number(),
54615459
is_splice: true,
54625460
})
54635461
} else {
5464-
Err("Channel is not refunding")
5462+
Err("Channel is not actively refunding")
54655463
}
54665464
} else {
54675465
Err("Channel is not refunding")
@@ -9151,14 +9149,18 @@ impl<SP: Deref> FundedChannel<SP> where
91519149
funding_inputs.push((tx_in.clone(), tx16));
91529150
}
91539151

9152+
let funding_negotiation_context = FundingNegotiationContext {
9153+
our_funding_satoshis: 0, // set at later phase
9154+
their_funding_satoshis: None, // set at later phase
9155+
funding_tx_locktime: LockTime::from_consensus(locktime),
9156+
funding_feerate_sat_per_1000_weight: funding_feerate_per_kw,
9157+
our_funding_inputs: funding_inputs,
9158+
};
91549159
self.pending_splice = Some(PendingSplice {
91559160
our_funding_contribution: our_funding_contribution_satoshis,
9156-
funding_feerate_per_kw,
9157-
locktime,
9158-
our_funding_inputs: funding_inputs,
91599161
awaiting_splice_ack: true, // we await splice_ack
91609162
funding_scope: None,
9161-
funding_negotiation_context: None,
9163+
funding_negotiation_context,
91629164
interactive_tx_constructor: None,
91639165
interactive_tx_signing_session: None,
91649166
});
@@ -9307,12 +9309,9 @@ impl<SP: Deref> FundedChannel<SP> where
93079309

93089310
self.pending_splice = Some(PendingSplice {
93099311
our_funding_contribution,
9310-
funding_feerate_per_kw: msg.funding_feerate_per_kw,
9311-
locktime: msg.locktime,
9312-
our_funding_inputs: Vec::new(), // inputs go directly to [`FundingNegotiationContext`] above
93139312
awaiting_splice_ack: false, // we don't need any additional message for the handshake
93149313
funding_scope: Some(funding_scope),
9315-
funding_negotiation_context: Some(funding_negotiation_context),
9314+
funding_negotiation_context,
93169315
interactive_tx_constructor: None,
93179316
interactive_tx_signing_session: None,
93189317
});
@@ -9382,24 +9381,15 @@ impl<SP: Deref> FundedChannel<SP> where
93829381

93839382
let funding_scope = self.funding_scope_for_splice(our_funding_satoshis, post_channel_value);
93849383

9385-
let mut funding_negotiation_context = FundingNegotiationContext {
9386-
our_funding_satoshis,
9387-
their_funding_satoshis: Some(their_funding_satoshis),
9388-
funding_tx_locktime: LockTime::from_consensus(pending_splice.locktime),
9389-
funding_feerate_sat_per_1000_weight: pending_splice.funding_feerate_per_kw,
9390-
our_funding_inputs: Vec::new(), // set below
9391-
};
9392-
if let Some(ref mut pending_splice_mut) = &mut self.pending_splice {
9393-
funding_negotiation_context.our_funding_inputs = std::mem::take(&mut pending_splice_mut.our_funding_inputs);
9394-
};
9395-
93969384
let pre_funding_transaction = &self.funding.funding_transaction;
93979385
let pre_funding_txo = &self.funding.get_funding_txo();
93989386
// We need the current funding tx as an extra input
93999387
let prev_funding_input = Self::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
94009388
if let Some(ref mut pending_splice) = &mut self.pending_splice {
94019389
pending_splice.funding_scope = Some(funding_scope);
9402-
pending_splice.funding_negotiation_context = Some(funding_negotiation_context);
9390+
// update funding values
9391+
pending_splice.funding_negotiation_context.our_funding_satoshis = our_funding_satoshis;
9392+
pending_splice.funding_negotiation_context.their_funding_satoshis = Some(their_funding_satoshis);
94039393
pending_splice.interactive_tx_constructor = None;
94049394
pending_splice.interactive_tx_signing_session = None;
94059395
debug_assert!(pending_splice.awaiting_splice_ack);

0 commit comments

Comments
 (0)