@@ -12397,9 +12397,7 @@ where
1239712397 }
1239812398
1239912399 /// Checks during handling splice_init
12400- pub fn validate_splice_init(
12401- &self, msg: &msgs::SpliceInit, our_funding_contribution: SignedAmount,
12402- ) -> Result<FundingScope, ChannelError> {
12400+ pub fn validate_splice_init(&self, msg: &msgs::SpliceInit) -> Result<(), ChannelError> {
1240312401 if self.holder_commitment_point.current_point().is_none() {
1240412402 return Err(ChannelError::WarnAndDisconnect(format!(
1240512403 "Channel {} commitment point needs to be advanced once before spliced",
@@ -12436,33 +12434,7 @@ where
1243612434 )));
1243712435 }
1243812436
12439- self.validate_splice_contributions(our_funding_contribution, their_funding_contribution)
12440- .map_err(|e| ChannelError::WarnAndDisconnect(e))?;
12441-
12442- // Rotate the pubkeys using the prev_funding_txid as a tweak
12443- let prev_funding_txid = self.funding.get_funding_txid();
12444- let funding_pubkey = match (prev_funding_txid, &self.context.holder_signer) {
12445- (None, _) => {
12446- debug_assert!(false);
12447- self.funding.get_holder_pubkeys().funding_pubkey
12448- },
12449- (Some(prev_funding_txid), ChannelSignerType::Ecdsa(ecdsa)) => {
12450- ecdsa.new_funding_pubkey(prev_funding_txid, &self.context.secp_ctx)
12451- },
12452- #[cfg(taproot)]
12453- _ => todo!(),
12454- };
12455- let mut new_keys = self.funding.get_holder_pubkeys().clone();
12456- new_keys.funding_pubkey = funding_pubkey;
12457-
12458- Ok(FundingScope::for_splice(
12459- &self.funding,
12460- &self.context,
12461- our_funding_contribution,
12462- their_funding_contribution,
12463- msg.funding_pubkey,
12464- new_keys,
12465- ))
12437+ Ok(())
1246612438 }
1246712439
1246812440 fn validate_splice_contributions(
@@ -12596,18 +12568,46 @@ where
1259612568 &mut self, msg: &msgs::SpliceInit, entropy_source: &ES, holder_node_id: &PublicKey,
1259712569 logger: &L,
1259812570 ) -> Result<msgs::SpliceAck, InteractiveTxMsgError> {
12571+ self.validate_splice_init(msg).map_err(|e| self.quiescent_negotiation_err(e))?;
12572+
1259912573 let feerate = FeeRate::from_sat_per_kwu(msg.funding_feerate_per_kw as u64);
12600- let (our_funding_contribution , holder_balance) = self
12574+ let (queued_net_value , holder_balance) = self
1260112575 .resolve_queued_contribution(feerate, logger)
1260212576 .map_err(|e| self.quiescent_negotiation_err(e))?;
1260312577
12604- let splice_funding = self
12605- .validate_splice_init(msg, our_funding_contribution.unwrap_or(SignedAmount::ZERO))
12606- .map_err(|e| self.quiescent_negotiation_err(e))?;
12578+ let our_funding_contribution = queued_net_value.unwrap_or(SignedAmount::ZERO);
12579+ let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
12580+ self.validate_splice_contributions(our_funding_contribution, their_funding_contribution)
12581+ .map_err(|e| self.quiescent_negotiation_err(ChannelError::WarnAndDisconnect(e)))?;
12582+
12583+ // Rotate the pubkeys using the prev_funding_txid as a tweak
12584+ let prev_funding_txid = self.funding.get_funding_txid();
12585+ let funding_pubkey = match (prev_funding_txid, &self.context.holder_signer) {
12586+ (None, _) => {
12587+ debug_assert!(false);
12588+ self.funding.get_holder_pubkeys().funding_pubkey
12589+ },
12590+ (Some(prev_funding_txid), ChannelSignerType::Ecdsa(ecdsa)) => {
12591+ ecdsa.new_funding_pubkey(prev_funding_txid, &self.context.secp_ctx)
12592+ },
12593+ #[cfg(taproot)]
12594+ _ => todo!(),
12595+ };
12596+ let mut holder_pubkeys = self.funding.get_holder_pubkeys().clone();
12597+ holder_pubkeys.funding_pubkey = funding_pubkey;
12598+
12599+ let splice_funding = FundingScope::for_splice(
12600+ &self.funding,
12601+ &self.context,
12602+ our_funding_contribution,
12603+ their_funding_contribution,
12604+ msg.funding_pubkey,
12605+ holder_pubkeys,
12606+ );
1260712607
1260812608 // Adjust for the feerate and clone so we can store it for future RBF re-use.
1260912609 let (adjusted_contribution, our_funding_inputs, our_funding_outputs) =
12610- if our_funding_contribution .is_some() {
12610+ if queued_net_value .is_some() {
1261112611 let adjusted_contribution = self
1261212612 .take_queued_funding_contribution()
1261312613 .expect("queued_funding_contribution was Some")
@@ -12618,7 +12618,6 @@ where
1261812618 } else {
1261912619 (None, Default::default(), Default::default())
1262012620 };
12621- let our_funding_contribution = our_funding_contribution.unwrap_or(SignedAmount::ZERO);
1262212621
1262312622 log_info!(
1262412623 logger,
@@ -12661,9 +12660,8 @@ where
1266112660
1266212661 /// Checks during handling tx_init_rbf for an existing splice
1266312662 fn validate_tx_init_rbf<F: FeeEstimator>(
12664- &self, msg: &msgs::TxInitRbf, our_funding_contribution: SignedAmount,
12665- fee_estimator: &LowerBoundedFeeEstimator<F>,
12666- ) -> Result<FundingScope, ChannelError> {
12663+ &self, msg: &msgs::TxInitRbf, fee_estimator: &LowerBoundedFeeEstimator<F>,
12664+ ) -> Result<(ChannelPublicKeys, PublicKey), ChannelError> {
1266712665 if self.holder_commitment_point.current_point().is_none() {
1266812666 return Err(ChannelError::WarnAndDisconnect(format!(
1266912667 "Channel {} commitment point needs to be advanced once before RBF",
@@ -12729,33 +12727,22 @@ where
1272912727 return Err(ChannelError::Abort(AbortReason::InsufficientRbfFeerate));
1273012728 }
1273112729
12732- let their_funding_contribution = match msg.funding_output_contribution {
12733- Some(value) => SignedAmount::from_sat(value),
12734- None => SignedAmount::ZERO,
12735- };
12736-
12737- self.validate_splice_contributions(our_funding_contribution, their_funding_contribution)
12738- .map_err(|e| ChannelError::WarnAndDisconnect(e))?;
12739-
1274012730 // Reuse funding pubkeys from the last negotiated candidate since all RBF candidates
1274112731 // for the same splice share the same funding output script.
12742- let holder_pubkeys = last_candidate.get_holder_pubkeys().clone();
12743- let counterparty_funding_pubkey = *last_candidate.counterparty_funding_pubkey();
12744-
12745- Ok(FundingScope::for_splice(
12746- &self.funding,
12747- &self.context,
12748- our_funding_contribution,
12749- their_funding_contribution,
12750- counterparty_funding_pubkey,
12751- holder_pubkeys,
12732+ Ok((
12733+ last_candidate.get_holder_pubkeys().clone(),
12734+ *last_candidate.counterparty_funding_pubkey(),
1275212735 ))
1275312736 }
1275412737
1275512738 pub(crate) fn tx_init_rbf<ES: EntropySource, F: FeeEstimator, L: Logger>(
1275612739 &mut self, msg: &msgs::TxInitRbf, entropy_source: &ES, holder_node_id: &PublicKey,
1275712740 fee_estimator: &LowerBoundedFeeEstimator<F>, logger: &L,
1275812741 ) -> Result<msgs::TxAckRbf, InteractiveTxMsgError> {
12742+ let (holder_pubkeys, counterparty_funding_pubkey) = self
12743+ .validate_tx_init_rbf(msg, fee_estimator)
12744+ .map_err(|e| self.quiescent_negotiation_err(e))?;
12745+
1275912746 let feerate = FeeRate::from_sat_per_kwu(msg.feerate_sat_per_1000_weight as u64);
1276012747 let (queued_net_value, holder_balance) = self
1276112748 .resolve_queued_contribution(feerate, logger)
@@ -12784,14 +12771,23 @@ where
1278412771 };
1278512772
1278612773 let our_funding_contribution = queued_net_value.or(prior_net_value);
12774+ let our_funding_contribution = our_funding_contribution.unwrap_or(SignedAmount::ZERO);
1278712775
12788- let rbf_funding = self
12789- .validate_tx_init_rbf(
12790- msg,
12791- our_funding_contribution.unwrap_or(SignedAmount::ZERO),
12792- fee_estimator,
12793- )
12794- .map_err(|e| self.quiescent_negotiation_err(e))?;
12776+ let their_funding_contribution = match msg.funding_output_contribution {
12777+ Some(value) => SignedAmount::from_sat(value),
12778+ None => SignedAmount::ZERO,
12779+ };
12780+ self.validate_splice_contributions(our_funding_contribution, their_funding_contribution)
12781+ .map_err(|e| self.quiescent_negotiation_err(ChannelError::WarnAndDisconnect(e)))?;
12782+
12783+ let rbf_funding = FundingScope::for_splice(
12784+ &self.funding,
12785+ &self.context,
12786+ our_funding_contribution,
12787+ their_funding_contribution,
12788+ counterparty_funding_pubkey,
12789+ holder_pubkeys,
12790+ );
1279512791
1279612792 // Consume the appropriate contribution source.
1279712793 let (our_funding_inputs, our_funding_outputs) = if queued_net_value.is_some() {
@@ -12828,8 +12824,6 @@ where
1282812824 Default::default()
1282912825 };
1283012826
12831- let our_funding_contribution = our_funding_contribution.unwrap_or(SignedAmount::ZERO);
12832-
1283312827 log_info!(
1283412828 logger,
1283512829 "Starting RBF funding negotiation for channel {} after receiving tx_init_rbf; channel value: {} sats",
@@ -13968,8 +13962,12 @@ where
1396813962 }
1396913963
1397013964 fn quiescent_negotiation_err(&mut self, err: ChannelError) -> InteractiveTxMsgError {
13971- let exited_quiescence =
13972- if matches!(err, ChannelError::Abort(_)) { self.exit_quiescence() } else { false };
13965+ let exited_quiescence = if matches!(err, ChannelError::Abort(_)) {
13966+ debug_assert!(self.context.channel_state.is_quiescent());
13967+ self.exit_quiescence()
13968+ } else {
13969+ false
13970+ };
1397313971 InteractiveTxMsgError { err, splice_funding_failed: None, exited_quiescence }
1397413972 }
1397513973
0 commit comments