Skip to content

Commit 04dc495

Browse files
committed
Move functions around to colocate impl of FeeParams and DecayParams
1 parent fd9e528 commit 04dc495

File tree

1 file changed

+75
-72
lines changed

1 file changed

+75
-72
lines changed

lightning/src/routing/scoring.rs

Lines changed: 75 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,75 @@ pub struct ProbabilisticScoringFeeParameters {
519519
pub considered_impossible_penalty_msat: u64,
520520
}
521521

522+
impl Default for ProbabilisticScoringFeeParameters {
523+
fn default() -> Self {
524+
Self {
525+
base_penalty_msat: 500,
526+
base_penalty_amount_multiplier_msat: 8192,
527+
liquidity_penalty_multiplier_msat: 30_000,
528+
liquidity_penalty_amount_multiplier_msat: 192,
529+
manual_node_penalties: HashMap::new(),
530+
anti_probing_penalty_msat: 250,
531+
considered_impossible_penalty_msat: 1_0000_0000_000,
532+
historical_liquidity_penalty_multiplier_msat: 10_000,
533+
historical_liquidity_penalty_amount_multiplier_msat: 64,
534+
}
535+
}
536+
}
537+
538+
impl ProbabilisticScoringFeeParameters {
539+
/// Marks the node with the given `node_id` as banned, i.e.,
540+
/// it will be avoided during path finding.
541+
pub fn add_banned(&mut self, node_id: &NodeId) {
542+
self.manual_node_penalties.insert(*node_id, u64::max_value());
543+
}
544+
545+
/// Marks all nodes in the given list as banned, i.e.,
546+
/// they will be avoided during path finding.
547+
pub fn add_banned_from_list(&mut self, node_ids: Vec<NodeId>) {
548+
for id in node_ids {
549+
self.manual_node_penalties.insert(id, u64::max_value());
550+
}
551+
}
552+
553+
/// Removes the node with the given `node_id` from the list of nodes to avoid.
554+
pub fn remove_banned(&mut self, node_id: &NodeId) {
555+
self.manual_node_penalties.remove(node_id);
556+
}
557+
558+
/// Sets a manual penalty for the given node.
559+
pub fn set_manual_penalty(&mut self, node_id: &NodeId, penalty: u64) {
560+
self.manual_node_penalties.insert(*node_id, penalty);
561+
}
562+
563+
/// Removes the node with the given `node_id` from the list of manual penalties.
564+
pub fn remove_manual_penalty(&mut self, node_id: &NodeId) {
565+
self.manual_node_penalties.remove(node_id);
566+
}
567+
568+
/// Clears the list of manual penalties that are applied during path finding.
569+
pub fn clear_manual_penalties(&mut self) {
570+
self.manual_node_penalties = HashMap::new();
571+
}
572+
}
573+
574+
#[cfg(test)]
575+
impl ProbabilisticScoringFeeParameters {
576+
fn zero_penalty() -> Self {
577+
Self {
578+
base_penalty_msat: 0,
579+
base_penalty_amount_multiplier_msat: 0,
580+
liquidity_penalty_multiplier_msat: 0,
581+
liquidity_penalty_amount_multiplier_msat: 0,
582+
historical_liquidity_penalty_multiplier_msat: 0,
583+
historical_liquidity_penalty_amount_multiplier_msat: 0,
584+
manual_node_penalties: HashMap::new(),
585+
anti_probing_penalty_msat: 0,
586+
considered_impossible_penalty_msat: 0,
587+
}
588+
}
589+
}
590+
522591
/// Parameters for configuring [`ProbabilisticScorer`].
523592
///
524593
/// Used to configure decay parameters that are static throughout the lifetime of the scorer.
@@ -561,24 +630,25 @@ pub struct ProbabilisticScoringDecayParameters {
561630
pub liquidity_offset_half_life: Duration,
562631
}
563632

