Skip to content

Commit c5e5866

Browse files
committed
fix Change error type from Channel::splice_init
1 parent 25ae6d8 commit c5e5866

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

lightning/src/ln/channel.rs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8418,26 +8418,30 @@ impl<SP: Deref> FundedChannel<SP> where
84188418
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
84198419
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
84208420
funding_feerate_per_kw: u32, locktime: u32,
8421-
) -> Result<msgs::SpliceInit, ChannelError> {
8421+
) -> Result<msgs::SpliceInit, APIError> {
84228422
// Check if a splice has been initiated already.
84238423
// Note: only a single outstanding splice is supported (per spec)
84248424
if let Some(splice_info) = &self.pending_splice_pre {
8425-
return Err(ChannelError::Warn(format!(
8426-
"Channel has already a splice pending, contribution {}", splice_info.our_funding_contribution
8427-
)));
8425+
return Err(APIError::APIMisuseError { err: format!(
8426+
"Channel {} cannot be spliced, as it has already a splice pending (contribution {})",
8427+
self.context.channel_id(), splice_info.our_funding_contribution
8428+
)});
84288429
}
84298430

84308431
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
8431-
return Err(ChannelError::Warn(format!("Cannot initiate splicing, as channel is not Ready")));
8432+
return Err(APIError::APIMisuseError { err: format!(
8433+
"Channel {} cannot be spliced, as channel is not Ready",
8434+
self.context.channel_id()
8435+
)});
84328436
}
84338437

84348438
// TODO(splicing): check for quiescence
84358439

84368440
if our_funding_contribution_satoshis < 0 {
8437-
return Err(ChannelError::Warn(format!(
8438-
"TODO(splicing): Splice-out not supported, only splice in, contribution {}",
8439-
our_funding_contribution_satoshis,
8440-
)));
8441+
return Err(APIError::APIMisuseError { err: format!(
8442+
"TODO(splicing): Splice-out not supported, only splice in; channel ID {}, contribution {}",
8443+
self.context.channel_id(), our_funding_contribution_satoshis,
8444+
)});
84418445
}
84428446

84438447
// TODO(splicing): Once splice-out is supported, check that channel balance does not go below 0
@@ -8449,7 +8453,11 @@ impl<SP: Deref> FundedChannel<SP> where
84498453
// Check that inputs are sufficient to cover our contribution.
84508454
// Extra common weight is the weight for spending the old funding
84518455
let extra_input_weight = Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
8452-
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)?;
8456+
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)
8457+
.map_err(|err| APIError::APIMisuseError { err: format!(
8458+
"Insufficient inputs for splicing; channel ID {}, err {}",
8459+
self.context.channel_id(), err,
8460+
)})?;
84538461

84548462
self.pending_splice_pre = Some(PendingSplice {
84558463
our_funding_contribution: our_funding_contribution_satoshis,

lightning/src/ln/channelmanager.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4307,12 +4307,7 @@ where
43074307
hash_map::Entry::Occupied(mut chan_phase_entry) => {
43084308
let locktime = locktime.unwrap_or(self.current_best_block().height);
43094309
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4310-
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)
4311-
.map_err(|err| APIError::APIMisuseError {
4312-
err: format!(
4313-
"Cannot initiate Splicing, {}, channel ID {}", err, channel_id
4314-
)
4315-
})?;
4310+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)?;
43164311

43174312
peer_state.pending_msg_events.push(events::MessageSendEvent::SendSpliceInit {
43184313
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)