From 7c54397d43c2b5921d4930a608a1c10b46d1dbcf Mon Sep 17 00:00:00 2001 From: Renato Dinhani <101204870+dinhani-cw@users.noreply.github.com> Date: Thu, 23 May 2024 18:19:13 -0300 Subject: [PATCH] fix: importer-offline checking for shutdown after each block (#909) --- src/bin/importer_offline.rs | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/bin/importer_offline.rs b/src/bin/importer_offline.rs index cd10205a3..8d2baa1d1 100644 --- a/src/bin/importer_offline.rs +++ b/src/bin/importer_offline.rs @@ -148,27 +148,26 @@ async fn execute_block_importer( tracing::info!(%block_start, %block_end, receipts = %receipts.len(), "importing blocks"); for (block_index, block) in blocks.into_iter().enumerate() { - async { - // re-execute block - executor.reexecute_external(&block, &receipts).await?; + if GlobalState::warn_if_shutdown(TASK_NAME) { + return Ok(()); + } - // mine block - let mined_block = miner.mine_external().await?; + // re-execute block + executor.reexecute_external(&block, &receipts).await?; - // export to csv OR permanent storage - match csv { - Some(ref mut csv) => import_external_to_csv(&storage, csv, mined_block.clone(), block_index, block_last_index).await?, - None => miner.commit(mined_block.clone()).await?, - }; + // mine block + let mined_block = miner.mine_external().await?; - // export snapshot for tests - if blocks_to_export_snapshot.contains(mined_block.number()) { - export_snapshot(&block, &receipts, &mined_block)?; - } + // export to csv OR permanent storage + match csv { + Some(ref mut csv) => import_external_to_csv(&storage, csv, mined_block.clone(), block_index, block_last_index).await?, + None => miner.commit(mined_block.clone()).await?, + }; - anyhow::Ok(()) + // export snapshot for tests + if blocks_to_export_snapshot.contains(mined_block.number()) { + export_snapshot(&block, &receipts, &mined_block)?; } - .await?; } } }