From 1b2a7b1c27706526725799b43a55559a215432fc Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Thu, 7 Aug 2025 12:39:18 +0200 Subject: [PATCH 1/2] query rpc only for hash --- crates/host/src/bin/cli.rs | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/crates/host/src/bin/cli.rs b/crates/host/src/bin/cli.rs index 1f528398..a8ce0708 100644 --- a/crates/host/src/bin/cli.rs +++ b/crates/host/src/bin/cli.rs @@ -101,22 +101,29 @@ async fn get_cached_input( block_id: BlockId, cache_dir: &Path, ) -> anyhow::Result { - // First, get the block header to determine the canonical hash for caching. - let header = processor - .provider() - .get_block(block_id) - .await? - .with_context(|| format!("block {block_id} not found"))? - .header; - - let cache_file = cache_dir.join(format!("input_{}.json", header.hash)); + let block_hash = match block_id { + BlockId::Hash(hash) => hash.block_hash, + _ => { + // First, get the block header to determine the canonical hash for caching. + let header = processor + .provider() + .get_block(block_id) + .await? + .with_context(|| format!("block {block_id} not found"))? + .header; + + header.hash + } + }; + + let cache_file = cache_dir.join(format!("input_{}.json", block_hash)); let input: StatelessInput = if cache_file.exists() { - println!("Cache hit for block {}. Loading from file: {:?}", header.hash, &cache_file); + println!("Cache hit for block {}. Loading from file: {:?}", block_hash, &cache_file); let f = File::open(&cache_file).context("failed to open file")?; serde_json::from_reader(BufReader::new(f)).context("failed to read file")? } else { - println!("Cache miss for block {}. Fetching from RPC.", header.hash); - let (input, _) = processor.create_input(header.hash).await?; + println!("Cache miss for block {}. Fetching from RPC.", block_hash); + let (input, _) = processor.create_input(block_hash).await?; // Save the newly fetched input to the cache. println!("Writing new input to cache: {:?}", &cache_file); @@ -125,7 +132,7 @@ async fn get_cached_input( input }; - ensure!(input.block.hash_slow() == header.hash); + ensure!(input.block.hash_slow() == block_hash); Ok(input) } From 5ca54a2c8fbf926170d9076c165ead554f2bb514 Mon Sep 17 00:00:00 2001 From: Wolfgang Welz Date: Thu, 7 Aug 2025 12:42:18 +0200 Subject: [PATCH 2/2] fix clippy warnings --- crates/host/src/bin/cli.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/host/src/bin/cli.rs b/crates/host/src/bin/cli.rs index a8ce0708..340f7f1d 100644 --- a/crates/host/src/bin/cli.rs +++ b/crates/host/src/bin/cli.rs @@ -116,17 +116,17 @@ async fn get_cached_input( } }; - let cache_file = cache_dir.join(format!("input_{}.json", block_hash)); + let cache_file = cache_dir.join(format!("input_{block_hash}.json")); let input: StatelessInput = if cache_file.exists() { - println!("Cache hit for block {}. Loading from file: {:?}", block_hash, &cache_file); + println!("Cache hit for block {block_hash}. Loading from file: {cache_file:?}"); let f = File::open(&cache_file).context("failed to open file")?; serde_json::from_reader(BufReader::new(f)).context("failed to read file")? } else { - println!("Cache miss for block {}. Fetching from RPC.", block_hash); + println!("Cache miss for block {block_hash}. Fetching from RPC."); let (input, _) = processor.create_input(block_hash).await?; // Save the newly fetched input to the cache. - println!("Writing new input to cache: {:?}", &cache_file); + println!("Writing new input to cache: {cache_file:?}"); let f = File::create(&cache_file).context("failed to create file")?; serde_json::to_writer(BufWriter::new(f), &input).context("failed to write file")?;