@@ -22,6 +22,7 @@ use sc_consensus::{BlockImportError, BlockImportStatus, IncomingBlock, Link};
2222use sc_service:: ImportQueue ;
2323use sc_tracing:: tracing:: { debug, info, trace} ;
2424use sp_consensus:: BlockOrigin ;
25+ use sp_core:: traits:: SpawnEssentialNamed ;
2526use sp_runtime:: generic:: BlockId ;
2627use sp_runtime:: traits:: { Block as BlockT , Header , NumberFor } ;
2728use std:: sync:: Arc ;
@@ -58,15 +59,26 @@ pub struct ImportBlocksFromDsnCmd {
5859
5960impl ImportBlocksFromDsnCmd {
6061 /// Run the import-blocks command
61- pub async fn run < B , C , IQ > ( & self , client : Arc < C > , import_queue : IQ ) -> sc_cli:: Result < ( ) >
62+ pub async fn run < B , C , IQ > (
63+ & self ,
64+ client : Arc < C > ,
65+ import_queue : IQ ,
66+ spawner : impl SpawnEssentialNamed ,
67+ ) -> sc_cli:: Result < ( ) >
6268 where
6369 C : HeaderBackend < B > + BlockBackend < B > + Send + Sync + ' static ,
6470 B : BlockT + for < ' de > serde:: Deserialize < ' de > ,
6571 IQ : sc_service:: ImportQueue < B > + ' static ,
6672 {
67- import_blocks ( self . bootstrap_node . clone ( ) , client, import_queue, false )
68- . await
69- . map_err ( Into :: into)
73+ import_blocks (
74+ self . bootstrap_node . clone ( ) ,
75+ client,
76+ import_queue,
77+ & spawner,
78+ false ,
79+ )
80+ . await
81+ . map_err ( Into :: into)
7082 }
7183}
7284
@@ -109,7 +121,7 @@ impl<B: BlockT> Link<B> for WaitLink<B> {
109121 B :: Hash ,
110122 ) > ,
111123 ) {
112- println ! ( "Imported {imported} blocks" ) ;
124+ debug ! ( "Imported {imported} blocks" ) ;
113125 self . imported_blocks += imported as u64 ;
114126
115127 for result in results {
@@ -126,6 +138,7 @@ async fn import_blocks<B, IQ, C>(
126138 bootstrap_nodes : Vec < Multiaddr > ,
127139 client : Arc < C > ,
128140 mut import_queue : IQ ,
141+ spawner : & impl SpawnEssentialNamed ,
129142 force : bool ,
130143) -> Result < ( ) , sc_service:: Error >
131144where
@@ -142,9 +155,13 @@ where
142155 . await
143156 . map_err ( |error| sc_service:: Error :: Other ( error. to_string ( ) ) ) ?;
144157
145- tokio:: spawn ( async move {
146- node_runner. run ( ) . await ;
147- } ) ;
158+ spawner. spawn_essential (
159+ "node-runner" ,
160+ Some ( "subspace-networking" ) ,
161+ Box :: pin ( async move {
162+ node_runner. run ( ) . await ;
163+ } ) ,
164+ ) ;
148165
149166 debug ! ( "Waiting for connected peers..." ) ;
150167 let _ = node. wait_for_connected_peers ( ) . await ;
@@ -263,10 +280,28 @@ where
263280 }
264281 }
265282
283+ while link. imported_blocks < imported_blocks {
284+ futures:: future:: poll_fn ( |ctx| {
285+ import_queue. poll_actions ( ctx, & mut link) ;
286+
287+ Poll :: Ready ( ( ) )
288+ } )
289+ . await ;
290+
291+ if let Some ( WaitLinkError { error, hash } ) = & link. error {
292+ return Err ( sc_service:: Error :: Other ( format ! (
293+ "Stopping block import after #{} blocks on {} because of an error: {}" ,
294+ link. imported_blocks, hash, error
295+ ) ) ) ;
296+ }
297+ }
298+
266299 info ! (
267- "🎉 Imported {} blocks, best #{}, exiting..." ,
300+ "🎉 Imported {} blocks, best #{}/#{}, check against reliable sources to make sure it is a \
301+ block on canonical chain",
268302 imported_blocks,
269- client. info( ) . best_number
303+ client. info( ) . best_number,
304+ client. info( ) . best_hash
270305 ) ;
271306
272307 Ok ( ( ) )
0 commit comments