@@ -1897,20 +1897,19 @@ impl FundingScope {
1897
1897
}
1898
1898
}
1899
1899
1900
- /// Info about a pending splice_init, used in the pre- splice channel
1900
+ /// Info about a pending splice
1901
1901
#[cfg(splicing)]
1902
- struct PendingSpliceInit {
1902
+ struct PendingSplice {
1903
+ /// Intended contributions to the splice from our end
1903
1904
pub our_funding_contribution: i64,
1904
1905
pub funding_feerate_per_kw: u32,
1905
1906
pub locktime: u32,
1906
1907
/// The funding inputs that we plan to contributing to the splice.
1908
+ /// Stored between [`splice_channel`] and [`splice_ack`]
1907
1909
pub our_funding_inputs: Vec<(TxIn, TransactionU16LenLimited)>,
1908
- }
1909
-
1910
- /// Info about a pending splice
1911
- #[cfg(splicing)]
1912
- struct PendingSplice {
1913
- pub pending_splice_init: Option<PendingSpliceInit>,
1910
+ /// Set when splice_ack has been processed (on the initiator side),
1911
+ /// used to prevent processing of multiple splice_ack's.
1912
+ awaiting_splice_ack: bool,
1914
1913
pub refunding_scope: Option<RefundingScope>,
1915
1914
}
1916
1915
@@ -8975,7 +8974,7 @@ impl<SP: Deref> FundedChannel<SP> where
8975
8974
return Err(APIError::APIMisuseError { err: format!(
8976
8975
"Channel {} cannot be spliced, as it has already a splice pending (contribution {})",
8977
8976
self.context.channel_id(),
8978
- pending_splice.pending_splice_init.as_ref().map(|ps| ps. our_funding_contribution).unwrap_or_default() ,
8977
+ pending_splice.our_funding_contribution,
8979
8978
)});
8980
8979
}
8981
8980
@@ -9014,14 +9013,12 @@ impl<SP: Deref> FundedChannel<SP> where
9014
9013
funding_inputs.push((tx_in.clone(), tx16));
9015
9014
}
9016
9015
9017
- let pending_splice_init = Some(PendingSpliceInit {
9016
+ self.pending_splice = Some(PendingSplice {
9018
9017
our_funding_contribution: our_funding_contribution_satoshis,
9019
9018
funding_feerate_per_kw,
9020
9019
locktime,
9021
9020
our_funding_inputs: funding_inputs,
9022
- });
9023
- self.pending_splice = Some(PendingSplice {
9024
- pending_splice_init,
9021
+ awaiting_splice_ack: true, // we await splice_ack
9025
9022
refunding_scope: None,
9026
9023
});
9027
9024
@@ -9059,7 +9056,7 @@ impl<SP: Deref> FundedChannel<SP> where
9059
9056
return Err(ChannelError::Warn(format!(
9060
9057
"Channel {} has already a splice pending, contribution {}",
9061
9058
self.context.channel_id(),
9062
- pending_splice.pending_splice_init.as_ref().map(|si| si. our_funding_contribution).unwrap_or_default() ,
9059
+ pending_splice.our_funding_contribution,
9063
9060
)));
9064
9061
}
9065
9062
@@ -9153,7 +9150,11 @@ impl<SP: Deref> FundedChannel<SP> where
9153
9150
pending_interactive_tx_signing_session: None,
9154
9151
});
9155
9152
self.pending_splice = Some(PendingSplice {
9156
- pending_splice_init: None,
9153
+ our_funding_contribution,
9154
+ funding_feerate_per_kw: msg.funding_feerate_per_kw,
9155
+ locktime: msg.locktime,
9156
+ our_funding_inputs: Vec::new(), // inputs go directly to [`DualFundingChannelContext`] above
9157
+ awaiting_splice_ack: false, // we don't need any additional message for the handshake
9157
9158
refunding_scope,
9158
9159
});
9159
9160
// TODO(splicing): Store msg.funding_pubkey
@@ -9192,17 +9193,17 @@ impl<SP: Deref> FundedChannel<SP> where
9192
9193
signer_provider: &SP, entropy_source: &ES, holder_node_id: &PublicKey, logger: &L,
9193
9194
) -> Result<Option<InteractiveTxMessageSend>, ChannelError> where ES::Target: EntropySource, L::Target: Logger {
9194
9195
// check if splice is pending
9195
- let pending_splice_init = if let Some(pending_splice) = &self.pending_splice {
9196
- if let Some(pending_splice_init) = &pending_splice.pending_splice_init {
9197
- pending_splice_init
9198
- } else {
9199
- return Err(ChannelError::Warn(format!("Channel is not in pending splice_init")));
9200
- }
9196
+ let pending_splice = if let Some(pending_splice) = &self.pending_splice {
9197
+ pending_splice
9201
9198
} else {
9202
9199
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
9203
9200
};
9204
9201
9205
- let our_funding_contribution = pending_splice_init.our_funding_contribution;
9202
+ if !pending_splice.awaiting_splice_ack {
9203
+ return Err(ChannelError::Warn(format!("Received unexpected splice_ack")));
9204
+ }
9205
+
9206
+ let our_funding_contribution = pending_splice.our_funding_contribution;
9206
9207
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
9207
9208
9208
9209
// TODO(splicing): Pre-check for reserve requirement
@@ -9237,12 +9238,15 @@ impl<SP: Deref> FundedChannel<SP> where
9237
9238
next_remote_commitment_tx_fee_info_cached: Mutex::new(None),
9238
9239
};
9239
9240
9240
- let pending_dual_funding_context = DualFundingChannelContext {
9241
+ let mut pending_dual_funding_context = DualFundingChannelContext {
9241
9242
our_funding_satoshis,
9242
9243
their_funding_satoshis: Some(their_funding_satoshis),
9243
- funding_tx_locktime: LockTime::from_consensus(pending_splice_init.locktime),
9244
- funding_feerate_sat_per_1000_weight: pending_splice_init.funding_feerate_per_kw,
9245
- our_funding_inputs: pending_splice_init.our_funding_inputs.clone(),
9244
+ funding_tx_locktime: LockTime::from_consensus(pending_splice.locktime),
9245
+ funding_feerate_sat_per_1000_weight: pending_splice.funding_feerate_per_kw,
9246
+ our_funding_inputs: Vec::new(), // set below
9247
+ };
9248
+ if let Some(ref mut pending_splice_mut) = &mut self.pending_splice {
9249
+ pending_dual_funding_context.our_funding_inputs = std::mem::take(&mut pending_splice_mut.our_funding_inputs);
9246
9250
};
9247
9251
let pending_unfunded_context = UnfundedChannelContext {
9248
9252
unfunded_channel_age_ticks: 0,
@@ -9262,6 +9266,8 @@ impl<SP: Deref> FundedChannel<SP> where
9262
9266
let prev_funding_input = RefundingScope::get_input_of_previous_funding(pre_funding_transaction, pre_funding_txo)?;
9263
9267
if let Some(ref mut pending_splice) = &mut self.pending_splice {
9264
9268
pending_splice.refunding_scope = Some(refunding_scope);
9269
+ debug_assert!(pending_splice.awaiting_splice_ack);
9270
+ pending_splice.awaiting_splice_ack = false;
9265
9271
} else {
9266
9272
return Err(ChannelError::Warn(format!("Channel is not in pending splice")));
9267
9273
};
0 commit comments