]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Use correct penalty and CLTV delta in route hints
authorJeffrey Czyz <jkczyz@gmail.com>
Tue, 17 May 2022 21:57:55 +0000 (16:57 -0500)
committerJeffrey Czyz <jkczyz@gmail.com>
Thu, 19 May 2022 19:25:22 +0000 (14:25 -0500)
For route hints, the aggregate next hops path penalty and CLTV delta
should be computed after considering each hop rather than before.
Otherwise, these aggregate values will include values from the current
hop, too.

lightning/src/routing/router.rs

index 7536011d06d72782672f91ff24a499f1681aa5b4..e8436e14651214f7dd3a694d8b6c34a04fe93e01 100644 (file)
@@ -1295,16 +1295,6 @@ where L::Target: Logger {
                                                        short_channel_id: hop.short_channel_id,
                                                })
                                                .unwrap_or_else(|| CandidateRouteHop::PrivateHop { hint: hop });
-                                       let amount_to_transfer_msat = final_value_msat + aggregate_next_hops_fee_msat;
-                                       let capacity_msat = candidate.effective_capacity().as_msat();
-                                       aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
-                                               .saturating_add(scorer.channel_penalty_msat(hop.short_channel_id, amount_to_transfer_msat, capacity_msat, &source, &target));
-
-                                       aggregate_next_hops_cltv_delta = aggregate_next_hops_cltv_delta
-                                               .saturating_add(hop.cltv_expiry_delta as u32);
-
-                                       aggregate_next_hops_path_length = aggregate_next_hops_path_length
-                                               .saturating_add(1);
 
                                        if !add_entry!(candidate, source, target, aggregate_next_hops_fee_msat,
                                                                path_value_msat, aggregate_next_hops_path_htlc_minimum_msat,
@@ -1316,6 +1306,17 @@ where L::Target: Logger {
                                                hop_used = false;
                                        }
 
+                                       let amount_to_transfer_msat = final_value_msat + aggregate_next_hops_fee_msat;
+                                       let capacity_msat = candidate.effective_capacity().as_msat();
+                                       aggregate_next_hops_path_penalty_msat = aggregate_next_hops_path_penalty_msat
+                                               .saturating_add(scorer.channel_penalty_msat(hop.short_channel_id, amount_to_transfer_msat, capacity_msat, &source, &target));
+
+                                       aggregate_next_hops_cltv_delta = aggregate_next_hops_cltv_delta
+                                               .saturating_add(hop.cltv_expiry_delta as u32);
+
+                                       aggregate_next_hops_path_length = aggregate_next_hops_path_length
+                                               .saturating_add(1);
+
                                        // Searching for a direct channel between last checked hop and first_hop_targets
                                        if let Some(first_channels) = first_hop_targets.get(&NodeId::from_pubkey(&prev_hop_id)) {
                                                for details in first_channels {