From d0eb909b30aed96d6849698ca7a7179dad4e2ac3 Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Tue, 30 Jul 2019 13:04:28 +0200 Subject: [PATCH] Properly stop block import on error (#3240) * Stop block import after error * Better diagnostic on error --- substrate/core/service/src/chain_ops.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/substrate/core/service/src/chain_ops.rs b/substrate/core/service/src/chain_ops.rs index 39cd5f570f..19666c090c 100644 --- a/substrate/core/service/src/chain_ops.rs +++ b/substrate/core/service/src/chain_ops.rs @@ -101,12 +101,14 @@ pub fn export_blocks( struct WaitLink { imported_blocks: u64, + has_error: bool, } impl WaitLink { fn new() -> WaitLink { WaitLink { imported_blocks: 0, + has_error: false, } } } @@ -115,12 +117,17 @@ impl Link for WaitLink { fn blocks_processed( &mut self, imported: usize, - count: usize, + _count: usize, results: Vec<(Result>, BlockImportError>, B::Hash)> ) { self.imported_blocks += imported as u64; - if results.iter().any(|(r, _)| r.is_err()) { - warn!("There was an error importing {} blocks", count); + + for result in results { + if let (Err(err), hash) = result { + warn!("There was an error importing block with hash {:?}: {:?}", hash, err); + self.has_error = true; + break; + } } } } @@ -198,6 +205,13 @@ pub fn import_blocks( queue.poll_actions(cx, &mut link); std::task::Poll::Pending::> }).compat().poll(); + if link.has_error { + info!( + "Stopping after #{} blocks because of an error", + link.imported_blocks, + ); + return Ok(Async::Ready(())); + } if link.imported_blocks / 1000 != blocks_before / 1000 { info!( "#{} blocks were imported (#{} left)",