From 6fd66000d392afc0b67de36f46a206528e4a8c13 Mon Sep 17 00:00:00 2001 From: Shanin Roman Date: Fri, 17 May 2024 12:06:01 +0300 Subject: [PATCH] fix(kura): Inline kura initialization into constructor Signed-off-by: Shanin Roman --- cli/src/lib.rs | 4 +--- core/benches/kura.rs | 2 +- core/src/kura.rs | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/cli/src/lib.rs b/cli/src/lib.rs index 74f524b1640..6c5ac55f9b1 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -255,12 +255,10 @@ impl Iroha { .into_non_empty_vec(), ); - let kura = Kura::new(&config.kura).change_context(StartError::InitKura)?; + let (kura, block_count) = Kura::new(&config.kura).change_context(StartError::InitKura)?; let kura_thread_handler = Kura::start(Arc::clone(&kura)); let live_query_store_handle = LiveQueryStore::from_config(config.live_query_store).start(); - let block_count = kura.init().change_context(StartError::InitKura)?; - let state = match try_read_snapshot( config.snapshot.store_dir.resolve_relative_path(), &kura, diff --git a/core/benches/kura.rs b/core/benches/kura.rs index 5483677c2ee..b311804ab1c 100644 --- a/core/benches/kura.rs +++ b/core/benches/kura.rs @@ -42,7 +42,7 @@ async fn measure_block_size_for_n_executors(n_executors: u32) { debug_output_new_blocks: false, store_dir: WithOrigin::inline(dir.path().to_path_buf()), }; - let kura = iroha_core::kura::Kura::new(&cfg).unwrap(); + let (kura, _) = iroha_core::kura::Kura::new(&cfg).unwrap(); let _thread_handle = iroha_core::kura::Kura::start(kura.clone()); let query_handle = LiveQueryStore::test().start(); diff --git a/core/src/kura.rs b/core/src/kura.rs index 19b8baf3d75..b9d37c8d104 100644 --- a/core/src/kura.rs +++ b/core/src/kura.rs @@ -49,7 +49,7 @@ impl Kura { /// Fails if there are filesystem errors when trying /// to access the block store indicated by the provided /// path. - pub fn new(config: &Config) -> Result> { + pub fn new(config: &Config) -> Result<(Arc, BlockCount)> { let store_dir = config.store_dir.resolve_relative_path(); let mut block_store = BlockStore::new(&store_dir, LockStatus::Unlocked); block_store.create_files_if_they_do_not_exist()?; @@ -65,7 +65,9 @@ impl Kura { block_plain_text_path, }); - Ok(kura) + let block_count = kura.init()?; + + Ok((kura, block_count)) } /// Create a kura instance that doesn't write to disk. Instead it serves as a handler @@ -104,7 +106,7 @@ impl Kura { /// - file storage is unavailable /// - data in file storage is invalid or corrupted #[iroha_logger::log(skip_all, name = "kura_init")] - pub fn init(self: &Arc) -> Result { + fn init(self: &Arc) -> Result { let mut block_store = self.block_store.lock(); let block_index_count: usize = block_store @@ -1056,8 +1058,6 @@ mod tests { ), debug_output_new_blocks: false, }) - .unwrap() - .init() .unwrap(); } }