mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-17 21:51:06 +00:00
Properly stop block import on error (#3240)
* Stop block import after error * Better diagnostic on error
This commit is contained in:
committed by
André Silva
parent
4c0934b2a7
commit
d0eb909b30
@@ -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 {
|
|||||||
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>(
|
|||||||
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)",
|
||||||
|
|||||||
Reference in New Issue
Block a user