]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Add a test which demonstrates scores for some realistic payments
authorMatt Corallo <git@bluematt.me>
Sun, 3 Apr 2022 20:36:09 +0000 (20:36 +0000)
committerMatt Corallo <git@bluematt.me>
Sun, 3 Apr 2022 21:18:15 +0000 (21:18 +0000)
lightning/src/routing/scoring.rs

index b7aa996ce2efae9622208e1293dcebf8b1b3d8b9..d21d8fa3b65285d6f7f912d22d4b81aa5adcebf4 100644 (file)
@@ -2119,6 +2119,29 @@ mod tests {
                assert_eq!(deserialized_scorer.channel_penalty_msat(42, 500, 1_000, &source, &target), 371);
        }
 
+       #[test]
+       fn scores_realistic_payments() {
+               // Shows the scores of "realistic" sends of 100k sats over channels of 1-10m sats (with a
+               // 50k sat reserve).
+               let network_graph = network_graph();
+               let params = ProbabilisticScoringParameters::default();
+               let scorer = ProbabilisticScorer::new(params, &network_graph);
+               let source = source_node_id();
+               let target = target_node_id();
+
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 950_000_000, &source, &target), 3645);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 1_950_000_000, &source, &target), 2512);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 2_950_000_000, &source, &target), 500);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 3_950_000_000, &source, &target), 1442);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 4_950_000_000, &source, &target), 500);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 5_950_000_000, &source, &target), 1820);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 6_950_000_000, &source, &target), 500);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 7_450_000_000, &source, &target), 500);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 7_950_000_000, &source, &target), 500);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 8_950_000_000, &source, &target), 500);
+               assert_eq!(scorer.channel_penalty_msat(42, 100_000_000, 9_950_000_000, &source, &target), 500);
+       }
+
        #[test]
        fn adds_base_penalty_to_liquidity_penalty() {
                let network_graph = network_graph();