@@ -1556,6 +1556,7 @@ DirectedChannelLiquidity<L, HT, T> {
15561556 chan_descr, existing_max_msat, amount_msat) ;
15571557 }
15581558 self . update_history_buckets ( 0 , duration_since_epoch) ;
1559+ * self . last_datapoint_time = duration_since_epoch;
15591560 }
15601561
15611562 /// Adjusts the channel liquidity balance bounds when failing to route `amount_msat` downstream.
@@ -1571,6 +1572,7 @@ DirectedChannelLiquidity<L, HT, T> {
15711572 chan_descr, existing_min_msat, amount_msat) ;
15721573 }
15731574 self . update_history_buckets ( 0 , duration_since_epoch) ;
1575+ * self . last_datapoint_time = duration_since_epoch;
15741576 }
15751577
15761578 /// Adjusts the channel liquidity balance bounds when successfully routing `amount_msat`.
@@ -1580,6 +1582,7 @@ DirectedChannelLiquidity<L, HT, T> {
15801582 let max_liquidity_msat = self . max_liquidity_msat ( ) . checked_sub ( amount_msat) . unwrap_or ( 0 ) ;
15811583 log_debug ! ( logger, "Subtracting {} from max liquidity of {} (setting it to {})" , amount_msat, chan_descr, max_liquidity_msat) ;
15821584 self . set_max_liquidity_msat ( max_liquidity_msat, duration_since_epoch) ;
1585+ * self . last_datapoint_time = duration_since_epoch;
15831586 self . update_history_buckets ( amount_msat, duration_since_epoch) ;
15841587 }
15851588
@@ -1603,7 +1606,6 @@ DirectedChannelLiquidity<L, HT, T> {
16031606 * self . max_liquidity_offset_msat = 0 ;
16041607 }
16051608 * self . last_updated = duration_since_epoch;
1606- * self . last_datapoint_time = duration_since_epoch;
16071609 }
16081610
16091611 /// Adjusts the upper bound of the channel liquidity balance in this direction.
@@ -1613,7 +1615,6 @@ DirectedChannelLiquidity<L, HT, T> {
16131615 * self . min_liquidity_offset_msat = 0 ;
16141616 }
16151617 * self . last_updated = duration_since_epoch;
1616- * self . last_datapoint_time = duration_since_epoch;
16171618 }
16181619}
16191620
@@ -4161,21 +4162,24 @@ mod tests {
41614162 short_channel_id : 42 ,
41624163 } ) ;
41634164
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 ) ) ;
41664170
41674171 // If no time has passed, we get the full probing_diversity_penalty_msat
41684172 assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 1_000_000 ) ;
41694173
41704174 // As time passes the penalty decreases.
4171- scorer. time_passed ( Duration :: from_secs ( 1 ) ) ;
4175+ scorer. time_passed ( Duration :: from_secs ( 2 ) ) ;
41724176 assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 999_976 ) ;
41734177
4174- scorer. time_passed ( Duration :: from_secs ( 2 ) ) ;
4178+ scorer. time_passed ( Duration :: from_secs ( 3 ) ) ;
41754179 assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 999_953 ) ;
41764180
41774181 // 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 ) ) ;
41794183 assert_eq ! ( scorer. channel_penalty_msat( & candidate, usage, & params) , 250_000 ) ;
41804184 }
41814185}
0 commit comments