@@ -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;
@@ -2396,10 +2394,7 @@ where
2396
2394
fee_estimator: LowerBoundedFeeEstimator<F>,
2397
2395
chain_monitor: M,
2398
2396
tx_broadcaster: T,
2399
- #[cfg(fuzzing)]
2400
- pub router: R,
2401
- #[cfg(not(fuzzing))]
2402
- router: R,
2397
+ router: CachingRouter<R>,
2403
2398
message_router: MR,
2404
2399
2405
2400
/// See `ChannelManager` struct-level documentation for lock order requirements.
@@ -3512,7 +3507,7 @@ where
3512
3507
fee_estimator: LowerBoundedFeeEstimator::new(fee_est),
3513
3508
chain_monitor,
3514
3509
tx_broadcaster,
3515
- router,
3510
+ router: CachingRouter::new(router) ,
3516
3511
message_router,
3517
3512
3518
3513
best_block: RwLock::new(params.best_block),
@@ -4621,21 +4616,21 @@ where
4621
4616
}
4622
4617
}
4623
4618
4624
- // Deprecated send method, for testing use [`Self::send_payment`] and
4625
- // [`TestRouter::expect_find_route`] instead.
4626
- //
4627
- // [`TestRouter::expect_find_route`]: crate::util::test_utils::TestRouter::expect_find_route
4628
- #[cfg(test)]
4629
- pub(crate) fn send_payment_with_route(
4619
+ /// Sends a payment along a given route. See [`Self::send_payment`] for more info.
4620
+ /// [`Route::route_params`] is required to be `Some`.
4621
+ pub fn send_payment_with_route(
4630
4622
&self, route: Route, payment_hash: PaymentHash, recipient_onion: RecipientOnionFields,
4631
4623
payment_id: PaymentId
4632
- ) -> Result<(), PaymentSendFailure > {
4624
+ ) -> Result<(), RetryableSendFailure > {
4633
4625
let best_block_height = self.best_block.read().unwrap().height;
4634
4626
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4627
+ let route_params = route.route_params.clone().ok_or(RetryableSendFailure::RouteNotFound)?;
4628
+ self.router.route_cache.lock().unwrap().insert(payment_id, route);
4635
4629
self.pending_outbound_payments
4636
- .send_payment_with_route(&route, payment_hash, recipient_onion, payment_id,
4637
- &self.entropy_source, &self.node_signer, best_block_height,
4638
- |args| self.send_payment_along_path(args))
4630
+ .send_payment(payment_hash, recipient_onion, payment_id, Retry::Attempts(0),
4631
+ route_params, &self.router, self.list_usable_channels(), ||
4632
+ self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
4633
+ &self.logger, &self.pending_events, |args| self.send_payment_along_path(args))
4639
4634
}
4640
4635
4641
4636
/// Sends a payment to the route found using the provided [`RouteParameters`], retrying failed
@@ -4664,7 +4659,8 @@ where
4664
4659
/// [`ChannelManager::list_recent_payments`] for more information.
4665
4660
///
4666
4661
/// Routes are automatically found using the [`Router] provided on startup. To fix a route for a
4667
- /// particular payment, match the [`PaymentId`] passed to [`Router::find_route_with_id`].
4662
+ /// particular payment, use [`Self::send_payment_with_route`] or match the [`PaymentId`] passed to
4663
+ /// [`Router::find_route_with_id`].
4668
4664
///
4669
4665
/// [`Event::PaymentSent`]: events::Event::PaymentSent
4670
4666
/// [`Event::PaymentFailed`]: events::Event::PaymentFailed
@@ -4679,7 +4675,7 @@ where
4679
4675
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4680
4676
self.pending_outbound_payments
4681
4677
.send_payment(payment_hash, recipient_onion, payment_id, retry_strategy, route_params,
4682
- &* self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4678
+ &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4683
4679
&self.entropy_source, &self.node_signer, best_block_height, &self.logger,
4684
4680
&self.pending_events, |args| self.send_payment_along_path(args))
4685
4681
}
@@ -4756,7 +4752,7 @@ where
4756
4752
let features = self.bolt12_invoice_features();
4757
4753
self.pending_outbound_payments
4758
4754
.send_payment_for_bolt12_invoice(
4759
- invoice, payment_id, &* self.router, self.list_usable_channels(), features,
4755
+ invoice, payment_id, &self.router, self.list_usable_channels(), features,
4760
4756
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, &self,
4761
4757
&self.secp_ctx, best_block_height, &self.logger, &self.pending_events,
4762
4758
|args| self.send_payment_along_path(args)
@@ -4831,7 +4827,7 @@ where
4831
4827
let mut res = Ok(());
4832
4828
PersistenceNotifierGuard::optionally_notify(self, || {
4833
4829
let outbound_pmts_res = self.pending_outbound_payments.send_payment_for_static_invoice(
4834
- payment_id, &* self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4830
+ payment_id, &self.router, self.list_usable_channels(), || self.compute_inflight_htlcs(),
4835
4831
&self.entropy_source, &self.node_signer, &self, &self.secp_ctx, best_block_height,
4836
4832
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args)
4837
4833
);
@@ -4907,7 +4903,7 @@ where
4907
4903
let best_block_height = self.best_block.read().unwrap().height;
4908
4904
let _persistence_guard = PersistenceNotifierGuard::notify_on_drop(self);
4909
4905
self.pending_outbound_payments.send_spontaneous_payment(payment_preimage, recipient_onion,
4910
- payment_id, retry_strategy, route_params, &* self.router, self.list_usable_channels(),
4906
+ payment_id, retry_strategy, route_params, &self.router, self.list_usable_channels(),
4911
4907
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
4912
4908
&self.logger, &self.pending_events, |args| self.send_payment_along_path(args))
4913
4909
}
@@ -6263,7 +6259,7 @@ where
6263
6259
}
6264
6260
6265
6261
let best_block_height = self.best_block.read().unwrap().height;
6266
- self.pending_outbound_payments.check_retry_payments(&* self.router, || self.list_usable_channels(),
6262
+ self.pending_outbound_payments.check_retry_payments(&self.router, || self.list_usable_channels(),
6267
6263
|| self.compute_inflight_htlcs(), &self.entropy_source, &self.node_signer, best_block_height,
6268
6264
&self.pending_events, &self.logger, |args| self.send_payment_along_path(args));
6269
6265
@@ -14108,7 +14104,7 @@ where
14108
14104
fee_estimator: bounded_fee_estimator,
14109
14105
chain_monitor: args.chain_monitor,
14110
14106
tx_broadcaster: args.tx_broadcaster,
14111
- router: args.router,
14107
+ router: CachingRouter::new( args.router) ,
14112
14108
message_router: args.message_router,
14113
14109
14114
14110
best_block: RwLock::new(BestBlock::new(best_block_hash, best_block_height)),
@@ -14352,7 +14348,7 @@ mod tests {
14352
14348
use crate::events::{Event, HTLCDestination, MessageSendEvent, MessageSendEventsProvider, ClosureReason};
14353
14349
use crate::ln::types::ChannelId;
14354
14350
use crate::types::payment::{PaymentPreimage, PaymentHash, PaymentSecret};
14355
- use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, PaymentSendFailure, RecipientOnionFields, InterceptId};
14351
+ use crate::ln::channelmanager::{create_recv_pending_htlc_info, HTLCForwardInfo, inbound_payment, PaymentId, RecipientOnionFields, InterceptId};
14356
14352
use crate::ln::functional_test_utils::*;
14357
14353
use crate::ln::msgs::{self, ErrorAction};
14358
14354
use crate::ln::msgs::ChannelMessageHandler;
@@ -14778,14 +14774,17 @@ mod tests {
14778
14774
route.paths[1].hops[0].short_channel_id = chan_2_id;
14779
14775
route.paths[1].hops[1].short_channel_id = chan_4_id;
14780
14776
14781
- match nodes[0].node.send_payment_with_route(route, payment_hash,
14782
- RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0))
14783
- .unwrap_err() {
14784
- PaymentSendFailure::ParameterError(APIError::APIMisuseError { ref err }) => {
14785
- assert!(regex::Regex::new(r"Payment secret is required for multi-path payments").unwrap().is_match(err))
14786
- },
14787
- _ => panic!("unexpected error")
14777
+ nodes[0].node.send_payment_with_route(route, payment_hash,
14778
+ RecipientOnionFields::spontaneous_empty(), PaymentId(payment_hash.0)).unwrap();
14779
+ let events = nodes[0].node.get_and_clear_pending_events();
14780
+ assert_eq!(events.len(), 1);
14781
+ match events[0] {
14782
+ Event::PaymentFailed { reason, .. } => {
14783
+ assert_eq!(reason.unwrap(), crate::events::PaymentFailureReason::UnexpectedError);
14784
+ }
14785
+ _ => panic!()
14788
14786
}
14787
+ nodes[0].logger.assert_log_contains("lightning::ln::outbound_payment", "Payment secret is required for multi-path payments", 2);
14789
14788
assert!(nodes[0].node.pending_outbound_payments.pending_outbound_payments.lock().unwrap().is_empty());
14790
14789
}
14791
14790
0 commit comments