564-
#[cfg(test)]
565-
impl ProbabilisticScoringDecayParameters {
566-
fn zero_penalty() -> Self {
633+
impl Default for ProbabilisticScoringDecayParameters {
634+
fn default() -> Self {
567635
Self {
568636
liquidity_offset_half_life: Duration::from_secs(6 * 60 * 60),
569637
historical_no_updates_half_life: Duration::from_secs(60 * 60 * 24 * 14),
570638
}
571639
}
572640
}
573641

574-
impl Default for ProbabilisticScoringDecayParameters {
575-
fn default() -> Self {
642+
#[cfg(test)]
643+
impl ProbabilisticScoringDecayParameters {
644+
fn zero_penalty() -> Self {
576645
Self {
577646
liquidity_offset_half_life: Duration::from_secs(6 * 60 * 60),
578647
historical_no_updates_half_life: Duration::from_secs(60 * 60 * 24 * 14),
579648
}
580649
}
581650
}
651+
582652
/// Tracks the historical state of a distribution as a weighted average of how much time was spent
583653
/// in each of 8 buckets.
584654
#[derive(Clone, Copy)]
@@ -882,73 +952,6 @@ impl<G: Deref<Target = NetworkGraph<L>>, L: Deref, T: Time> ProbabilisticScorerU
882952
}
883953
}
884954

885-
impl ProbabilisticScoringFeeParameters {
886-
#[cfg(test)]
887-
fn zero_penalty() -> Self {
888-
Self {
889-
base_penalty_msat: 0,
890-
base_penalty_amount_multiplier_msat: 0,
891-
liquidity_penalty_multiplier_msat: 0,
892-
liquidity_penalty_amount_multiplier_msat: 0,
893-
historical_liquidity_penalty_multiplier_msat: 0,
894-
historical_liquidity_penalty_amount_multiplier_msat: 0,
895-
manual_node_penalties: HashMap::new(),
896-
anti_probing_penalty_msat: 0,
897-
considered_impossible_penalty_msat: 0,
898-
}
899-
}
900-
901-
/// Marks the node with the given `node_id` as banned, i.e.,
902-
/// it will be avoided during path finding.
903-
pub fn add_banned(&mut self, node_id: &NodeId) {
904-
self.manual_node_penalties.insert(*node_id, u64::max_value());
905-
}
906-
907-
/// Marks all nodes in the given list as banned, i.e.,
908-
/// they will be avoided during path finding.
909-
pub fn add_banned_from_list(&mut self, node_ids: Vec<NodeId>) {
910-
for id in node_ids {
911-
self.manual_node_penalties.insert(id, u64::max_value());
912-
}
913-
}
914-
915-
/// Removes the node with the given `node_id` from the list of nodes to avoid.
916-
pub fn remove_banned(&mut self, node_id: &NodeId) {
917-
self.manual_node_penalties.remove(node_id);
918-
}
919-
920-
/// Sets a manual penalty for the given node.
921-
pub fn set_manual_penalty(&mut self, node_id: &NodeId, penalty: u64) {
922-
self.manual_node_penalties.insert(*node_id, penalty);
923-
}
924-
925-
/// Removes the node with the given `node_id` from the list of manual penalties.
926-
pub fn remove_manual_penalty(&mut self, node_id: &NodeId) {
927-
self.manual_node_penalties.remove(node_id);
928-
}
929-
930-
/// Clears the list of manual penalties that are applied during path finding.
931-
pub fn clear_manual_penalties(&mut self) {
932-
self.manual_node_penalties = HashMap::new();
933-
}
934-
}
935-
936-
impl Default for ProbabilisticScoringFeeParameters {
937-
fn default() -> Self {
938-
Self {
939-
base_penalty_msat: 500,
940-
base_penalty_amount_multiplier_msat: 8192,
941-
liquidity_penalty_multiplier_msat: 30_000,
942-
liquidity_penalty_amount_multiplier_msat: 192,
943-
manual_node_penalties: HashMap::new(),
944-
anti_probing_penalty_msat: 250,
945-
considered_impossible_penalty_msat: 1_0000_0000_000,
946-
historical_liquidity_penalty_multiplier_msat: 10_000,
947-
historical_liquidity_penalty_amount_multiplier_msat: 64,
948-
}
949-
}
950-
}
951-
952955
impl<T: Time> ChannelLiquidity<T> {
953956
#[inline]
954957
fn new() -> Self {

0 commit comments

Comments
 (0)