Skip to content
Snippets Groups Projects
Commit d0eb909b authored by Pierre Krieger's avatar Pierre Krieger Committed by André Silva
Browse files

Properly stop block import on error (#3240)

* Stop block import after error

* Better diagnostic on error
parent 4c0934b2
No related merge requests found
...@@ -101,12 +101,14 @@ pub fn export_blocks<F, E, W>( ...@@ -101,12 +101,14 @@ pub fn export_blocks<F, E, W>(
struct WaitLink { struct WaitLink {
imported_blocks: u64, imported_blocks: u64,
has_error: bool,
} }
impl WaitLink { impl WaitLink {
fn new() -> WaitLink { fn new() -> WaitLink {
WaitLink { WaitLink {
imported_blocks: 0, imported_blocks: 0,
has_error: false,
} }
} }
} }
...@@ -115,12 +117,17 @@ impl<B: Block> Link<B> for WaitLink { ...@@ -115,12 +117,17 @@ impl<B: Block> Link<B> for WaitLink {
fn blocks_processed( fn blocks_processed(
&mut self, &mut self,
imported: usize, imported: usize,
count: usize, _count: usize,
results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)> results: Vec<(Result<BlockImportResult<NumberFor<B>>, BlockImportError>, B::Hash)>
) { ) {
self.imported_blocks += imported as u64; 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<F, E, R>( ...@@ -198,6 +205,13 @@ pub fn import_blocks<F, E, R>(
queue.poll_actions(cx, &mut link); queue.poll_actions(cx, &mut link);
std::task::Poll::Pending::<Result<(), ()>> std::task::Poll::Pending::<Result<(), ()>>
}).compat().poll(); }).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 { if link.imported_blocks / 1000 != blocks_before / 1000 {
info!( info!(
"#{} blocks were imported (#{} left)", "#{} blocks were imported (#{} left)",
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment