@@ -1556,6 +1556,7 @@ DirectedChannelLiquidity<L, HT, T> {
1556
1556
chan_descr, existing_max_msat, amount_msat) ;
1557
1557
}
1558
1558
self . update_history_buckets ( 0 , duration_since_epoch) ;
1559
+ * self . last_datapoint_time = duration_since_epoch;
1559
1560
}
1560
1561
1561
1562
/// Adjusts the channel liquidity balance bounds when failing to route `amount_msat` downstream.
@@ -1571,6 +1572,7 @@ DirectedChannelLiquidity<L, HT, T> {
1571
1572
chan_descr, existing_min_msat, amount_msat) ;
1572
1573
}
1573
1574
self . update_history_buckets ( 0 , duration_since_epoch) ;
1575
+ * self . last_datapoint_time = duration_since_epoch;
1574
1576
}
1575
1577
1576
1578
/// Adjusts the channel liquidity balance bounds when successfully routing `amount_msat`.
@@ -1580,6 +1582,7 @@ DirectedChannelLiquidity<L, HT, T> {
1580
1582
let max_liquidity_msat = self . max_liquidity_msat ( ) . checked_sub ( amount_msat) . unwrap_or ( 0 ) ;
1581
1583
log_debug ! ( logger, "Subtracting {} from max liquidity of {} (setting it to {})" , amount_msat, chan_descr, max_liquidity_msat) ;
1582
1584
self . set_max_liquidity_msat ( max_liquidity_msat, duration_since_epoch) ;
1585
+ * self . last_datapoint_time = duration_since_epoch;
1583
1586
self . update_history_buckets ( amount_msat, duration_since_epoch) ;
1584
1587
}
1585
1588
@@ -1603,7 +1606,6 @@ DirectedChannelLiquidity<L, HT, T> {
1603
1606
* self . max_liquidity_offset_msat = 0 ;
1604
1607
}
1605
1608
* self . last_updated = duration_since_epoch;
1606
- * self . last_datapoint_time = duration_since_epoch;
1607
1609
}
1608
1610
1609
1611
/// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1613,7 +1615,6 @@ DirectedChannelLiquidity<L, HT, T> {
1613
1615
* self . min_liquidity_offset_msat = 0 ;
1614
1616
}
1615
1617
* self . last_updated = duration_since_epoch;
1616
- * self . last_datapoint_time = duration_since_epoch;
1617
1618
}
1618
1619
}
1619
1620
@@ -4161,21 +4162,24 @@ mod tests {
4161
4162
short_channel_id : 42 ,
4162
4163
} ) ;
4163
4164
4164
- // Apply some update to set the last-update time to now
4165
- scorer. payment_path_failed ( & payment_path_for_amount ( 1000 ) , 42 , Duration :: ZERO ) ;
4165
+ // Initialize the state for channel 42
4166
+ scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) , 42 , Duration :: ZERO ) ;
4167
+
4168
+ // Apply an update to set the last-update time to 1 second
4169
+ scorer. payment_path_failed ( & payment_path_for_amount ( 500 ) , 42 , Duration :: from_secs ( 1 ) ) ;
4166
4170
4167
4171
// If no time has passed, we get the full probing_diversity_penalty_msat
4168
4172
assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 1_000_000 ) ;
4169
4173
4170
4174
// As time passes the penalty decreases.
4171
- scorer. time_passed ( Duration :: from_secs ( 1 ) ) ;
4175
+ scorer. time_passed ( Duration :: from_secs ( 2 ) ) ;
4172
4176
assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 999_976 ) ;
4173
4177
4174
- scorer. time_passed ( Duration :: from_secs ( 2 ) ) ;
4178
+ scorer. time_passed ( Duration :: from_secs ( 3 ) ) ;
4175
4179
assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 999_953 ) ;
4176
4180
4177
4181
// Once we've gotten halfway through the day our penalty is 1/4 the configured value.
4178
- scorer. time_passed ( Duration :: from_secs ( 86400 /2 ) ) ;
4182
+ scorer. time_passed ( Duration :: from_secs ( 86400 /2 + 1 ) ) ;
4179
4183
assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 250_000 ) ;
4180
4184
}
4181
4185
}
0 commit comments