@@ -110,59 +110,59 @@ pub struct BackgroundProcessor {
110
110
}
111
111
112
112
#[ cfg( not( test) ) ]
113
- const FRESHNESS_TIMER : u64 = 60 ;
113
+ const FRESHNESS_TIMER : Duration = Duration :: from_secs ( 60 ) ;
114
114
#[ cfg( test) ]
115
- const FRESHNESS_TIMER : u64 = 1 ;
115
+ const FRESHNESS_TIMER : Duration = Duration :: from_secs ( 1 ) ;
116
116
117
117
#[ cfg( all( not( test) , not( debug_assertions) ) ) ]
118
- const PING_TIMER : u64 = 10 ;
118
+ const PING_TIMER : Duration = Duration :: from_secs ( 10 ) ;
119
119
/// Signature operations take a lot longer without compiler optimisations.
120
120
/// Increasing the ping timer allows for this but slower devices will be disconnected if the
121
121
/// timeout is reached.
122
122
#[ cfg( all( not( test) , debug_assertions) ) ]
123
- const PING_TIMER : u64 = 30 ;
123
+ const PING_TIMER : Duration = Duration :: from_secs ( 30 ) ;
124
124
#[ cfg( test) ]
125
- const PING_TIMER : u64 = 1 ;
125
+ const PING_TIMER : Duration = Duration :: from_secs ( 1 ) ;
126
126
127
127
#[ cfg( not( test) ) ]
128
- const ONION_MESSAGE_HANDLER_TIMER : u64 = 10 ;
128
+ const ONION_MESSAGE_HANDLER_TIMER : Duration = Duration :: from_secs ( 10 ) ;
129
129
#[ cfg( test) ]
130
- const ONION_MESSAGE_HANDLER_TIMER : u64 = 1 ;
130
+ const ONION_MESSAGE_HANDLER_TIMER : Duration = Duration :: from_secs ( 1 ) ;
131
131
132
132
/// Prune the network graph of stale entries hourly.
133
- const NETWORK_PRUNE_TIMER : u64 = 60 * 60 ;
133
+ const NETWORK_PRUNE_TIMER : Duration = Duration :: from_secs ( 60 * 60 ) ;
134
134
135
135
#[ cfg( not( test) ) ]
136
- const SCORER_PERSIST_TIMER : u64 = 60 * 5 ;
136
+ const SCORER_PERSIST_TIMER : Duration = Duration :: from_secs ( 60 * 5 ) ;
137
137
#[ cfg( test) ]
138
- const SCORER_PERSIST_TIMER : u64 = 1 ;
138
+ const SCORER_PERSIST_TIMER : Duration = Duration :: from_secs ( 1 ) ;
139
139
140
140
#[ cfg( not( test) ) ]
141
- const FIRST_NETWORK_PRUNE_TIMER : u64 = 60 ;
141
+ const FIRST_NETWORK_PRUNE_TIMER : Duration = Duration :: from_secs ( 60 ) ;
142
142
#[ cfg( test) ]
143
- const FIRST_NETWORK_PRUNE_TIMER : u64 = 1 ;
143
+ const FIRST_NETWORK_PRUNE_TIMER : Duration = Duration :: from_secs ( 1 ) ;
144
144
145
145
#[ cfg( not( test) ) ]
146
- const REBROADCAST_TIMER : u64 = 30 ;
146
+ const REBROADCAST_TIMER : Duration = Duration :: from_secs ( 30 ) ;
147
147
#[ cfg( test) ]
148
- const REBROADCAST_TIMER : u64 = 1 ;
148
+ const REBROADCAST_TIMER : Duration = Duration :: from_secs ( 1 ) ;
149
149
150
150
#[ cfg( not( test) ) ]
151
- const SWEEPER_TIMER : u64 = 30 ;
151
+ const SWEEPER_TIMER : Duration = Duration :: from_secs ( 30 ) ;
152
152
#[ cfg( test) ]
153
- const SWEEPER_TIMER : u64 = 1 ;
153
+ const SWEEPER_TIMER : Duration = Duration :: from_secs ( 1 ) ;
154
154
155
155
/// core::cmp::min is not currently const, so we define a trivial (and equivalent) replacement
156
- const fn min_u64 ( a : u64 , b : u64 ) -> u64 {
157
- if a < b {
156
+ const fn min_duration ( a : Duration , b : Duration ) -> Duration {
157
+ if a. as_nanos ( ) < b. as_nanos ( ) {
158
158
a
159
159
} else {
160
160
b
161
161
}
162
162
}
163
- const FASTEST_TIMER : u64 = min_u64 (
164
- min_u64 ( FRESHNESS_TIMER , PING_TIMER ) ,
165
- min_u64 ( SCORER_PERSIST_TIMER , min_u64 ( FIRST_NETWORK_PRUNE_TIMER , REBROADCAST_TIMER ) ) ,
163
+ const FASTEST_TIMER : Duration = min_duration (
164
+ min_duration ( FRESHNESS_TIMER , PING_TIMER ) ,
165
+ min_duration ( SCORER_PERSIST_TIMER , min_duration ( FIRST_NETWORK_PRUNE_TIMER , REBROADCAST_TIMER ) ) ,
166
166
) ;
167
167
168
168
/// Either [`P2PGossipSync`] or [`RapidGossipSync`].
@@ -372,9 +372,9 @@ macro_rules! define_run_body {
372
372
// We wait up to 100ms, but track how long it takes to detect being put to sleep,
373
373
// see `await_start`'s use below.
374
374
let mut await_start = None ;
375
- if $check_slow_await { await_start = Some ( $get_timer( 1 ) ) ; }
375
+ if $check_slow_await { await_start = Some ( $get_timer( Duration :: from_secs ( 1 ) ) ) ; }
376
376
$await;
377
- let await_slow = if $check_slow_await { $timer_elapsed( & mut await_start. unwrap( ) , 1 ) } else { false } ;
377
+ let await_slow = if $check_slow_await { $timer_elapsed( & mut await_start. unwrap( ) , Duration :: from_secs ( 1 ) ) } else { false } ;
378
378
379
379
// Exit the loop if the background processor was requested to stop.
380
380
if $loop_exit_check {
@@ -904,7 +904,7 @@ where
904
904
e: sleeper( if mobile_interruptable_platform {
905
905
Duration :: from_millis( 100 )
906
906
} else {
907
- Duration :: from_secs ( FASTEST_TIMER )
907
+ FASTEST_TIMER
908
908
} ) ,
909
909
} ;
910
910
match fut. await {
@@ -914,7 +914,7 @@ where
914
914
} ,
915
915
}
916
916
} ,
917
- |t| sleeper( Duration :: from_secs ( t ) ) ,
917
+ |t| sleeper( t ) ,
918
918
|fut: & mut SleepFuture , _| {
919
919
let mut waker = dummy_waker( ) ;
920
920
let mut ctx = task:: Context :: from_waker( & mut waker) ;
@@ -1097,7 +1097,7 @@ impl BackgroundProcessor {
1097
1097
sleeper. wait_timeout( Duration :: from_millis( 100 ) ) ;
1098
1098
} ,
1099
1099
|_| Instant :: now( ) ,
1100
- |time: & Instant , dur| time. elapsed( ) . as_secs ( ) > dur,
1100
+ |time: & Instant , dur| time. elapsed( ) > dur,
1101
1101
false ,
1102
1102
|| {
1103
1103
use std:: time:: SystemTime ;
@@ -1215,7 +1215,8 @@ mod tests {
1215
1215
use std:: time:: Duration ;
1216
1216
use std:: { env, fs} ;
1217
1217
1218
- const EVENT_DEADLINE : u64 = 5 * FRESHNESS_TIMER ;
1218
+ const EVENT_DEADLINE : Duration =
1219
+ Duration :: from_millis ( 5 * ( FRESHNESS_TIMER . as_millis ( ) as u64 ) ) ;
1219
1220
1220
1221
#[ derive( Clone , Hash , PartialEq , Eq ) ]
1221
1222
struct TestDescriptor { }
@@ -2253,7 +2254,7 @@ mod tests {
2253
2254
// Open a channel and check that the FundingGenerationReady event was handled.
2254
2255
begin_open_channel ! ( nodes[ 0 ] , nodes[ 1 ] , channel_value) ;
2255
2256
let ( temporary_channel_id, funding_tx) = funding_generation_recv
2256
- . recv_timeout ( Duration :: from_secs ( EVENT_DEADLINE ) )
2257
+ . recv_timeout ( EVENT_DEADLINE )
2257
2258
. expect ( "FundingGenerationReady not handled within deadline" ) ;
2258
2259
nodes[ 0 ]
2259
2260
. node
@@ -2265,7 +2266,7 @@ mod tests {
2265
2266
let msg_1 = get_event_msg ! ( nodes[ 1 ] , MessageSendEvent :: SendFundingSigned , node_0_id) ;
2266
2267
nodes[ 0 ] . node . handle_funding_signed ( node_1_id, & msg_1) ;
2267
2268
channel_pending_recv
2268
- . recv_timeout ( Duration :: from_secs ( EVENT_DEADLINE ) )
2269
+ . recv_timeout ( EVENT_DEADLINE )
2269
2270
. expect ( "ChannelPending not handled within deadline" ) ;
2270
2271
2271
2272
// Confirm the funding transaction.
@@ -2327,9 +2328,8 @@ mod tests {
2327
2328
let commitment_tx = nodes[ 0 ] . tx_broadcaster . txn_broadcasted . lock ( ) . unwrap ( ) . pop ( ) . unwrap ( ) ;
2328
2329
confirm_transaction_depth ( & mut nodes[ 0 ] , & commitment_tx, BREAKDOWN_TIMEOUT as u32 ) ;
2329
2330
2330
- let event = receiver
2331
- . recv_timeout ( Duration :: from_secs ( EVENT_DEADLINE ) )
2332
- . expect ( "Events not handled within deadline" ) ;
2331
+ let event =
2332
+ receiver. recv_timeout ( EVENT_DEADLINE ) . expect ( "Events not handled within deadline" ) ;
2333
2333
match event {
2334
2334
Event :: SpendableOutputs { outputs, channel_id } => {
2335
2335
nodes[ 0 ]
@@ -2481,8 +2481,8 @@ mod tests {
2481
2481
2482
2482
begin_open_channel ! ( nodes[ 0 ] , nodes[ 1 ] , channel_value) ;
2483
2483
assert_eq ! (
2484
- first_event_recv. recv_timeout( Duration :: from_secs ( EVENT_DEADLINE ) ) . unwrap( ) ,
2485
- second_event_recv. recv_timeout( Duration :: from_secs ( EVENT_DEADLINE ) ) . unwrap( )
2484
+ first_event_recv. recv_timeout( EVENT_DEADLINE ) . unwrap( ) ,
2485
+ second_event_recv. recv_timeout( EVENT_DEADLINE ) . unwrap( )
2486
2486
) ;
2487
2487
2488
2488
if !std:: thread:: panicking ( ) {
@@ -2609,7 +2609,7 @@ mod tests {
2609
2609
2610
2610
do_test_not_pruning_network_graph_until_graph_sync_completion ! (
2611
2611
nodes,
2612
- receiver. recv_timeout( Duration :: from_secs ( super :: FIRST_NETWORK_PRUNE_TIMER * 5 ) ) ,
2612
+ receiver. recv_timeout( super :: FIRST_NETWORK_PRUNE_TIMER * 5 ) ,
2613
2613
std:: thread:: sleep( Duration :: from_millis( 1 ) )
2614
2614
) ;
2615
2615
@@ -2658,8 +2658,7 @@ mod tests {
2658
2658
{
2659
2659
let mut i = 0 ;
2660
2660
loop {
2661
- tokio:: time:: sleep( Duration :: from_secs( super :: FIRST_NETWORK_PRUNE_TIMER ) )
2662
- . await ;
2661
+ tokio:: time:: sleep( super :: FIRST_NETWORK_PRUNE_TIMER ) . await ;
2663
2662
if let Ok ( ( ) ) = receiver. try_recv( ) {
2664
2663
break Ok :: <( ) , ( ) >( ( ) ) ;
2665
2664
}
@@ -2806,10 +2805,7 @@ mod tests {
2806
2805
Some ( Arc :: clone ( & nodes[ 0 ] . scorer ) ) ,
2807
2806
) ;
2808
2807
2809
- do_test_payment_path_scoring ! (
2810
- nodes,
2811
- receiver. recv_timeout( Duration :: from_secs( EVENT_DEADLINE ) )
2812
- ) ;
2808
+ do_test_payment_path_scoring ! ( nodes, receiver. recv_timeout( EVENT_DEADLINE ) ) ;
2813
2809
2814
2810
if !std:: thread:: panicking ( ) {
2815
2811
bg_processor. stop ( ) . unwrap ( ) ;
0 commit comments