@@ -7,7 +7,7 @@ use serde::{Deserialize, Serialize};
7
7
use signet_bundle:: SignetEthBundle ;
8
8
use tokio:: sync:: mpsc:: { UnboundedReceiver , UnboundedSender , unbounded_channel} ;
9
9
use tokio:: task:: JoinHandle ;
10
- use tokio:: time;
10
+ use tokio:: time:: { self , Duration } ;
11
11
12
12
/// Holds a bundle from the cache with a unique ID and a Zenith bundle.
13
13
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
@@ -62,18 +62,21 @@ impl BundlePoller {
62
62
return Ok ( vec ! [ ] ) ;
63
63
} ;
64
64
65
- let result = self
66
- . client
65
+ self . client
67
66
. get ( bundle_url)
68
67
. bearer_auth ( token. access_token ( ) . secret ( ) )
69
68
. send ( )
70
69
. await ?
71
- . error_for_status ( ) ?;
72
-
73
- let body = result. bytes ( ) . await ?;
74
- let resp: TxPoolBundleResponse = serde_json:: from_slice ( & body) ?;
70
+ . error_for_status ( ) ?
71
+ . json ( )
72
+ . await
73
+ . map ( |resp : TxPoolBundleResponse | resp. bundles )
74
+ . map_err ( Into :: into)
75
+ }
75
76
76
- Ok ( resp. bundles )
77
+ /// Returns the poll duration as a [`Duration`].
78
+ const fn poll_duration ( & self ) -> Duration {
79
+ Duration :: from_millis ( self . poll_interval_ms )
77
80
}
78
81
79
82
async fn task_future ( mut self , outbound : UnboundedSender < Bundle > ) {
@@ -92,22 +95,21 @@ impl BundlePoller {
92
95
// exit the span after the check.
93
96
drop ( _guard) ;
94
97
95
- match self . check_bundle_cache ( ) . instrument ( span. clone ( ) ) . await {
96
- Ok ( bundles) => {
97
- debug ! ( count = ?bundles. len( ) , "found bundles" ) ;
98
- for bundle in bundles. into_iter ( ) {
99
- if let Err ( err) = outbound. send ( bundle) {
100
- error ! ( err = ?err, "Failed to send bundle - channel is dropped" ) ;
101
- }
98
+ if let Ok ( bundles) = self
99
+ . check_bundle_cache ( )
100
+ . instrument ( span. clone ( ) )
101
+ . await
102
+ . inspect_err ( |err| debug ! ( %err, "Error fetching bundles" ) )
103
+ {
104
+ debug ! ( count = ?bundles. len( ) , "found bundles" ) ;
105
+ for bundle in bundles. into_iter ( ) {
106
+ if let Err ( err) = outbound. send ( bundle) {
107
+ error ! ( err = ?err, "Failed to send bundle - channel is dropped" ) ;
102
108
}
103
109
}
104
- // If fetching was an error, we log and continue. We expect
105
- // these to be transient network issues.
106
- Err ( e) => {
107
- debug ! ( error = %e, "Error fetching bundles" ) ;
108
- }
109
110
}
110
- time:: sleep ( time:: Duration :: from_millis ( self . poll_interval_ms ) ) . await ;
111
+
112
+ time:: sleep ( self . poll_duration ( ) ) . await ;
111
113
}
112
114
}
113
115
0 commit comments