X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-invoice%2Fsrc%2Fpayment.rs;h=cadb595e719276e5fb8aa88f74c347b6d185ee57;hb=559ed20f92cb86b02094421fa51ad243dbf800b6;hp=226e8fe42b8982cfe58e3fc8917a149cc86078d1;hpb=4910c7cffee4ce35de44c0bef361c2d822daacde;p=rust-lightning diff --git a/lightning-invoice/src/payment.rs b/lightning-invoice/src/payment.rs index 226e8fe4..cadb595e 100644 --- a/lightning-invoice/src/payment.rs +++ b/lightning-invoice/src/payment.rs @@ -149,6 +149,7 @@ use lightning::routing::router::{PaymentParameters, Route, RouteHop, RouteParame use lightning::util::errors::APIError; use lightning::util::events::{Event, EventHandler}; use lightning::util::logger::Logger; +use lightning::util::ser::Writeable; use time_utils::Time; use crate::sync::Mutex; @@ -473,11 +474,11 @@ where }, PaymentSendFailure::PartialFailure { failed_paths_retry, payment_id, results } => { // If a `PartialFailure` event returns a result that is an `Ok()`, it means that - // part of our payment is retried. When we receive `MonitorUpdateFailed`, it + // part of our payment is retried. When we receive `MonitorUpdateInProgress`, it // means that we are still waiting for our channel monitor update to be completed. for (result, path) in results.iter().zip(route.paths.into_iter()) { match result { - Ok(_) | Err(APIError::MonitorUpdateFailed) => { + Ok(_) | Err(APIError::MonitorUpdateInProgress) => { self.process_path_inflight_htlcs(payment_hash, path); }, _ => {}, @@ -577,11 +578,11 @@ where }, Err(PaymentSendFailure::PartialFailure { failed_paths_retry, results, .. }) => { // If a `PartialFailure` error contains a result that is an `Ok()`, it means that - // part of our payment is retried. When we receive `MonitorUpdateFailed`, it + // part of our payment is retried. When we receive `MonitorUpdateInProgress`, it // means that we are still waiting for our channel monitor update to complete. for (result, path) in results.iter().zip(route.unwrap().paths.into_iter()) { match result { - Ok(_) | Err(APIError::MonitorUpdateFailed) => { + Ok(_) | Err(APIError::MonitorUpdateInProgress) => { self.process_path_inflight_htlcs(payment_hash, path); }, _ => {}, @@ -741,12 +742,12 @@ pub struct InFlightHtlcs(HashMap<(u64, bool), u64>); impl InFlightHtlcs { /// Returns liquidity in msat given the public key of the HTLC source, target, and short channel /// id. - pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option<&u64> { - self.0.get(&(channel_scid, source < target)) + pub fn used_liquidity_msat(&self, source: &NodeId, target: &NodeId, channel_scid: u64) -> Option { + self.0.get(&(channel_scid, source < target)).map(|v| *v) } } -impl lightning::util::ser::Writeable for InFlightHtlcs { +impl Writeable for InFlightHtlcs { fn write(&self, writer: &mut W) -> Result<(), io::Error> { self.0.write(writer) } } @@ -781,7 +782,7 @@ mod tests { use std::time::{SystemTime, Duration}; use time_utils::tests::SinceEpoch; use DEFAULT_EXPIRY_TIME; - use lightning::util::errors::APIError::{ChannelUnavailable, MonitorUpdateFailed}; + use lightning::util::errors::APIError::{ChannelUnavailable, MonitorUpdateInProgress}; fn invoice(payment_preimage: PaymentPreimage) -> Invoice { let payment_hash = Sha256::hash(&payment_preimage.0); @@ -1682,7 +1683,7 @@ mod tests { .fails_with_partial_failure( retry.clone(), OnAttempt(1), Some(vec![ - Err(ChannelUnavailable { err: "abc".to_string() }), Err(MonitorUpdateFailed) + Err(ChannelUnavailable { err: "abc".to_string() }), Err(MonitorUpdateInProgress) ])) .expect_send(Amount::ForInvoice(final_value_msat)); @@ -1694,7 +1695,7 @@ mod tests { invoice_payer.pay_invoice(&invoice_to_pay).unwrap(); let inflight_map = invoice_payer.create_inflight_map(); - // Only the second path, which failed with `MonitorUpdateFailed` should be added to our + // Only the second path, which failed with `MonitorUpdateInProgress` should be added to our // inflight map because retries are disabled. assert_eq!(inflight_map.0.len(), 2); } @@ -1713,7 +1714,7 @@ mod tests { .fails_with_partial_failure( retry.clone(), OnAttempt(1), Some(vec![ - Ok(()), Err(MonitorUpdateFailed) + Ok(()), Err(MonitorUpdateInProgress) ])) .expect_send(Amount::ForInvoice(final_value_msat)); @@ -1912,7 +1913,7 @@ mod tests { #[cfg(c_bindings)] impl lightning::util::ser::Writeable for TestScorer { - fn write(&self, _: &mut W) -> Result<(), std::io::Error> { unreachable!(); } + fn write(&self, _: &mut W) -> Result<(), lightning::io::Error> { unreachable!(); } } impl Score for TestScorer { @@ -2038,7 +2039,7 @@ mod tests { } fn fails_on_attempt(self, attempt: usize) -> Self { - let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateFailed); + let failure = PaymentSendFailure::ParameterError(APIError::MonitorUpdateInProgress); self.fails_with(failure, OnAttempt(attempt)) }