Skip to content

Commit 68980c0

Browse files
Test scoring paths with blinded tails
1 parent b449b43 commit 68980c0

File tree

1 file changed

+47
-2
lines changed

1 file changed

+47
-2
lines changed

lightning/src/routing/scoring.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1702,17 +1702,18 @@ impl<T: Time> Readable for ChannelLiquidity<T> {
17021702
#[cfg(test)]
17031703
mod tests {
17041704
use super::{ChannelLiquidity, HistoricalBucketRangeTracker, ProbabilisticScoringParameters, ProbabilisticScorerUsingTime};
1705+
use crate::blinded_path::{BlindedHop, BlindedPath};
17051706
use crate::util::config::UserConfig;
17061707
use crate::util::time::Time;
17071708
use crate::util::time::tests::SinceEpoch;
17081709

17091710
use crate::ln::channelmanager;
17101711
use crate::ln::msgs::{ChannelAnnouncement, ChannelUpdate, UnsignedChannelAnnouncement, UnsignedChannelUpdate};
17111712
use crate::routing::gossip::{EffectiveCapacity, NetworkGraph, NodeId};
1712-
use crate::routing::router::{Path, RouteHop};
1713+
use crate::routing::router::{BlindedTail, Path, RouteHop};
17131714
use crate::routing::scoring::{ChannelUsage, Score};
17141715
use crate::util::ser::{ReadableArgs, Writeable};
1715-
use crate::util::test_utils::TestLogger;
1716+
use crate::util::test_utils::{self, TestLogger};
17161717

17171718
use bitcoin::blockdata::constants::genesis_block;
17181719
use bitcoin::hashes::Hash;
@@ -2870,4 +2871,48 @@ mod tests {
28702871
};
28712872
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), 0);
28722873
}
2874+
2875+
#[test]
2876+
fn scores_with_blinded_path() {
2877+
// Make sure we'll account for a blinded path's final_value_msat in scoring
2878+
let logger = TestLogger::new();
2879+
let network_graph = network_graph(&logger);
2880+
let params = ProbabilisticScoringParameters {
2881+
liquidity_penalty_multiplier_msat: 1_000,
2882+
liquidity_offset_half_life: Duration::from_secs(10),
2883+
..ProbabilisticScoringParameters::zero_penalty()
2884+
};
2885+
let mut scorer = ProbabilisticScorer::new(params, &network_graph, &logger);
2886+
let source = source_node_id();
2887+
let target = target_node_id();
2888+
let usage = ChannelUsage {
2889+
amount_msat: 512,
2890+
inflight_htlc_msat: 0,
2891+
effective_capacity: EffectiveCapacity::Total { capacity_msat: 1_024, htlc_maximum_msat: 1_000 },
2892+
};
2893+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), 300);
2894+
2895+
let mut path = payment_path_for_amount(768);
2896+
let recipient_hop = path.hops.pop().unwrap();
2897+
let blinded_path = BlindedPath {
2898+
introduction_node_id: path.hops.last().as_ref().unwrap().pubkey,
2899+
blinding_point: test_utils::pubkey(42),
2900+
blinded_hops: vec![
2901+
BlindedHop { blinded_node_id: test_utils::pubkey(44), encrypted_payload: Vec::new() }
2902+
],
2903+
};
2904+
path.blinded_tail = Some(BlindedTail {
2905+
hops: blinded_path.blinded_hops,
2906+
blinding_point: blinded_path.blinding_point,
2907+
final_cltv_expiry_delta: recipient_hop.cltv_expiry_delta,
2908+
final_value_msat: recipient_hop.fee_msat,
2909+
});
2910+
2911+
// More knowledge gives higher confidence (256, 768), meaning a lower penalty.
2912+
scorer.payment_path_failed(&path, 42);
2913+
path.blinded_tail.as_mut().unwrap().final_value_msat = 256;
2914+
scorer.payment_path_failed(&path, 43);
2915+
assert_eq!(scorer.channel_penalty_msat(42, &source, &target, usage), 281);
2916+
assert_eq!(scorer.channel_penalty_msat(43, &source, &target, usage), 300);
2917+
}
28732918
}

0 commit comments

Comments
 (0)