From e0820aee432c49ac88646bbcc17dbbedb6d26298 Mon Sep 17 00:00:00 2001 From: Valentine Wallace Date: Thu, 1 Dec 2022 01:08:55 -0500 Subject: [PATCH] Rename APIError::RouteError to ::InvalidRoute Soon we're going to need to return an error when ChannelManager is unable to find a route, so we'll need a way to distinguish between that and the user supplying an invalid route. --- fuzz/src/chanmon_consistency.rs | 2 +- lightning/src/ln/channelmanager.rs | 16 ++++++++-------- lightning/src/ln/functional_tests.rs | 2 +- lightning/src/ln/onion_utils.rs | 4 ++-- lightning/src/util/errors.rs | 4 ++-- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/fuzz/src/chanmon_consistency.rs b/fuzz/src/chanmon_consistency.rs index 783bbc06..6c1d4348 100644 --- a/fuzz/src/chanmon_consistency.rs +++ b/fuzz/src/chanmon_consistency.rs @@ -253,7 +253,7 @@ fn check_api_err(api_err: APIError) { match api_err { APIError::APIMisuseError { .. } => panic!("We can't misuse the API"), APIError::FeeRateTooHigh { .. } => panic!("We can't send too much fee?"), - APIError::RouteError { .. } => panic!("Our routes should work"), + APIError::InvalidRoute { .. } => panic!("Our routes should work"), APIError::ChannelUnavailable { err } => { // Test the error against a list of errors we can hit, and reject // all others. If you hit this panic, the list of acceptable errors diff --git a/lightning/src/ln/channelmanager.rs b/lightning/src/ln/channelmanager.rs index 35b240e4..c45a0abf 100644 --- a/lightning/src/ln/channelmanager.rs +++ b/lightning/src/ln/channelmanager.rs @@ -2407,10 +2407,10 @@ impl ChannelManager ChannelManager ChannelManager ChannelManager ChannelManager, keysend_preimage: Option, payment_id: PaymentId, recv_value_msat: Option, onion_session_privs: Vec<[u8; 32]>) -> Result<(), PaymentSendFailure> { if route.paths.len() < 1 { - return Err(PaymentSendFailure::ParameterError(APIError::RouteError{err: "There must be at least one path to send over"})); + return Err(PaymentSendFailure::ParameterError(APIError::InvalidRoute{err: "There must be at least one path to send over"})); } if payment_secret.is_none() && route.paths.len() > 1 { return Err(PaymentSendFailure::ParameterError(APIError::APIMisuseError{err: "Payment secret is required for multi-path payments".to_string()})); @@ -2596,12 +2596,12 @@ impl ChannelManager 20 { - path_errs.push(Err(APIError::RouteError{err: "Path didn't go anywhere/had bogus size"})); + path_errs.push(Err(APIError::InvalidRoute{err: "Path didn't go anywhere/had bogus size"})); continue 'path_check; } for (idx, hop) in path.iter().enumerate() { if idx != path.len() - 1 && hop.pubkey == our_node_id { - path_errs.push(Err(APIError::RouteError{err: "Path went through us but wasn't a simple rebalance loop to us"})); + path_errs.push(Err(APIError::InvalidRoute{err: "Path went through us but wasn't a simple rebalance loop to us"})); continue 'path_check; } } diff --git a/lightning/src/ln/functional_tests.rs b/lightning/src/ln/functional_tests.rs index d8dcb013..c0d6eb2c 100644 --- a/lightning/src/ln/functional_tests.rs +++ b/lightning/src/ln/functional_tests.rs @@ -6023,7 +6023,7 @@ fn test_update_add_htlc_bolt2_sender_cltv_expiry_too_high() { .with_features(channelmanager::provided_invoice_features()); let (mut route, our_payment_hash, _, our_payment_secret) = get_route_and_payment_hash!(nodes[0], nodes[1], payment_params, 100000000, 0); route.paths[0].last_mut().unwrap().cltv_expiry_delta = 500000001; - unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), PaymentId(our_payment_hash.0)), true, APIError::RouteError { ref err }, + unwrap_send_err!(nodes[0].node.send_payment(&route, our_payment_hash, &Some(our_payment_secret), PaymentId(our_payment_hash.0)), true, APIError::InvalidRoute { ref err }, assert_eq!(err, &"Channel CLTV overflowed?")); } diff --git a/lightning/src/ln/onion_utils.rs b/lightning/src/ln/onion_utils.rs index 23dc556c..6f85e2db 100644 --- a/lightning/src/ln/onion_utils.rs +++ b/lightning/src/ln/onion_utils.rs @@ -182,11 +182,11 @@ pub(super) fn build_onion_payloads(path: &Vec, total_msat: u64, paymen }); cur_value_msat += hop.fee_msat; if cur_value_msat >= 21000000 * 100000000 * 1000 { - return Err(APIError::RouteError{err: "Channel fees overflowed?"}); + return Err(APIError::InvalidRoute{err: "Channel fees overflowed?"}); } cur_cltv += hop.cltv_expiry_delta as u32; if cur_cltv >= 500000000 { - return Err(APIError::RouteError{err: "Channel CLTV overflowed?"}); + return Err(APIError::InvalidRoute{err: "Channel CLTV overflowed?"}); } last_short_channel_id = hop.short_channel_id; } diff --git a/lightning/src/util/errors.rs b/lightning/src/util/errors.rs index 092f104b..17e55a97 100644 --- a/lightning/src/util/errors.rs +++ b/lightning/src/util/errors.rs @@ -35,7 +35,7 @@ pub enum APIError { }, /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route, /// too-many-hops, etc). - RouteError { + InvalidRoute { /// A human-readable error message err: &'static str }, @@ -74,7 +74,7 @@ impl fmt::Debug for APIError { match *self { APIError::APIMisuseError {ref err} => write!(f, "Misuse error: {}", err), APIError::FeeRateTooHigh {ref err, ref feerate} => write!(f, "{} feerate: {}", err, feerate), - APIError::RouteError {ref err} => write!(f, "Route error: {}", err), + APIError::InvalidRoute {ref err} => write!(f, "Invalid route provided: {}", err), APIError::ChannelUnavailable {ref err} => write!(f, "Channel unavailable: {}", err), APIError::MonitorUpdateInProgress => f.write_str("Client indicated a channel monitor update is in progress but not yet complete"), APIError::IncompatibleShutdownScript { ref script } => { -- 2.30.2