Skip to content

Commit 1edbe7e

Browse files
committed
Add validate_splice_ack helper function
As in `splice_init`, this helps clearly delineate `splice_ack` message validation from the subsequent state mutations. This is a code-move.
1 parent c8c9ab5 commit 1edbe7e

File tree

1 file changed

+45
-37
lines changed

1 file changed

+45
-37
lines changed

lightning/src/ln/channel.rs

Lines changed: 45 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10821,7 +10821,7 @@ where
1082110821
})
1082210822
}
1082310823

10824-
/// Handle splice_ack
10824+
/// See also [`validate_splice_ack`]
1082510825
#[cfg(splicing)]
1082610826
pub(crate) fn splice_ack<ES: Deref, L: Deref>(
1082710827
&mut self, msg: &msgs::SpliceAck, signer_provider: &SP, entropy_source: &ES,
@@ -10831,42 +10831,7 @@ where
1083110831
ES::Target: EntropySource,
1083210832
L::Target: Logger,
1083310833
{
10834-
// TODO(splicing): Add check that we are the splice (quiescence) initiator
10835-
10836-
let funding_negotiation_context = match &self
10837-
.pending_splice
10838-
.as_ref()
10839-
.ok_or(ChannelError::Ignore(format!("Channel is not in pending splice")))?
10840-
.funding_negotiation
10841-
{
10842-
Some(FundingNegotiation::AwaitingAck(context)) => context,
10843-
Some(FundingNegotiation::ConstructingTransaction(_, _))
10844-
| Some(FundingNegotiation::AwaitingSignatures(_)) => {
10845-
return Err(ChannelError::WarnAndDisconnect(format!(
10846-
"Got unexpected splice_ack; splice negotiation already in progress"
10847-
)));
10848-
},
10849-
None => {
10850-
return Err(ChannelError::Ignore(format!(
10851-
"Got unexpected splice_ack; no splice negotiation in progress"
10852-
)));
10853-
},
10854-
};
10855-
10856-
let our_funding_contribution_satoshis =
10857-
funding_negotiation_context.our_funding_contribution_satoshis;
10858-
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
10859-
10860-
let splice_funding = FundingScope::for_splice(
10861-
&self.funding,
10862-
&self.context,
10863-
our_funding_contribution_satoshis,
10864-
their_funding_contribution_satoshis,
10865-
msg.funding_pubkey,
10866-
)?;
10867-
10868-
// TODO(splicing): Pre-check for reserve requirement
10869-
// (Note: It should also be checked later at tx_complete)
10834+
let splice_funding = self.validate_splice_ack(msg)?;
1087010835

1087110836
log_info!(
1087210837
logger,
@@ -10912,6 +10877,49 @@ where
1091210877
Ok(tx_msg_opt)
1091310878
}
1091410879

10880+
/// Checks during handling splice_ack
10881+
#[cfg(splicing)]
10882+
fn validate_splice_ack(&self, msg: &msgs::SpliceAck) -> Result<FundingScope, ChannelError> {
10883+
// TODO(splicing): Add check that we are the splice (quiescence) initiator
10884+
10885+
let funding_negotiation_context = match &self
10886+
.pending_splice
10887+
.as_ref()
10888+
.ok_or(ChannelError::Ignore(format!("Channel is not in pending splice")))?
10889+
.funding_negotiation
10890+
{
10891+
Some(FundingNegotiation::AwaitingAck(context)) => context,
10892+
Some(FundingNegotiation::ConstructingTransaction(_, _))
10893+
| Some(FundingNegotiation::AwaitingSignatures(_)) => {
10894+
return Err(ChannelError::WarnAndDisconnect(format!(
10895+
"Got unexpected splice_ack; splice negotiation already in progress"
10896+
)));
10897+
},
10898+
None => {
10899+
return Err(ChannelError::Ignore(format!(
10900+
"Got unexpected splice_ack; no splice negotiation in progress"
10901+
)));
10902+
},
10903+
};
10904+
10905+
let our_funding_contribution_satoshis =
10906+
funding_negotiation_context.our_funding_contribution_satoshis;
10907+
let their_funding_contribution_satoshis = msg.funding_contribution_satoshis;
10908+
10909+
let splice_funding = FundingScope::for_splice(
10910+
&self.funding,
10911+
&self.context,
10912+
our_funding_contribution_satoshis,
10913+
their_funding_contribution_satoshis,
10914+
msg.funding_pubkey,
10915+
)?;
10916+
10917+
// TODO(splicing): Pre-check for reserve requirement
10918+
// (Note: It should also be checked later at tx_complete)
10919+
10920+
Ok(splice_funding)
10921+
}
10922+
1091510923
#[cfg(splicing)]
1091610924
pub fn splice_locked<NS: Deref, L: Deref>(
1091710925
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,

0 commit comments

Comments
 (0)