@@ -55,9 +55,7 @@ use crate::ln::channel_state::ChannelDetails;
55
55
use crate::types::features::{Bolt12InvoiceFeatures, ChannelFeatures, ChannelTypeFeatures, InitFeatures, NodeFeatures};
56
56
#[cfg(any(feature = "_test_utils", test))]
57
57
use crate::types::features::Bolt11InvoiceFeatures;
58
- use crate::routing::router::{BlindedTail, InFlightHtlcs, Path, Payee, PaymentParameters, RouteParameters, Router};
59
- #[cfg(test)]
60
- use crate::routing::router::Route;
58
+ use crate::routing::router::{BlindedTail, CachingRouter, InFlightHtlcs, Path, Payee, PaymentParameters, Route, RouteParameters, Router};
61
59
use crate::ln::onion_payment::{check_incoming_htlc_cltv, create_recv_pending_htlc_info, create_fwd_pending_htlc_info, decode_incoming_update_add_htlc_onion, InboundHTLCErr, NextPacketDetails};
62
60
use crate::ln::msgs;
63
61
use crate::ln::onion_utils;
@@ -2390,10 +2388,7 @@ where
2390
2388
fee_estimator: LowerBoundedFeeEstimator<F>,
2391
2389
chain_monitor: M,
2392
2390
tx_broadcaster: T,
2393
- #[cfg(fuzzing)]
2394
- pub router: R,
2395
- #[cfg(not(fuzzing))]
2396
- router: R,
2391
+ router: CachingRouter<R>,
2397
2392
message_router: MR,
2398
2393
2399
2394
/// See `ChannelManager` struct-level documentation for lock order requirements.
@@ -3503,7 +3498,7 @@ where
3503
3498
fee_estimator: LowerBoundedFeeEstimator::new(fee_est),
3504
3499
chain_monitor,
3505
3500
tx_broadcaster,
3506
- router,
3501
+ router: CachingRouter::new(router) ,
3507
3502
message_router,
3508
3503
3509
3504
best_block: RwLock::new(params.best_block),
@@ -4606,21 +4601,21 @@ where
4606
4601
}
4607
4602
}
4608
4603
4609
- // Deprecated send method, for testing use [`Self::send_payment`] and
4610
- // [`TestRouter::expect_find_route`] instead.
4611
- //
4612
- // [`TestRouter::expect_find_route`]: crate::util::test_utils::TestRouter::expect_find_route
4613
- #[cfg(test)]
4614
- pub(crate) fn send_payment_with_route(
4604
+ /// Sends a payment along a given route. See [`Self::send_payment`] for more info.
4605
+ /// [`Route::route_params`] is required to be `Some`.
4606
+ pub fn send_payment_with_route(
4615
4607
&self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
4616
4608
payment_id: PaymentId
4617
- ) -> Result<(), PaymentSendFailure > {
4609
+ ) -> Result<(), RetryableSendFailure > {
4618
4610
let best_block_height = self.best_block.read().unwrap().height;
4619
4611
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4612
+ let route_params = route.route_params.clone().ok_or(RetryableSendFailure::RouteNotFound)?;
4613
+ self.router.route_cache.lock().unwrap().insert(payment_id, route);
4620
4614
self.pending_outbound_payments
4621
- .send_payment_with_route(&route, payment_hash, recipient_onion, payment_id,
4622
- &self.entropy_source, &self.node_signer, best_block_height,
4623
- |args| self.send_payment_along_path(args))
4615
+ .send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),
4616
+ route_params, &self.router, self.list_usable_channels(), ||
4617
+ self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
4618
+ &self.logger, &self.pending_events, |args| self.send_payment_along_path(args))
4624
4619
}
4625
4620
4626
4621
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -4649,7 +4644,8 @@ where
4649
4644
/// [`ChannelManager::list_recent_payments`] for more information.
4650
4645
///
4651
4646
/// Routes are automatically found using the [`Router] provided on startup. To fix a route for a
4652
- /// particular payment, match the [`PaymentId`] passed to [`Router::find_route_with_id`].
4647
+ /// particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to
4648
+ /// [`Router::find_route_with_id`].
4653
4649
///
4654
4650
/// [`Event::PaymentSent`]: events::Event::PaymentSent
4655
4651
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
@@ -4664,7 +4660,7 @@ where
4664
4660
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4665
4661
self.pending_outbound_payments
4666
4662
.send_payment(payment_hash, recipient_onion, payment_id, retry_strategy, route_params,
4667
- &* self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4663
+ &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4668
4664
&self.entropy_source, &self.node_signer, best_block_height, &self.logger,
4669
4665
&self.pending_events, |args| self.send_payment_along_path(args))
4670
4666
}
@@ -4741,7 +4737,7 @@ where
4741
4737
let features = self.bolt12_invoice_features();
4742
4738
self.pending_outbound_payments
4743
4739
.send_payment_for_bolt12_invoice(
4744
- invoice, payment_id, &* self.router, self.list_usable_channels(), features,
4740
+ invoice, payment_id, &self.router, self.list_usable_channels(), features,
4745
4741
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, &self,
4746
4742
&self.secp_ctx, best_block_height, &self.logger, &self.pending_events,
4747
4743
|args| self.send_payment_along_path(args)
@@ -4816,7 +4812,7 @@ where
4816
4812
let mut res = Ok(());
4817
4813
PersistenceNotifierGuard::optionally_notify(self, || {
4818
4814
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
4819
- payment_id, &* self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4815
+ payment_id, &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4820
4816
&self.entropy_source, &self.node_signer, &self, &self.secp_ctx, best_block_height,
4821
4817
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args)
4822
4818
);
@@ -4892,7 +4888,7 @@ where
4892
4888
let best_block_height = self.best_block.read().unwrap().height;
4893
4889
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4894
4890
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
4895
- payment_id, retry_strategy, route_params, &* self.router, self.list_usable_channels(),
4891
+ payment_id, retry_strategy, route_params, &self.router, self.list_usable_channels(),
4896
4892
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
4897
4893
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args))
4898
4894
}
@@ -6266,7 +6262,7 @@ where
6266
6262
}
6267
6263
6268
6264
let best_block_height = self.best_block.read().unwrap().height;
6269
- self.pending_outbound_payments.check_retry_payments(&* self.router, || self.list_usable_channels(),
6265
+ self.pending_outbound_payments.check_retry_payments(&self.router, || self.list_usable_channels(),
6270
6266
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
6271
6267
&self.pending_events, &self.logger, |args| self.send_payment_along_path(args));
6272
6268
@@ -14084,7 +14080,7 @@ where
14084
14080
fee_estimator: bounded_fee_estimator,
14085
14081
chain_monitor: args.chain_monitor,
14086
14082
tx_broadcaster: args.tx_broadcaster,
14087
- router: args.router,
14083
+ router: CachingRouter::new( args.router) ,
14088
14084
message_router: args.message_router,
14089
14085
14090
14086
best_block: RwLock::new(BestBlock::new(best_block_hash, best_block_height)),
@@ -14331,7 +14327,7 @@ mod tests {
14331
14327
use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
14332
14328
use crate::ln::types::ChannelId;
14333
14329
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
14334
- use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
14330
+ use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, RecipientOnionFields, InterceptId};
14335
14331
use crate::ln::functional_test_utils::*;
14336
14332
use crate::ln::msgs::{self, ErrorAction};
14337
14333
use crate::ln::msgs::ChannelMessageHandler;
@@ -14757,14 +14753,17 @@ mod tests {
14757
14753
route.paths[1].hops[0].short_channel_id = chan_2_id;
14758
14754
route.paths[1].hops[1].short_channel_id = chan_4_id;
14759
14755
14760
- match nodes[0].node.send_payment_with_route(route, payment_hash,
14761
- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0))
14762
- .unwrap_err() {
14763
- PaymentSendFailure::ParameterError(APIError::APIMisuseError { ref err }) => {
14764
- assert!(regex::Regex::new(r"Payment secret is required for multi-path payments").unwrap().is_match(err))
14765
- },
14766
- _ => panic!("unexpected error")
14756
+ nodes[0].node.send_payment_with_route(route, payment_hash,
14757
+ RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0)).unwrap();
14758
+ let events = nodes[0].node.get_and_clear_pending_events();
14759
+ assert_eq!(events.len(), 1);
14760
+ match events[0] {
14761
+ Event::PaymentFailed { reason, .. } => {
14762
+ assert_eq!(reason.unwrap(), crate::events::PaymentFailureReason::UnexpectedError);
14763
+ }
14764
+ _ => panic!()
14767
14765
}
14766
+ nodes[0].logger.assert_log_contains("lightning::ln::outbound_payment", "Payment secret is required for multi-path payments", 2);
14768
14767
assert!(nodes[0].node.pending_outbound_payments.pending_outbound_payments.lock().unwrap().is_empty());
14769
14768
}
14770
14769
0 commit comments