@@ -3,8 +3,8 @@ use std::sync::Arc;
3
3
4
4
use anyhow:: anyhow;
5
5
use anyhow:: Context ;
6
+ use futures:: stream;
6
7
use futures:: StreamExt ;
7
- use futures:: TryStreamExt ;
8
8
use itertools:: Itertools ;
9
9
use serde:: Deserialize ;
10
10
use stratus:: config:: RpcDownloaderConfig ;
@@ -14,9 +14,9 @@ use stratus::eth::primitives::Hash;
14
14
use stratus:: eth:: storage:: ExternalRpcStorage ;
15
15
use stratus:: ext:: not;
16
16
use stratus:: infra:: BlockchainClient ;
17
- use stratus:: log_and_err;
18
17
use stratus:: utils:: DropTimer ;
19
18
use stratus:: GlobalServices ;
19
+ use stratus:: GlobalState ;
20
20
#[ cfg( all( not( target_env = "msvc" ) , any( feature = "jemalloc" , feature = "jeprof" ) ) ) ]
21
21
use tikv_jemallocator:: Jemalloc ;
22
22
@@ -83,7 +83,8 @@ async fn download_balances(rpc_storage: Arc<dyn ExternalRpcStorage>, chain: &Blo
83
83
}
84
84
85
85
async fn download_blocks ( rpc_storage : Arc < dyn ExternalRpcStorage > , chain : Arc < BlockchainClient > , paralellism : usize , end : BlockNumber ) -> anyhow:: Result < ( ) > {
86
- let _timer = DropTimer :: start ( "rpc-downloader::download_blocks" ) ;
86
+ const TASK_NAME : & str = "rpc-downloader::download_blocks" ;
87
+ let _timer = DropTimer :: start ( TASK_NAME ) ;
87
88
88
89
// prepare download block tasks
89
90
let mut start = BlockNumber :: ZERO ;
@@ -99,16 +100,20 @@ async fn download_blocks(rpc_storage: Arc<dyn ExternalRpcStorage>, chain: Arc<Bl
99
100
100
101
// execute download block tasks
101
102
tracing:: info!( tasks = %tasks. len( ) , %paralellism, "executing block downloads" ) ;
102
- let result = futures :: stream :: iter ( tasks ) . buffer_unordered ( paralellism ) . try_collect :: < Vec < ( ) > > ( ) . await ;
103
- match result {
104
- Ok ( _ ) => {
105
- tracing :: info! ( "tasks finished" ) ;
106
- Ok ( ( ) )
103
+
104
+ let mut stream = stream :: iter ( tasks ) . buffered ( paralellism ) ;
105
+ while let Some ( result ) = stream . next ( ) . await {
106
+ if let Err ( e ) = result {
107
+ tracing :: error! ( reason = ?e , "download task failed" ) ;
107
108
}
108
- Err ( e) => {
109
- log_and_err ! ( reason = e, "tasks failed" )
109
+
110
+ if GlobalState :: is_shutdown_warn ( TASK_NAME ) {
111
+ break ;
110
112
}
111
113
}
114
+
115
+ tracing:: info!( "download finished" ) ;
116
+ Ok ( ( ) )
112
117
}
113
118
114
119
async fn download (
0 commit comments