Skip to content

Commit 2a6501a

Browse files
committed
Correct error types for outbound splice checking methods
When doing an outbound splice, we check some of the instructions first in utility methods, then convert errors to `APIError`s. These utility methods should thus either return an `APIError` or more generic (string or `()`) error type, but they currently return a `ChannelError`, which is only approprite when the calling code will do what the `ChannelError` instructs (including closing the channel). Here we fix that by returning `String`s instead.
1 parent a18f362 commit 2a6501a

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

lightning/src/ln/channel.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5982,7 +5982,7 @@ fn get_v2_channel_reserve_satoshis(channel_value_satoshis: u64, dust_limit_satos
59825982
fn check_splice_contribution_sufficient(
59835983
channel_balance: Amount, contribution: &SpliceContribution, is_initiator: bool,
59845984
funding_feerate: FeeRate,
5985-
) -> Result<Amount, ChannelError> {
5985+
) -> Result<Amount, String> {
59865986
let contribution_amount = contribution.value();
59875987
if contribution_amount < SignedAmount::ZERO {
59885988
let estimated_fee = Amount::from_sat(estimate_v2_funding_transaction_fee(
@@ -5996,10 +5996,10 @@ fn check_splice_contribution_sufficient(
59965996
if channel_balance >= contribution_amount.unsigned_abs() + estimated_fee {
59975997
Ok(estimated_fee)
59985998
} else {
5999-
Err(ChannelError::Warn(format!(
6000-
"Available channel balance {} is lower than needed for splicing out {}, considering fees of {}",
6001-
channel_balance, contribution_amount.unsigned_abs(), estimated_fee,
6002-
)))
5999+
Err(format!(
6000+
"Available channel balance {channel_balance} is lower than needed for splicing out {}, considering fees of {estimated_fee}",
6001+
contribution_amount.unsigned_abs(),
6002+
))
60036003
}
60046004
} else {
60056005
check_v2_funding_inputs_sufficient(
@@ -6066,7 +6066,7 @@ fn estimate_v2_funding_transaction_fee(
60666066
fn check_v2_funding_inputs_sufficient(
60676067
contribution_amount: i64, funding_inputs: &[FundingTxInput], is_initiator: bool,
60686068
is_splice: bool, funding_feerate_sat_per_1000_weight: u32,
6069-
) -> Result<u64, ChannelError> {
6069+
) -> Result<u64, String> {
60706070
let estimated_fee = estimate_v2_funding_transaction_fee(
60716071
funding_inputs, &[], is_initiator, is_splice, funding_feerate_sat_per_1000_weight,
60726072
);
@@ -6089,10 +6089,9 @@ fn check_v2_funding_inputs_sufficient(
60896089

60906090
let minimal_input_amount_needed = contribution_amount.saturating_add(estimated_fee as i64);
60916091
if (total_input_sats as i64) < minimal_input_amount_needed {
6092-
Err(ChannelError::Warn(format!(
6093-
"Total input amount {} is lower than needed for contribution {}, considering fees of {}. Need more inputs.",
6094-
total_input_sats, contribution_amount, estimated_fee,
6095-
)))
6092+
Err(format!(
6093+
"Total input amount {total_input_sats} is lower than needed for contribution {contribution_amount}, considering fees of {estimated_fee}. Need more inputs.",
6094+
))
60966095
} else {
60976096
Ok(estimated_fee)
60986097
}
@@ -16205,8 +16204,8 @@ mod tests {
1620516204
2000,
1620616205
);
1620716206
assert_eq!(
16208-
format!("{:?}", res.err().unwrap()),
16209-
"Warn: Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1746. Need more inputs.",
16207+
res.err().unwrap(),
16208+
"Total input amount 100000 is lower than needed for contribution 220000, considering fees of 1746. Need more inputs.",
1621016209
);
1621116210
}
1621216211

@@ -16241,8 +16240,8 @@ mod tests {
1624116240
2200,
1624216241
);
1624316242
assert_eq!(
16244-
format!("{:?}", res.err().unwrap()),
16245-
"Warn: Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2522. Need more inputs.",
16243+
res.err().unwrap(),
16244+
"Total input amount 300000 is lower than needed for contribution 298032, considering fees of 2522. Need more inputs.",
1624616245
);
1624716246
}
1624816247

0 commit comments

Comments
 (0)