1+ use backoff:: { ExponentialBackoff , ExponentialBackoffBuilder } ;
12use clap:: Parser ;
3+ use std:: time:: Duration ;
24use url:: Url ;
35
46#[ derive( Parser , Clone , Debug ) ]
@@ -19,7 +21,59 @@ pub struct FlashblocksArgs {
1921 #[ arg( long, env, default_value = "1112" ) ]
2022 pub flashblocks_port : u16 ,
2123
22- /// Time used for timeout if builder disconnected
24+ /// Websocket connection configuration
25+ #[ command( flatten) ]
26+ pub flashblocks_ws_config : FlashblocksWebsocketConfig ,
27+ }
28+
29+ #[ derive( Parser , Debug , Clone , Copy ) ]
30+ pub struct FlashblocksWebsocketConfig {
31+ /// Minimum time for exponential backoff for timeout if builder disconnected
32+ #[ arg( long, env, default_value = "10" ) ]
33+ pub flashblock_builder_ws_initial_reconnect_ms : u64 ,
34+
35+ /// Maximum time for exponential backoff for timeout if builder disconnected
2336 #[ arg( long, env, default_value = "5000" ) ]
24- pub flashblock_builder_ws_reconnect_ms : u64 ,
37+ pub flashblock_builder_ws_max_reconnect_ms : u64 ,
38+
39+ /// Interval in milliseconds between ping messages sent to upstream servers to detect unresponsive connections
40+ #[ arg( long, env, default_value = "500" ) ]
41+ pub flashblock_builder_ws_ping_interval_ms : u64 ,
42+
43+ /// Timeout in milliseconds to wait for pong responses from upstream servers before considering the connection dead
44+ #[ arg( long, env, default_value = "1500" ) ]
45+ pub flashblock_builder_ws_pong_timeout_ms : u64 ,
46+ }
47+
48+ impl FlashblocksWebsocketConfig {
49+ /// Creates `ExponentialBackoff` use to control builder websocket reconnection time
50+ pub fn backoff ( & self ) -> ExponentialBackoff {
51+ ExponentialBackoffBuilder :: default ( )
52+ . with_initial_interval ( self . initial_interval ( ) )
53+ . with_max_interval ( self . max_interval ( ) )
54+ . with_randomization_factor ( 0 as f64 )
55+ . with_max_elapsed_time ( None )
56+ . with_multiplier ( 2.0 )
57+ . build ( )
58+ }
59+
60+ /// Returns initial time for exponential backoff
61+ pub fn initial_interval ( & self ) -> Duration {
62+ Duration :: from_millis ( self . flashblock_builder_ws_initial_reconnect_ms )
63+ }
64+
65+ /// Returns maximal time for exponential backoff
66+ pub fn max_interval ( & self ) -> Duration {
67+ Duration :: from_millis ( self . flashblock_builder_ws_max_reconnect_ms )
68+ }
69+
70+ /// Returns ping interval
71+ pub fn ping_interval ( & self ) -> Duration {
72+ Duration :: from_millis ( self . flashblock_builder_ws_ping_interval_ms )
73+ }
74+
75+ /// Returns pong interval
76+ pub fn pong_interval ( & self ) -> Duration {
77+ Duration :: from_millis ( self . flashblock_builder_ws_pong_timeout_ms )
78+ }
2579}
0 commit comments