Skip to content

Commit 05876f5

Browse files
committed
fix Change error type from Channel::splice_init
1 parent b9f9022 commit 05876f5

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
@@ -8243,26 +8243,30 @@ impl<SP: Deref> FundedChannel<SP> where
82438243
pub fn splice_channel(&mut self, our_funding_contribution_satoshis: i64,
82448244
our_funding_inputs: Vec<(TxIn, Transaction, Weight)>,
82458245
funding_feerate_per_kw: u32, locktime: u32,
8246-
) -> Result<msgs::SpliceInit, ChannelError> {
8246+
) -> Result<msgs::SpliceInit, APIError> {
82478247
// Check if a splice has been initiated already.
82488248
// Note: only a single outstanding splice is supported (per spec)
82498249
if let Some(splice_info) = &self.pending_splice_pre {
8250-
return Err(ChannelError::Warn(format!(
8251-
"Channel has already a splice pending, contribution {}", splice_info.our_funding_contribution
8252-
)));
8250+
return Err(APIError::APIMisuseError { err: format!(
8251+
"Channel {} cannot be spliced, as it has already a splice pending (contribution {})",
8252+
self.context.channel_id(), splice_info.our_funding_contribution
8253+
)});
82538254
}
82548255

82558256
if !matches!(self.context.channel_state, ChannelState::ChannelReady(_)) {
8256-
return Err(ChannelError::Warn(format!("Cannot initiate splicing, as channel is not Ready")));
8257+
return Err(APIError::APIMisuseError { err: format!(
8258+
"Channel {} cannot be spliced, as channel is not Ready",
8259+
self.context.channel_id()
8260+
)});
82578261
}
82588262

82598263
// TODO(splicing): check for quiescence
82608264

82618265
if our_funding_contribution_satoshis < 0 {
8262-
return Err(ChannelError::Warn(format!(
8263-
"TODO(splicing): Splice-out not supported, only splice in, contribution {}",
8264-
our_funding_contribution_satoshis,
8265-
)));
8266+
return Err(APIError::APIMisuseError { err: format!(
8267+
"TODO(splicing): Splice-out not supported, only splice in; channel ID {}, contribution {}",
8268+
self.context.channel_id(), our_funding_contribution_satoshis,
8269+
)});
82668270
}
82678271

82688272
// TODO(splicing): Once splice-out is supported, check that channel balance does not go below 0
@@ -8274,7 +8278,11 @@ impl<SP: Deref> FundedChannel<SP> where
82748278
// Check that inputs are sufficient to cover our contribution.
82758279
// Extra common weight is the weight for spending the old funding
82768280
let extra_input_weight = Weight::from_wu(FUNDING_TRANSACTION_WITNESS_WEIGHT);
8277-
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)?;
8281+
let _fee = check_v2_funding_inputs_sufficient(our_funding_contribution_satoshis, &our_funding_inputs, true, Some(extra_input_weight), funding_feerate_per_kw)
8282+
.map_err(|err| APIError::APIMisuseError { err: format!(
8283+
"Insufficient inputs for splicing; channel ID {}, err {}",
8284+
self.context.channel_id(), err,
8285+
)})?;
82788286

82798287
self.pending_splice_pre = Some(PendingSplice {
82808288
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
@@ -4260,12 +4260,7 @@ where
42604260
hash_map::Entry::Occupied(mut chan_phase_entry) => {
42614261
let locktime = locktime.unwrap_or(self.current_best_block().height);
42624262
if let Some(chan) = chan_phase_entry.get_mut().as_funded_mut() {
4263-
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)
4264-
.map_err(|err| APIError::APIMisuseError {
4265-
err: format!(
4266-
"Cannot initiate Splicing, {}, channel ID {}", err, channel_id
4267-
)
4268-
})?;
4263+
let msg = chan.splice_channel(our_funding_contribution_satoshis, our_funding_inputs, funding_feerate_per_kw, locktime)?;
42694264

42704265
peer_state.pending_msg_events.push(events::MessageSendEvent::SendSpliceInit {
42714266
node_id: *counterparty_node_id,

0 commit comments

Comments
 (0)