mirror of
https://github.com/lightningdevkit/rust-lightning.git
synced 2025-03-10 13:35:38 +01:00
Pass InFlightHltcs
to the scorer by ownership rather than ref
Given we build `InFlightHtlcs` per route-fetch call, there's no reason to pass them out by reference rather than simply giving the user the full object. This also allows them to tweak the in-flight set before fetching a route.
This commit is contained in:
parent
0c629ff60a
commit
d2c20ecc2d
6 changed files with 12 additions and 12 deletions
|
@ -89,7 +89,7 @@ struct FuzzRouter {}
|
||||||
impl Router for FuzzRouter {
|
impl Router for FuzzRouter {
|
||||||
fn find_route(
|
fn find_route(
|
||||||
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
|
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
|
||||||
_inflight_htlcs: &InFlightHtlcs
|
_inflight_htlcs: InFlightHtlcs
|
||||||
) -> Result<Route, msgs::LightningError> {
|
) -> Result<Route, msgs::LightningError> {
|
||||||
Err(msgs::LightningError {
|
Err(msgs::LightningError {
|
||||||
err: String::from("Not implemented"),
|
err: String::from("Not implemented"),
|
||||||
|
|
|
@ -131,7 +131,7 @@ struct FuzzRouter {}
|
||||||
impl Router for FuzzRouter {
|
impl Router for FuzzRouter {
|
||||||
fn find_route(
|
fn find_route(
|
||||||
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
|
&self, _payer: &PublicKey, _params: &RouteParameters, _first_hops: Option<&[&ChannelDetails]>,
|
||||||
_inflight_htlcs: &InFlightHtlcs
|
_inflight_htlcs: InFlightHtlcs
|
||||||
) -> Result<Route, msgs::LightningError> {
|
) -> Result<Route, msgs::LightningError> {
|
||||||
Err(msgs::LightningError {
|
Err(msgs::LightningError {
|
||||||
err: String::from("Not implemented"),
|
err: String::from("Not implemented"),
|
||||||
|
|
|
@ -669,7 +669,7 @@ impl OutboundPayments {
|
||||||
|
|
||||||
let route = router.find_route_with_id(
|
let route = router.find_route_with_id(
|
||||||
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
|
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
|
||||||
Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs(),
|
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
|
||||||
payment_hash, payment_id,
|
payment_hash, payment_id,
|
||||||
).map_err(|_| RetryableSendFailure::RouteNotFound)?;
|
).map_err(|_| RetryableSendFailure::RouteNotFound)?;
|
||||||
|
|
||||||
|
@ -712,7 +712,7 @@ impl OutboundPayments {
|
||||||
|
|
||||||
let route = match router.find_route_with_id(
|
let route = match router.find_route_with_id(
|
||||||
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
|
&node_signer.get_node_id(Recipient::Node).unwrap(), &route_params,
|
||||||
Some(&first_hops.iter().collect::<Vec<_>>()), &inflight_htlcs(),
|
Some(&first_hops.iter().collect::<Vec<_>>()), inflight_htlcs(),
|
||||||
payment_hash, payment_id,
|
payment_hash, payment_id,
|
||||||
) {
|
) {
|
||||||
Ok(route) => route,
|
Ok(route) => route,
|
||||||
|
|
|
@ -3218,7 +3218,7 @@ fn do_claim_from_closed_chan(fail_payment: bool) {
|
||||||
final_value_msat: 10_000_000,
|
final_value_msat: 10_000_000,
|
||||||
};
|
};
|
||||||
let mut route = nodes[0].router.find_route(&nodes[0].node.get_our_node_id(), &route_params,
|
let mut route = nodes[0].router.find_route(&nodes[0].node.get_our_node_id(), &route_params,
|
||||||
None, &nodes[0].node.compute_inflight_htlcs()).unwrap();
|
None, nodes[0].node.compute_inflight_htlcs()).unwrap();
|
||||||
// Make sure the route is ordered as the B->D path before C->D
|
// Make sure the route is ordered as the B->D path before C->D
|
||||||
route.paths.sort_by(|a, _| if a.hops[0].pubkey == nodes[1].node.get_our_node_id() {
|
route.paths.sort_by(|a, _| if a.hops[0].pubkey == nodes[1].node.get_our_node_id() {
|
||||||
std::cmp::Ordering::Less } else { std::cmp::Ordering::Greater });
|
std::cmp::Ordering::Less } else { std::cmp::Ordering::Greater });
|
||||||
|
|
|
@ -64,7 +64,7 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Sco
|
||||||
payer: &PublicKey,
|
payer: &PublicKey,
|
||||||
params: &RouteParameters,
|
params: &RouteParameters,
|
||||||
first_hops: Option<&[&ChannelDetails]>,
|
first_hops: Option<&[&ChannelDetails]>,
|
||||||
inflight_htlcs: &InFlightHtlcs
|
inflight_htlcs: InFlightHtlcs
|
||||||
) -> Result<Route, LightningError> {
|
) -> Result<Route, LightningError> {
|
||||||
let random_seed_bytes = {
|
let random_seed_bytes = {
|
||||||
let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
|
let mut locked_random_seed_bytes = self.random_seed_bytes.lock().unwrap();
|
||||||
|
@ -73,7 +73,7 @@ impl< G: Deref<Target = NetworkGraph<L>>, L: Deref, S: Deref, SP: Sized, Sc: Sco
|
||||||
};
|
};
|
||||||
find_route(
|
find_route(
|
||||||
payer, params, &self.network_graph, first_hops, &*self.logger,
|
payer, params, &self.network_graph, first_hops, &*self.logger,
|
||||||
&ScorerAccountingForInFlightHtlcs::new(self.scorer.lock().deref_mut(), inflight_htlcs),
|
&ScorerAccountingForInFlightHtlcs::new(self.scorer.lock().deref_mut(), &inflight_htlcs),
|
||||||
&self.score_params,
|
&self.score_params,
|
||||||
&random_seed_bytes
|
&random_seed_bytes
|
||||||
)
|
)
|
||||||
|
@ -85,13 +85,13 @@ pub trait Router {
|
||||||
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
|
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values.
|
||||||
fn find_route(
|
fn find_route(
|
||||||
&self, payer: &PublicKey, route_params: &RouteParameters,
|
&self, payer: &PublicKey, route_params: &RouteParameters,
|
||||||
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs
|
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs
|
||||||
) -> Result<Route, LightningError>;
|
) -> Result<Route, LightningError>;
|
||||||
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
|
/// Finds a [`Route`] between `payer` and `payee` for a payment with the given values. Includes
|
||||||
/// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
|
/// `PaymentHash` and `PaymentId` to be able to correlate the request with a specific payment.
|
||||||
fn find_route_with_id(
|
fn find_route_with_id(
|
||||||
&self, payer: &PublicKey, route_params: &RouteParameters,
|
&self, payer: &PublicKey, route_params: &RouteParameters,
|
||||||
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: &InFlightHtlcs,
|
first_hops: Option<&[&ChannelDetails]>, inflight_htlcs: InFlightHtlcs,
|
||||||
_payment_hash: PaymentHash, _payment_id: PaymentId
|
_payment_hash: PaymentHash, _payment_id: PaymentId
|
||||||
) -> Result<Route, LightningError> {
|
) -> Result<Route, LightningError> {
|
||||||
self.find_route(payer, route_params, first_hops, inflight_htlcs)
|
self.find_route(payer, route_params, first_hops, inflight_htlcs)
|
||||||
|
|
|
@ -112,13 +112,13 @@ impl<'a> TestRouter<'a> {
|
||||||
impl<'a> Router for TestRouter<'a> {
|
impl<'a> Router for TestRouter<'a> {
|
||||||
fn find_route(
|
fn find_route(
|
||||||
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
|
&self, payer: &PublicKey, params: &RouteParameters, first_hops: Option<&[&channelmanager::ChannelDetails]>,
|
||||||
inflight_htlcs: &InFlightHtlcs
|
inflight_htlcs: InFlightHtlcs
|
||||||
) -> Result<Route, msgs::LightningError> {
|
) -> Result<Route, msgs::LightningError> {
|
||||||
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
|
if let Some((find_route_query, find_route_res)) = self.next_routes.lock().unwrap().pop_front() {
|
||||||
assert_eq!(find_route_query, *params);
|
assert_eq!(find_route_query, *params);
|
||||||
if let Ok(ref route) = find_route_res {
|
if let Ok(ref route) = find_route_res {
|
||||||
let mut binding = self.scorer.lock().unwrap();
|
let mut binding = self.scorer.lock().unwrap();
|
||||||
let scorer = ScorerAccountingForInFlightHtlcs::new(binding.deref_mut(), inflight_htlcs);
|
let scorer = ScorerAccountingForInFlightHtlcs::new(binding.deref_mut(), &inflight_htlcs);
|
||||||
for path in &route.paths {
|
for path in &route.paths {
|
||||||
let mut aggregate_msat = 0u64;
|
let mut aggregate_msat = 0u64;
|
||||||
for (idx, hop) in path.hops.iter().rev().enumerate() {
|
for (idx, hop) in path.hops.iter().rev().enumerate() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue