From 738567894adfb801699a6faaad9a4140723ef2a9 Mon Sep 17 00:00:00 2001 From: Nicholas Wehr Date: Tue, 26 Aug 2025 19:49:45 -0700 Subject: [PATCH] only consider top level highest dir name on archive node file root; also added back hlfs to blockingest struct --- bin/reth/src/block_ingest.rs | 2 ++ bin/reth/src/share_blocks.rs | 4 ++-- crates/net/hlfs/src/lib.rs | 20 +++++++++++++++----- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bin/reth/src/block_ingest.rs b/bin/reth/src/block_ingest.rs index 39586e305..da6884870 100644 --- a/bin/reth/src/block_ingest.rs +++ b/bin/reth/src/block_ingest.rs @@ -29,6 +29,7 @@ use tokio::sync::Mutex; use tracing::{debug, info}; use crate::serialized::{BlockAndReceipts, EvmBlock}; +use crate::share_blocks::ShareBlocks; use crate::spot_meta::erc20_contract_to_spot_token; /// Poll interval when tailing an *open* hourly file. @@ -41,6 +42,7 @@ pub(crate) struct BlockIngest { pub local_ingest_dir: Option, pub local_blocks_cache: Arc>>, // height → block pub precompiles_cache: PrecompilesCache, + pub hlfs: Option, } #[derive(Deserialize)] diff --git a/bin/reth/src/share_blocks.rs b/bin/reth/src/share_blocks.rs index ee7afa1bc..4e5188c12 100644 --- a/bin/reth/src/share_blocks.rs +++ b/bin/reth/src/share_blocks.rs @@ -54,12 +54,12 @@ impl ShareBlocks { } }); - let _autodetect = spawn_autodetect(network, host, args.share_blocks_port, args.archive_dir.clone()); + let _autodetect = + spawn_autodetect(network, host, args.share_blocks_port, args.archive_dir.clone()); info!(%bind, dir=%args.archive_dir.display(), "hlfs: enabled (reth peers)"); Ok(Self { _server, _autodetect }) } - } fn spawn_autodetect( diff --git a/crates/net/hlfs/src/lib.rs b/crates/net/hlfs/src/lib.rs index d8ba3a059..d9490f159 100644 --- a/crates/net/hlfs/src/lib.rs +++ b/crates/net/hlfs/src/lib.rs @@ -194,7 +194,20 @@ fn find_max_number_file(root: &Path) -> Result { } let mut best = Some(0); - walk(root, &mut best)?; + let top: PathBuf = fs::read_dir(root)? + .filter_map(|e| e.ok()) + .filter(|e| e.file_type().map(|t| t.is_dir()).unwrap_or(false)) + .filter_map(|e| { + let name = e.file_name(); + let s = name.to_str()?; + let n: u64 = s.parse().ok()?; + Some((n, e.path())) + }) + .max_by_key(|(n, _)| *n) + .map(|(_, p)| p) + .ok_or_else(|| io::Error::new(io::ErrorKind::NotFound, "no numeric top-level dirs"))?; + + walk(&top, &mut best)?; Ok(best.expect("cannot find block files")) } @@ -327,10 +340,7 @@ impl Backfiller { } } } - pub async fn fetch_if_missing( - &mut self, - number: u64, - ) -> Result, HlfsError> { + pub async fn fetch_if_missing(&mut self, number: u64) -> Result, HlfsError> { let rr_index = number as usize; let n = number.saturating_sub(1); // 0 -> 0, others -> number-1 let f = (n / 1_000_000) * 1_000_000;