@@ -5,7 +5,6 @@ use eyre::Error;
5
5
use init4_bin_base:: deps:: tracing:: { Instrument , debug, debug_span, trace} ;
6
6
use reqwest:: { Client , Url } ;
7
7
use serde:: { Deserialize , Serialize } ;
8
- use serde_json:: from_slice;
9
8
use tokio:: { sync:: mpsc, task:: JoinHandle , time} ;
10
9
11
10
/// Models a response from the transaction pool.
@@ -43,9 +42,14 @@ impl TxPoller {
43
42
/// Polls the transaction cache for transactions.
44
43
pub async fn check_tx_cache ( & mut self ) -> Result < Vec < TxEnvelope > , Error > {
45
44
let url: Url = Url :: parse ( & self . config . tx_pool_url ) ?. join ( "transactions" ) ?;
46
- let result = self . client . get ( url) . send ( ) . await ?;
47
- let response: TxPoolResponse = from_slice ( result. text ( ) . await ?. as_bytes ( ) ) ?;
48
- Ok ( response. transactions )
45
+ self . client
46
+ . get ( url)
47
+ . send ( )
48
+ . await ?
49
+ . json ( )
50
+ . await
51
+ . map ( |resp : TxPoolResponse | resp. transactions )
52
+ . map_err ( Into :: into)
49
53
}
50
54
51
55
async fn task_future ( mut self , outbound : mpsc:: UnboundedSender < TxEnvelope > ) {
@@ -64,24 +68,22 @@ impl TxPoller {
64
68
// exit the span after the check.
65
69
drop ( _guard) ;
66
70
67
- match self . check_tx_cache ( ) . instrument ( span. clone ( ) ) . await {
68
- Ok ( transactions) => {
69
- let _guard = span. entered ( ) ;
70
- debug ! ( count = ?transactions. len( ) , "found transactions" ) ;
71
- for tx in transactions. into_iter ( ) {
72
- if outbound. send ( tx) . is_err ( ) {
73
- // If there are no receivers, we can shut down
74
- trace ! ( "No receivers left, shutting down" ) ;
75
- break ;
76
- }
71
+ if let Ok ( transactions) =
72
+ self . check_tx_cache ( ) . instrument ( span. clone ( ) ) . await . inspect_err ( |err| {
73
+ debug ! ( %err, "Error fetching transactions" ) ;
74
+ } )
75
+ {
76
+ let _guard = span. entered ( ) ;
77
+ debug ! ( count = ?transactions. len( ) , "found transactions" ) ;
78
+ for tx in transactions. into_iter ( ) {
79
+ if outbound. send ( tx) . is_err ( ) {
80
+ // If there are no receivers, we can shut down
81
+ trace ! ( "No receivers left, shutting down" ) ;
82
+ break ;
77
83
}
78
84
}
79
- // If fetching was an error, we log and continue. We expect
80
- // these to be transient network issues.
81
- Err ( e) => {
82
- debug ! ( error = %e, "Error fetching transactions" ) ;
83
- }
84
85
}
86
+
85
87
time:: sleep ( time:: Duration :: from_millis ( self . poll_interval_ms ) ) . await ;
86
88
}
87
89
}
0 commit comments