Skip to content

Commit 35d6f65

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 a4796a4 commit 35d6f65

File tree

1 file changed

+46
-40
lines changed

1 file changed

+46
-40
lines changed

lightning/src/ln/channel.rs

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11364,7 +11364,6 @@ where
1136411364
Ok(())
1136511365
}
1136611366

11367-
/// See also [`validate_splice_init`]
1136811367
#[cfg(splicing)]
1136911368
pub(crate) fn splice_init<ES: Deref, L: Deref>(
1137011369
&mut self, msg: &msgs::SpliceInit, our_funding_contribution_satoshis: i64,
@@ -11441,7 +11440,6 @@ where
1144111440
})
1144211441
}
1144311442

11444-
/// Handle splice_ack
1144511443
#[cfg(splicing)]
1144611444
pub(crate) fn splice_ack<ES: Deref, L: Deref>(
1144711445
&mut self, msg: &msgs::SpliceAck, signer_provider: &SP, entropy_source: &ES,
@@ -11451,44 +11449,7 @@ where
1145111449
ES::Target: EntropySource,
1145211450
L::Target: Logger,
1145311451
{
11454-
// TODO(splicing): Add check that we are the splice (quiescence) initiator
11455-
11456-
let funding_negotiation_context = match &self
11457-
.pending_splice
11458-
.as_ref()
11459-
.ok_or(ChannelError::Ignore(format!("Channel is not in pending splice")))?
11460-
.funding_negotiation
11461-
{
11462-
Some(FundingNegotiation::AwaitingAck(context)) => context,
11463-
Some(FundingNegotiation::ConstructingTransaction(_, _))
11464-
| Some(FundingNegotiation::AwaitingSignatures(_)) => {
11465-
return Err(ChannelError::WarnAndDisconnect(format!(
11466-
"Got unexpected splice_ack; splice negotiation already in progress"
11467-
)));
11468-
},
11469-
None => {
11470-
return Err(ChannelError::Ignore(format!(
11471-
"Got unexpected splice_ack; no splice negotiation in progress"
11472-
)));
11473-
},
11474-
};
11475-
11476-
let our_funding_contribution = funding_negotiation_context.our_funding_contribution;
11477-
debug_assert!(our_funding_contribution.abs() <= SignedAmount::MAX_MONEY);
11478-
11479-
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
11480-
self.validate_splice_contribution(their_funding_contribution)?;
11481-
11482-
let splice_funding = FundingScope::for_splice(
11483-
&self.funding,
11484-
&self.context,
11485-
our_funding_contribution,
11486-
their_funding_contribution,
11487-
msg.funding_pubkey,
11488-
)?;
11489-
11490-
// TODO(splicing): Pre-check for reserve requirement
11491-
// (Note: It should also be checked later at tx_complete)
11452+
let splice_funding = self.validate_splice_ack(msg)?;
1149211453

1149311454
log_info!(
1149411455
logger,
@@ -11535,6 +11496,51 @@ where
1153511496
Ok(tx_msg_opt)
1153611497
}
1153711498

11499+
/// Checks during handling splice_ack
11500+
#[cfg(splicing)]
11501+
fn validate_splice_ack(&self, msg: &msgs::SpliceAck) -> Result<FundingScope, ChannelError> {
11502+
// TODO(splicing): Add check that we are the splice (quiescence) initiator
11503+
11504+
let funding_negotiation_context = match &self
11505+
.pending_splice
11506+
.as_ref()
11507+
.ok_or(ChannelError::Ignore(format!("Channel is not in pending splice")))?
11508+
.funding_negotiation
11509+
{
11510+
Some(FundingNegotiation::AwaitingAck(context)) => context,
11511+
Some(FundingNegotiation::ConstructingTransaction(_, _))
11512+
| Some(FundingNegotiation::AwaitingSignatures(_)) => {
11513+
return Err(ChannelError::WarnAndDisconnect(format!(
11514+
"Got unexpected splice_ack; splice negotiation already in progress"
11515+
)));
11516+
},
11517+
None => {
11518+
return Err(ChannelError::Ignore(format!(
11519+
"Got unexpected splice_ack; no splice negotiation in progress"
11520+
)));
11521+
},
11522+
};
11523+
11524+
let our_funding_contribution = funding_negotiation_context.our_funding_contribution;
11525+
debug_assert!(our_funding_contribution.abs() <= SignedAmount::MAX_MONEY);
11526+
11527+
let their_funding_contribution = SignedAmount::from_sat(msg.funding_contribution_satoshis);
11528+
self.validate_splice_contribution(their_funding_contribution)?;
11529+
11530+
let splice_funding = FundingScope::for_splice(
11531+
&self.funding,
11532+
&self.context,
11533+
our_funding_contribution,
11534+
their_funding_contribution,
11535+
msg.funding_pubkey,
11536+
)?;
11537+
11538+
// TODO(splicing): Pre-check for reserve requirement
11539+
// (Note: It should also be checked later at tx_complete)
11540+
11541+
Ok(splice_funding)
11542+
}
11543+
1153811544
#[cfg(splicing)]
1153911545
pub fn splice_locked<NS: Deref, L: Deref>(
1154011546
&mut self, msg: &msgs::SpliceLocked, node_signer: &NS, chain_hash: ChainHash,

0 commit comments

Comments
 (0)